You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
EEE / GEF321! ! ! ! ! ! ! ! ! Winter / hiver 2013Exercice <strong>de</strong> <strong>Java</strong> / <strong>UML</strong> Exercise1. Consi<strong>de</strong>r the following <strong>UML</strong> class diagram.Generate the <strong>Java</strong> skel<strong>et</strong>on-co<strong>de</strong> that wouldcorrespond to following classes. Provi<strong>de</strong> as muchinformation as is visible in the diagram, but notmore:• InQueue• N<strong>et</strong>workPack<strong>et</strong>• StreamPack<strong>et</strong>• Router1. Considérez le diagramme <strong>de</strong> classe <strong>UML</strong> ci<strong>de</strong>ssous.Écrivez le co<strong>de</strong> <strong>Java</strong> squel<strong>et</strong>te qui secorrespond aux classes suivantes. Montrertoute l’information disponible du diagramme,mais pas plus.• InQueue• N<strong>et</strong>workPack<strong>et</strong>• StreamPack<strong>et</strong>• Router2. Read the following short class <strong>de</strong>scriptions andprovi<strong>de</strong> the <strong>Java</strong> co<strong>de</strong> for the compl<strong>et</strong>e Routerclass.2. Lisez les <strong>de</strong>scriptions courtes <strong>de</strong>s classesmontrées ci-<strong>de</strong>ssous <strong>et</strong> écrivez le co<strong>de</strong> <strong>Java</strong>pour la classe Router au compl<strong>et</strong>.Router class <strong>de</strong>scription: Description <strong>de</strong> la classe Router :A Router has two input queues: a high priorityqueue called high and a low priority queue calledlow. It also has a routing table, containing routinginformation that is maintained by another part ofthe system (not shown). The queues and therouting table are passed to the Router in itsconstructor.Un Router a <strong>de</strong>ux queues d’entrée : unequeue à haut priorité qui s’appelle high <strong>et</strong> unequeue à base priorité qui s’appelle low. Il aaussi une table d’acheminement, qui contientinformation venant d’une autre partie dusystème (non-montré). Les queues <strong>et</strong> la tabled’acheminement sont passées au Router dansson constructeur.1/3
EEE / GEF321! ! ! ! ! ! ! ! ! Winter / hiver 2013A Router’s route() m<strong>et</strong>hod is used to routepack<strong>et</strong>s received on either input queue out thecorrect output queue. The route() m<strong>et</strong>hod is aninfinite loop which operates as follows:• Check the high queue. If it has pack<strong>et</strong>s,continue routing them (see below) until thequeue is empty.• Check the low queue. If it has pack<strong>et</strong>s,route one pack<strong>et</strong>. Then check the highqueue again.The mechanism for routing a pack<strong>et</strong> is as follows:• Call the pack<strong>et</strong>’s g<strong>et</strong>Hops() m<strong>et</strong>hod. If thenumber r<strong>et</strong>urned is less than one, discardthe pack<strong>et</strong>. Otherwise, call the pack<strong>et</strong>’s<strong>de</strong>crementHops() m<strong>et</strong>hod and continu<strong>et</strong>he routing process.• If the pack<strong>et</strong> is part of a stream(isStream() r<strong>et</strong>urns true) call itsg<strong>et</strong>Stream() m<strong>et</strong>hod to g<strong>et</strong> its streami<strong>de</strong>ntifier. Otherwise, call itsg<strong>et</strong>Destination() m<strong>et</strong>hod to g<strong>et</strong> its<strong>de</strong>stination address.• Query the routing table to find theappropriate OutQueue, and send thepack<strong>et</strong> using that queue. If there is noappropriate OutQueue, discard the pack<strong>et</strong>.La métho<strong>de</strong> route() d’un Router est utilisépour acheminer les paqu<strong>et</strong>s reçu dans les <strong>de</strong>uxqueues d’entrée à la bonne queue <strong>de</strong> sortie. Lamétho<strong>de</strong> route() est une boucle infinie quiopère comme suite :Examinez la queue high. S’il contient <strong>de</strong>spaqu<strong>et</strong>s, continuez à les acheminer (voir ci<strong>de</strong>ssous)jusqu'à la queue est vi<strong>de</strong>.Examinez la queue low. S’il contient <strong>de</strong>spaqu<strong>et</strong>s, acheminez un paqu<strong>et</strong>, ensuiter<strong>et</strong>ournez à la queue high.Le mécanisme pour acheminer un paqu<strong>et</strong> estcomme suite :• Appelez la métho<strong>de</strong> g<strong>et</strong>Hops() dupaqu<strong>et</strong>. Si le nombre r<strong>et</strong>ourné est moinsqu’un, laissez tomber le paqu<strong>et</strong>. Sinon,appelez la métho<strong>de</strong> <strong>de</strong>crementHops()du paqu<strong>et</strong> <strong>et</strong> continuez le processusd’acheminement.• Si le paqu<strong>et</strong> fait partie d’un train (un«stream», c’est-à-dire que isStream()r<strong>et</strong>ourne true) appelez sa métho<strong>de</strong>g<strong>et</strong>Stream() pour trouver soni<strong>de</strong>ntifiant du train. Sinon, appelez samétho<strong>de</strong> g<strong>et</strong>Destination() pourtrouver son adresse <strong>de</strong> <strong>de</strong>stination.• Interrogez la table d’acheminement pourtrouver la bonne OutQueue, <strong>et</strong> ém<strong>et</strong>tre lepaqu<strong>et</strong> en utilisant c<strong>et</strong>te queue. S’il n’y apas <strong>de</strong> bonne OutQueue, laissez tomberle paqu<strong>et</strong>.OutQueue class <strong>de</strong>scription: Description <strong>de</strong> la classe OutQueue :An OutQueue provi<strong>de</strong>s an abstract layer thathi<strong>de</strong>s the router’s pack<strong>et</strong> transmissionmechanism. Calling an OutQueue’s send()m<strong>et</strong>hod allows a pack<strong>et</strong> to be sent on that queue.There is typically one OutQueue for each routerport.Un obj<strong>et</strong> OutQueue nous donne une coucheabstrait qui cache le mécanisme d<strong>et</strong>ransmission <strong>de</strong>s paqu<strong>et</strong>s du routeur. On ém<strong>et</strong>un paqu<strong>et</strong> avec la métho<strong>de</strong> send() d’uneOutQueue. Normalement, il y a une OutQueuepour chaque port sur le router.2/3
EEE / GEF321! ! ! ! ! ! ! ! ! Winter / hiver 2013InQueue class <strong>de</strong>scription: Description <strong>de</strong> la classe InQueue :An InQueue provi<strong>de</strong>s an abstract layer that hi<strong>de</strong>sthe router’s pack<strong>et</strong> receiving mechanism. If anInQueue has waiting pack<strong>et</strong>s, its hasPack<strong>et</strong>s()m<strong>et</strong>hod will r<strong>et</strong>urn true, otherwise it will r<strong>et</strong>urnfalse. If an InQueue has waiting pack<strong>et</strong>s,calling its next() m<strong>et</strong>hod will r<strong>et</strong>urn the nextpack<strong>et</strong>. Calling next() when there are nopack<strong>et</strong>s will cause the caller to wait until a pack<strong>et</strong>is available in the queue. There is typically oneInQueue for each routing priority level.Un obj<strong>et</strong> InQueue nous donne une coucheabstrait qui cache le mécanisme <strong>de</strong> réception<strong>de</strong>s paqu<strong>et</strong>s <strong>de</strong> notre Router. Si une InQueue a<strong>de</strong>s paqu<strong>et</strong>s qui atten<strong>de</strong>nt, sa métho<strong>de</strong>hasPack<strong>et</strong>s() r<strong>et</strong>ournera true, sinon, ilr<strong>et</strong>ournera false. Si une InQueue a <strong>de</strong>spaqu<strong>et</strong>s qui atten<strong>de</strong>nt, sa métho<strong>de</strong> next()r<strong>et</strong>ournera la prochaine paqu<strong>et</strong>. Si on appellenext() quand il n’y a pas <strong>de</strong> paqu<strong>et</strong>s dans laqueue, on atten<strong>de</strong> jusqu'à un paqu<strong>et</strong> soitdisponible dans la queue. Il y a normalementune InQueue pour chaque niveau <strong>de</strong> prioritéd’acheminement.RoutingTable class <strong>de</strong>scription: Description <strong>de</strong> la classe RoutingTable :A RoutingTable maintains a mapping fromaddresses to OutQueues and a mapping fromstream i<strong>de</strong>ntifiers (see below) to OutQueues.Calling its g<strong>et</strong>Queue() m<strong>et</strong>hod with a streami<strong>de</strong>ntifier or an address will r<strong>et</strong>urn the appropriateOutQueue. If the stream i<strong>de</strong>ntifier or address isnot recognized, g<strong>et</strong>Queue() r<strong>et</strong>urns null.Un obj<strong>et</strong> RoutingTable est une tabled’acheminement qui entr<strong>et</strong>ient un mappageentre <strong>de</strong>s adresses <strong>et</strong> <strong>de</strong>s OutQueues <strong>et</strong> unmappage entre <strong>de</strong>s i<strong>de</strong>ntifiants <strong>de</strong>s trains(«streams», voyez ci-<strong>de</strong>ssous) <strong>et</strong> <strong>de</strong>sOutQueues. Si on appelle la métho<strong>de</strong>g<strong>et</strong>Queue() d’une RoutingTable avec unadresse ou un i<strong>de</strong>ntifiant <strong>de</strong> train, la métho<strong>de</strong>r<strong>et</strong>ournera l’OutQueue appropriée. Si leRoutingTable n’a pas une OutQueue quicorrespond au i<strong>de</strong>ntifiant ou adresse, lamétho<strong>de</strong> g<strong>et</strong>Queue() r<strong>et</strong>ourne une valeur <strong>de</strong>null.3. Provi<strong>de</strong> a collaboration diagram correspondingto the execution of your Router.route()m<strong>et</strong>hod in the case where:• there is exactly one pack<strong>et</strong> in the highqueue, where this pack<strong>et</strong> is part of a streamand has a g<strong>et</strong>Hops() value of 3;• there is also one pack<strong>et</strong> in the low queue,which is not part of a stream and which hasa g<strong>et</strong>Hops() r<strong>et</strong>urn value of 7; and• both pack<strong>et</strong>s are sent using the sameOutQueue.3. Donnez un diagramme <strong>de</strong> collaboration quise correspond à l’exécution <strong>de</strong> votre métho<strong>de</strong>Router.route() dans le cas où :• il y a exactement un paqu<strong>et</strong> dans laqueue high, <strong>et</strong> le paqu<strong>et</strong> fait partie d’untrain <strong>et</strong> a un valeur <strong>de</strong> r<strong>et</strong>our <strong>de</strong>g<strong>et</strong>Hops() <strong>de</strong> 3;• il y a aussi un paqu<strong>et</strong> dans la queue low,qui ne fait pas partie d’un train <strong>et</strong> qui a unvaleur <strong>de</strong> r<strong>et</strong>our <strong>de</strong> g<strong>et</strong>Hops() <strong>de</strong> 7; <strong>et</strong>• les <strong>de</strong>ux paqu<strong>et</strong>s sont émis en utilisant lamême OutQueue.3/3