예제 #1
0
    def testStepNewEvents(self):
        """ Test that step correctly enqueues new events.
        """
        stub = NetworkObjectStubWithNewEvents()

        e1 = Event(5, stub, 'message')
        e2 = Event(0, stub, 'message')
        e3 = Event(7, stub, 'message')
        e4 = PacketEvent(1, 'sender2', stub, 4, 'message5')
        eventList = [e1, e2, e3, e4]

        eventHandler = EventHandler('network', eventList)
        self.assertEqual(e2, eventHandler.step())
        self.assertEqual(e4, eventHandler.step())
        self.assertEqual(e1, eventHandler.step())
        self.assertEqual(e3, eventHandler.step())

        # Test that there are 8 more Events enqueued and in the correct order
        self.assertEqual(8, eventHandler._queue.qsize())
        for i in xrange(102, 110):
            self.assertEqual(i, eventHandler.step().timestamp)

        # Test that stepping into an empty queue raises Empty
        with self.assertRaises(Empty) as e:
            eventHandler.step()
예제 #2
0
    def testEventHandlerInit(self):
        """ Test the constructor of EventHandler.

        Checks the priority queue enqueues Events in the correct order.
        """
        stub = NetworkObjectStub()

        e1 = Event(5, stub, 'message')
        e2 = Event(0, stub, 'message')
        e3 = Event(7, stub, 'message')
        e4 = PacketEvent(1, 'sender2', stub, 4, 'message5')
        eventList = [e1, e2, e3, e4]

        eventHandler = EventHandler('network', eventList)
        self.assertEqual('network', eventHandler._network)
        self.assertEqual(4, eventHandler._queue.qsize())
예제 #3
0
    def testRun(self):
        """ Test that run() handles interval and steps correctly.
        """
        stub = NetworkObjectStub()

        e1 = Event(5, stub, 'message')
        e2 = Event(0, stub, 'message')
        e3 = Event(7, stub, 'message')
        e4 = PacketEvent(1, 'sender2', stub, 4, 'message5')
        eventList = [e1, e2, e3, e4]

        eventHandler = EventHandler('network', eventList)
        eventHandler.run(0, 4)
        with self.assertRaises(Empty) as e:
            eventHandler.run(0, 1)
예제 #4
0
    def testStepOrder(self):
        """ Test that step grabs the event with smallest timestamp.
        """
        stub = NetworkObjectStub()

        e1 = Event(5, stub, 'message')
        e2 = Event(0, stub, 'message')
        e3 = Event(7, stub, 'message')
        e4 = PacketEvent(1, 'sender2', stub, 4, 'message5')
        eventList = [e1, e2, e3, e4]

        eventHandler = EventHandler('network', eventList)

        # Test that there are 4 Events enqueued and in the correct order
        self.assertEqual(4, eventHandler._queue.qsize())
        self.assertEqual(e2, eventHandler.step())
        self.assertEqual(e4, eventHandler.step())
        self.assertEqual(e1, eventHandler.step())
        self.assertEqual(e3, eventHandler.step())

        # Test that stepping into an empty queue raises Empty
        with self.assertRaises(Empty) as e:
            eventHandler.step()
예제 #5
0
from icfire.network import Network
from icfire.eventhandler import EventHandler

if __name__ == '__main__':
    filename = 'tc1Reno.json'
    # filename = 'tc1Fast.json'

    # plotting specs
    flowinterval = 40
    plotflows = ['F1']
    linkinterval = 40
    plotlinks = ['L1', 'L2']
    hostinterval = 40
    plothosts = ['H1', 'H2']

    # load network
    tc1 = Network()
    tc1.load(filename)

    # run
    EventHandler(tc1).run(2000000)
    tc1.draw()

    # plot
    tc1.plotAll(flowinterval, plotflows, linkinterval, plotlinks, hostinterval,
                plothosts, filename[:filename.index('.')])
예제 #6
0
from icfire.network import Network
from icfire.eventhandler import EventHandler

if __name__ == '__main__':
    filename = 'tc0Reno.json'
    # filename = 'tc0Fast.json'

    # plotting specs
    flowinterval = 100
    plotflows = ['F1']
    linkinterval = 100
    plotlinks = ['L1']
    hostinterval = 100
    plothosts = ['H1', 'H2']

    # load network
    tc0 = Network()
    tc0.load(filename)

    # run
    EventHandler(tc0).run(2000000)
    tc0.draw()

    # plot
    tc0.plotAll(flowinterval, plotflows, linkinterval, plotlinks, hostinterval,
                plothosts, filename[:filename.index('.')])
예제 #7
0
from icfire.network import Network
from icfire.eventhandler import EventHandler

if __name__ == '__main__':
    filename = 'tc2Reno.json'
    # filename = 'tc2Fast.json'

    # plotting specs
    flowinterval = 100
    plotflows = ['F1', 'F2', 'F3']
    linkinterval = 100
    plotlinks = ['L1', 'L2', 'L3']
    hostinterval = 100
    plothosts = ['S1', 'S2', 'S3', 'T1', 'T2', 'T3']

    # load network
    tc2 = Network()
    tc2.load(filename)

    # run
    EventHandler(tc2).run(2000000)
    tc2.draw()

    # plot
    tc2.plotAll(flowinterval, plotflows, linkinterval, plotlinks,
                hostinterval, plothosts, filename[:filename.index('.')])