Esempio n. 1
0
    def addLink(self, source_id, target_id, rate, delay, buffsize, linkid):
        """ Adds a link from source_id to target_id

        :param source_id: id of a node
        :param target_id: id of a node
        :param rate: link rate (Mbps)
        :param delay: delay of the link (ms)
        :param buffsize: link buffer size (KB)
        :param linkid: (optional) optional unique id in
        :returns: integer or string key of the link

        """
        if source_id in self.nodes and target_id in self.nodes:
            # If no linkid is provided, generate a unique
            if not self.G.has_edge(source_id, target_id):
                self.G.add_edge(source_id,
                                target_id,
                                rate=rate,
                                delay=delay,
                                buffsize=buffsize,
                                linkid=linkid)
            self.links[linkid] = Link(self.nodes[source_id],
                                      self.nodes[target_id], rate, delay,
                                      buffsize, linkid)
            self.nodes[source_id].addLink(self.links[linkid])
            self.nodes[target_id].addLink(self.links[linkid])
            return linkid
        else:
            print("Source or target not in the graph!")
            return None
Esempio n. 2
0
    def testProcessWithNonPacketEvent(self):
        """ Tests that processEvent will fail when not passed a PacketEvent. """
        l = Link('nodeA', 'nodeB', 5, 5, 100, 0)
        e = Event(5, 'obj', 'message')
        e2 = PacketEvent(1, 'sender2', 'receiver3', 4, 'message5')

        with self.assertRaises(AssertionError):
            l.processEvent(e)
        l.processEvent(e2)      # Should not fail
Esempio n. 3
0
    def testSendPackets(self):
        """ Tests sendPackets generates the correct set of new Events. """
        l = Link('nodeA', 'nodeB', 5, 5, 100, 0)
        h = Host('hostaddr', [l])
        newevents = h.sendPackets(10, 'destaddr', 42)

        self.assertEqual(10, len(newevents))
        for e in newevents:
            self.assertEqual(h, e.sender)          # Event sender is the host
            self.assertEqual(l, e.eventObject)     # Event receiver is the link
            self.assertEqual(42, e.timestamp)      # Timestamp is 42
            p = e.packet
            # Host address is source of packet
            self.assertEqual(h.address, p.source)
            # Destination is address 'destaddr'
            self.assertEqual('destaddr', p.dest)
Esempio n. 4
0
 def testOtherNode(self):
     """ Tests _otherNode. """
     l = Link('nodeA', 'nodeB', 5, 5, 100, 0)
     self.assertEqual('nodeA', l._otherNode('nodeB'))
     self.assertEqual('nodeB', l._otherNode('nodeA'))