Esempio n. 1
0
def main():
    # parameters
    Sim.scheduler.reset()
    Sim.set_debug("Node")

    # setup network
    net = Network("test2network.txt")
    for hostname, node in sorted(net.nodes.iteritems()):
        node.add_protocol(protocol="dvrouting", handler=RoutingApp(node))

    n3 = net.get_node("n3")
    n3.add_protocol(protocol="delay", handler=DelayHandler())

    p = Packet(destination_address=n3.get_address("n2"),
               ident=1,
               protocol="delay",
               length=1000)
    n2 = net.get_node("n2")
    Sim.scheduler.add(delay=1.2, event=p, handler=n2.send_packet)
    Sim.scheduler.add(delay=1.6, event=None, handler=n2.get_link("n3").down)
    Sim.scheduler.add(delay=1.6, event=None, handler=n3.get_link("n2").down)

    p = Packet(destination_address=n3.get_address("n2"),
               ident=2,
               protocol="delay",
               length=1000)
    Sim.scheduler.add(delay=6.6, event=p, handler=n2.send_packet)

    # run the simulation
    Sim.scheduler.run()
Esempio n. 2
0
def part2(config):
    Sim.scheduler.reset()

    # setup network
    net = Network(config)

    # setup routes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n3 = net.get_node('n3')
    n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
    n1.add_forwarding_entry(address=n3.get_address('n2'), link=n1.links[0])
    n2.add_forwarding_entry(address=n3.get_address('n2'), link=n2.links[1])
    
    # setup app
    d = DelayHandler()
    net.nodes['n2'].add_protocol(protocol="delay", handler=d)
    net.nodes['n3'].add_protocol(protocol='delay', handler=d)
    # send one packet
    for i in range(0,1000):
        Sim.scheduler.add(delay=i * 0.03125,
            event = Packet(destination_address=n3.get_address('n2'), ident=i, protocol='delay', length=1000),
            handler=n1.send_packet
        )
    # p1 = Packet(destination_address=n2.get_address('n1'), ident=1, protocol='delay', length=1000)
    # Sim.scheduler.add(delay=0, event=p1, handler=n1.send_packet)
    
    # run the simulation
    Sim.scheduler.run()
Esempio n. 3
0
def main():
    # parameters
    Sim.scheduler.reset()

    # setup network
    net = Network('threenodes2.txt')

    # setup routes
    node_a = net.get_node('A')
    node_b = net.get_node('B')
    node_c = net.get_node('C')
    node_a.add_forwarding_entry(address=node_b.get_address('A'),
                                link=node_a.links[0])
    node_b.add_forwarding_entry(address=node_c.get_address('B'),
                                link=node_b.links[0])

    # setup app
    d = DelayHandler()
    net.nodes['A'].add_protocol(protocol='delay', handler=d)
    net.nodes['B'].add_protocol(protocol='delay', handler=d)
    net.nodes['C'].add_protocol(protocol='delay', handler=d)

    # send one packet
    for i in range(1000):
        p = Packet(destination_address=node_c.get_address('B'),
                   ident=i,
                   protocol='delay',
                   length=1000)
        Sim.scheduler.add(delay=i * .008, event=p, handler=node_a.send_packet)

    # run the simulation
    Sim.scheduler.run()
Esempio n. 4
0
def main():
	d = DelayHandler()
	for i in range(1, 4):
		Sim.scheduler.reset()

		net = Network('./threenodes' + str(i) + '.txt')

		n1 = net.get_node('n1')
		n2 = net.get_node('n2')
		n3 = net.get_node('n3')
		n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
		n1.add_forwarding_entry(address=n3.get_address('n2'), link=n1.links[0])
		n2.add_forwarding_entry(address=n3.get_address('n2'), link=n2.links[1])

		net.nodes['n3'].add_protocol(protocol="delay", handler=d)

		n1_transmission_delay = 8000.0 / n1.links[0].bandwidth

		for j in range(0, 1001):
			protocol = None
			if (j > 995):
				protocol = 'delay'

			packet = Packet(destination_address=n3.get_address('n2'), ident=j, protocol=protocol, length=1000)
			delay = j * n1_transmission_delay
			Sim.scheduler.add(delay=delay, event=packet, handler=n1.send_packet)

		Sim.scheduler.run()
		print("\n")
Esempio n. 5
0
def main():
    # parameters
    Sim.scheduler.reset()
    Sim.set_debug(True)

    # setup network
    net = Network('../networks/five-nodes.txt')

    # get nodes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n3 = net.get_node('n3')
    n4 = net.get_node('n4')
    n5 = net.get_node('n5')

    # setup broadcast application
    b1 = BroadcastApp(n1)
    n1.add_protocol(protocol="broadcast", handler=b1)
    b2 = BroadcastApp(n2)
    n2.add_protocol(protocol="broadcast", handler=b2)
    b3 = BroadcastApp(n3)
    n3.add_protocol(protocol="broadcast", handler=b3)
    b4 = BroadcastApp(n4)
    n4.add_protocol(protocol="broadcast", handler=b4)
    b5 = BroadcastApp(n5)
    n5.add_protocol(protocol="broadcast", handler=b5)

    # send a broadcast packet from 1 with TTL 2, so everyone should get it
    p = Packet(source_address=n1.get_address('n2'),
               destination_address=0,
               ident=1,
               ttl=2,
               protocol='broadcast',
               length=100)
    Sim.scheduler.add(delay=0, event=p, handler=n1.send_packet)

    # send a broadcast packet from 1 with TTL 1, so just nodes 2 and 3
    # should get it
    p = Packet(source_address=n1.get_address('n2'),
               destination_address=0,
               ident=2,
               ttl=1,
               protocol='broadcast',
               length=100)
    print("this is an address of n2", n1.get_address('n3'))
    Sim.scheduler.add(delay=1, event=p, handler=n1.send_packet)

    # send a broadcast packet from 3 with TTL 1, so just nodes 1, 4, and 5
    # should get it
    p = Packet(source_address=n3.get_address('n1'),
               destination_address=0,
               ident=3,
               ttl=1,
               protocol='broadcast',
               length=100)
    Sim.scheduler.add(delay=2, event=p, handler=n3.send_packet)

    # run the simulation
    Sim.scheduler.run()
Esempio n. 6
0
def run_five_nodes_line():
    network = Network('./networks/five-nodes-line.txt')
    n1 = network.get_node('n1')
    n2 = network.get_node('n2')
    n3 = network.get_node('n3')
    n4 = network.get_node('n4')
    n5 = network.get_node('n5')
    run([n1, n2, n3, n4, n5])
Esempio n. 7
0
def main():
    # parameters
    Sim.scheduler.reset()

    # setup network
    #net = Network('./networks/five-nodes-line.txt')
    #net = Network('./networks/five-nodes-ring.txt')
    net = Network('./networks/fifteen-nodes.txt')

    # Setup broadcast protocol for all nodes in the network
    packet_count = 1
    for k, n in net.nodes.iteritems():
        b = BroadcastApp(n)
        ph = PacketHandler(k)
        n.add_protocol(protocol="broadcast", handler=b)
        n.add_protocol(protocol="transmit", handler=ph)
        n.init_routing()
        pbody = {
            "hostname": n.hostname,
            "dv": n.get_distance_vector()
        }
        p = Packet(
            destination_address=0,
            ident=packet_count, ttl=1, protocol='broadcast', body=pbody)
        Sim.scheduler.add(delay=0, event=p, handler=n.send_packet)
        packet_count = packet_count + 1

    # Send a packet after everything has been setup
    n1 = net.get_node('n1')
    n4 = net.get_node('n4')
    n5 = net.get_node('n5')
    daddr = 5
    p = Packet(destination_address=daddr, ident=2, protocol='transmit', length=1000)
    Sim.scheduler.add(delay=5, event=p, handler=n1.send_packet)

    if True:
        # Take a link down (between n5 and n1)
        Sim.scheduler.add(delay=10, event=None, handler=net.get_link(daddr-1).down)
        Sim.scheduler.add(delay=10, event=None, handler=net.get_link(daddr-1).down)

        # Send a packet
        p = Packet(destination_address=daddr, ident=3, protocol='transmit', length=1000)
        Sim.scheduler.add(delay=20, event=p, handler=n1.send_packet)

        # Bring the link back up
        Sim.scheduler.add(delay=30, event=None, handler=net.get_link(daddr-1).up)
        Sim.scheduler.add(delay=30, event=None, handler=net.get_link(daddr-1).up)

        # Send a packet
        p = Packet(destination_address=daddr, ident=2, protocol='transmit', length=1000)
        Sim.scheduler.add(delay=40, event=p, handler=n1.send_packet)


    # run the simulation
    Sim.scheduler.run()
Esempio n. 8
0
def main():
    # parameters
    Sim.scheduler.reset()

    # setup network
    net = Network('../networks/five-nodes.txt')

    # get nodes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n3 = net.get_node('n3')
    n4 = net.get_node('n4')
    n5 = net.get_node('n5')

    # setup broadcast application
    b1 = BroadcastApp(n1)
    n1.add_protocol(protocol="broadcast", handler=b1)
    b2 = BroadcastApp(n2)
    n2.add_protocol(protocol="broadcast", handler=b2)
    b3 = BroadcastApp(n3)
    n3.add_protocol(protocol="broadcast", handler=b3)
    b4 = BroadcastApp(n4)
    n4.add_protocol(protocol="broadcast", handler=b4)
    b5 = BroadcastApp(n5)
    n5.add_protocol(protocol="broadcast", handler=b5)

    # send a broadcast packet from 1 with TTL 2, so everyone should get it
    p = Packet(
        source_address=n1.get_address('n2'),
        destination_address=0,
        ident=1, ttl=2, protocol='broadcast', length=100)
    Sim.scheduler.add(delay=0, event=p, handler=n1.send_packet)

    # send a broadcast packet from 1 with TTL 1, so just nodes 2 and 3
    # should get it
    p = Packet(
        source_address=n1.get_address('n2'),
        destination_address=0,
        ident=2, ttl=1, protocol='broadcast', length=100)
    Sim.scheduler.add(delay=1, event=p, handler=n1.send_packet)

    # send a broadcast packet from 3 with TTL 1, so just nodes 1, 4, and 5
    # should get it
    p = Packet(
        source_address=n3.get_address('n1'),
        destination_address=0,
        ident=3, ttl=1, protocol='broadcast', length=100)
    Sim.scheduler.add(delay=2, event=p, handler=n3.send_packet)

    # run the simulation
    Sim.scheduler.run()
Esempio n. 9
0
def main():
    # parameters
    Sim.scheduler.reset()

    # setup network
    net = Network('../networks/one-hop.txt')

    # setup routes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
    n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

    # setup app
    d = DelayHandler()
    net.nodes['n2'].add_protocol(protocol="delay", handler=d)

    # setup packet generator
    destination = n2.get_address('n1')
    max_rate = 1000000 // (1000 * 8)
    load = 0.8 * max_rate
    g = Generator(node=n1, destination=destination, load=load, duration=10)
    Sim.scheduler.add(delay=0, event='generate', handler=g.handle)

    # run the simulation
    Sim.scheduler.run()
Esempio n. 10
0
def setup_network(config_path):
    Sim.scheduler.reset()
    # Sim.set_debug('Node')
    network = Network(config_path)
    n1 = network.get_node('n1')
    n2 = network.get_node('n2')
    n3 = network.get_node('n3')
    n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
    n1.add_forwarding_entry(address=n3.get_address('n2'), link=n1.links[0])
    n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])
    n2.add_forwarding_entry(address=n3.get_address('n2'), link=n2.links[1])
    n3.add_forwarding_entry(address=n1.get_address('n2'), link=n3.links[0])
    n3.add_forwarding_entry(address=n2.get_address('n3'), link=n3.links[0])
    delay_handler = DelayHandler()
    network.nodes['n3'].add_protocol(protocol='delay', handler=delay_handler)
    return n1, n2, n3
Esempio n. 11
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug(True)

        # setup network
        net = Network('../networks/one-hop.txt')

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        a = AppHandler(self.filename)

        # setup connection
        c1 = StopAndWait(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,a)
        c2 = StopAndWait(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,a)

        # send a file
        with open(self.filename,'r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)

        # run the simulation
        Sim.scheduler.run()
Esempio n. 12
0
def part1_2():
    # parameters
    Sim.scheduler.reset()

    # setup network
    net = Network('../networks/lab1/2nodes-2.txt')

    # setup routes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
    n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

    # setup app
    d = DelayHandler()
    net.nodes['n2'].add_protocol(protocol="delay", handler=d)

    # send one packet
    p = Packet(destination_address=n2.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=0, event=p, handler=n1.send_packet)

    # run the simulation
    Sim.scheduler.run()
Esempio n. 13
0
def setup_network(config_path):
    Sim.scheduler.reset()
    network = Network(config_path)
    n1 = network.get_node('n1')
    n2 = network.get_node('n2')
    n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
    n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])
    return network, n1, n2
Esempio n. 14
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        Sim.set_debug('TCP')
        Sim.set_debug('Plot')

        # setup network
        net = Network('./networks/one-hop.txt')
        net.loss(self.loss)

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        a = AppHandler(self.filename)

        # setup connection
        c1 = TCP(t1,
                 n1.get_address('n2'),
                 1,
                 n2.get_address('n1'),
                 1,
                 a,
                 window=self.window,
                 drop=self.drops)
        c2 = TCP(t2,
                 n2.get_address('n1'),
                 1,
                 n1.get_address('n2'),
                 1,
                 a,
                 window=self.window,
                 drop=self.drops)

        # setup fast retransmit
        if self.fast_retransmit:
            c1.set_fast_retransmit_enabled(True)
            c2.set_fast_retransmit_enabled(True)

        # send a file
        with open(self.filename, 'rb') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)

        # run the simulation
        Sim.scheduler.run()
Esempio n. 15
0
    def run(self):
        drop_packets = [14000, 26000, 28000]
        Sim.set_debug('Plot')

        # setup network
        net = Network('basic.txt')

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        plotter = Plotter()

        for i in range(0, 4):
            application = AppHandler(self.filename)
            Sim.scheduler.reset()
            Sim.files = {}

            # setup connection
            c1 = TCP(t1,
                     n1.get_address('n2'),
                     1,
                     n2.get_address('n1'),
                     1,
                     application,
                     fast_retransmit=True,
                     drop=drop_packets[:i])
            TCP(t2,
                n2.get_address('n1'),
                1,
                n1.get_address('n2'),
                1,
                application,
                fast_retransmit=True)

            # send a file
            with open(self.filename, 'rb') as f:
                while True:
                    data = f.read()
                    if not data:
                        break
                    Sim.scheduler.add(delay=0, event=data, handler=c1.send)

            Sim.scheduler.run()
            for filename, file in Sim.files.iteritems():
                file.close()

            plotter.sequence("sequence" + str(i + 1) + ".png")
            plotter.cwnd("cwnd" + str(i + 1) + ".png")

            self.diff()
Esempio n. 16
0
    def run(self):
        # parameters
        Sim.scheduler.reset()

        # setup network
        net = Network('experiment.txt')
        net.loss(self.loss)

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        a = AppHandler(self.filename)

        # setup connection
        c1 = TCP(t1,
                 n1.get_address('n2'),
                 1,
                 n2.get_address('n1'),
                 1,
                 a,
                 window=self.window,
                 fast_retransmit=self.fast_retransmit,
                 measure=True)
        TCP(t2,
            n2.get_address('n1'),
            1,
            n1.get_address('n2'),
            1,
            a,
            window=self.window,
            fast_retransmit=self.fast_retransmit,
            measure=True)

        # send a file
        with open(self.filename, 'rb') as f:
            while True:
                data = f.read()
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)

        Sim.scheduler.run()
        result_file = open("results.txt", "r")
        results = result_file.read()
        result_file.close()
        f = open("experiment.csv", "a")
        f.write(str(self.window) + "," + results + "\n")
Esempio n. 17
0
    def run(self, janela, perda, fila, fast):

        self.filename = fila
        loss = perda
        Sim.trace('Trans', "It is %s that I am using fast transmit." % (fast))

        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        Sim.set_debug('TCP')
        Sim.set_debug('Trans')

        # setup network
        net = Network('./network.txt')
        net.loss(loss)

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        net.set_queue(n1.links[0], "100")
        net.set_queue(n2.links[0], "100")

        n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        a = AppHandler(self.filename)

        # setup connection
        c1 = TCP(t1, n1.get_address('n2'), 1, n2.get_address('n1'), 1, a,
                 janela, fast)
        c2 = TCP(t2, n2.get_address('n1'), 1, n1.get_address('n2'), 1, a,
                 janela, fast)

        # send a file
        with open(self.filename, 'rb') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)

        # run the simulation
        Sim.scheduler.run()

        self.diff()

        self.filename = None

        return Sim.scheduler.current_time()
Esempio n. 18
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        Sim.set_debug('TCP')

        # setup network
        net = Network('network.txt')
        net.loss(self.loss)

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        a = AppHandler(self.filename)

        # setup connection
        c1 = TCP(t1,
                 n1.get_address('n2'),
                 1,
                 n2.get_address('n1'),
                 1,
                 a,
                 window=self.window,
                 fast_retransmit=self.fast_retransmit)
        c2 = TCP(t2,
                 n2.get_address('n1'),
                 1,
                 n1.get_address('n2'),
                 1,
                 a,
                 window=self.window,
                 fast_retransmit=self.fast_retransmit)

        # send a file
        with open(self.filename, 'rb') as f:
            while True:
                data = f.read(10000)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)

        # run the simulation
        Sim.scheduler.run()
        if self.print_queueing_delay:
            print('average queueing delay: {}'.format(
                c2.total_queueing_delay / c2.total_packets_received))
Esempio n. 19
0
def part2_1():
    # parameters

    Sim.scheduler.reset()

    # setup network
    net = Network('../networks/lab1/3nodes-1.txt')

    # setup routes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n3 = net.get_node('n3')
    n1.add_forwarding_entry(address=n3.get_address('n1'), link=n1.links[0])
    n1.add_forwarding_entry(address=n3.get_address('n2'), link=n1.links[0])
    n2.add_forwarding_entry(address=n3.get_address('n2'), link=n2.links[0])

    # setup app
    d2 = ForwardHandler()
    net.nodes['n2'].add_protocol(protocol="delay", handler=d2)
    d3 = DelayHandler()
    net.nodes['n3'].add_protocol(protocol="delay", handler=d3)

    # send one packet
    p1 = Packet(destination_address=n3.get_address('n2'),
                ident=1,
                protocol='delay',
                length=1000)
    Sim.scheduler.add(delay=0, event=p1, handler=n1.send_packet)

    # p2 = Packet(destination_address=n2.get_address('n1'), ident=2, protocol='delay', length=1000)
    # Sim.scheduler.add(delay=0, event=p2, handler=n1.send_packet)

    # p3 = Packet(destination_address=n2.get_address('n1'), ident=3, protocol='delay', length=1000)
    # Sim.scheduler.add(delay=0, event=p3, handler=n1.send_packet)

    # p4 = Packet(destination_address=n2.get_address('n1'), ident=4, protocol='delay', length=1000)
    # Sim.scheduler.add(delay=2, event=p4, handler=n1.send_packet)

    # run the simulation
    Sim.scheduler.run()
Esempio n. 20
0
def main():
    # parameters
    Sim.scheduler.reset()
    Sim.set_debug("Node")

    # setup network
    net = Network("test1network.txt")
    for hostname, node in sorted(net.nodes.iteritems()):
        node.add_protocol(protocol="dvrouting", handler=RoutingApp(node))

    n5 = net.get_node("n5")
    n5.add_protocol(protocol="delay", handler=DelayHandler())

    p = Packet(destination_address=n5.get_address("n4"),
               ident=1,
               protocol="delay",
               length=1000)
    n1 = net.get_node("n1")
    Sim.scheduler.add(delay=3.2, event=p, handler=n1.send_packet)

    # run the simulation
    Sim.scheduler.run()
Esempio n. 21
0
def main():
    # parameters
    Sim.scheduler.reset()
    Sim.set_debug("Node")

    # setup network
    net = Network("test3network.txt")
    for hostname, node in sorted(net.nodes.iteritems()):
        node.add_protocol(protocol="dvrouting", handler=RoutingApp(node))

    n7 = net.get_node("n7")
    n7.add_protocol(protocol="delay", handler=DelayHandler())
    n10 = net.get_node("n10")
    n10.add_protocol(protocol="delay", handler=DelayHandler())
    n15 = net.get_node("n15")
    n15.add_protocol(protocol="delay", handler=DelayHandler())

    n8 = net.get_node("n8")
    n11 = net.get_node("n11")
    n12 = net.get_node("n12")

    p1 = Packet(destination_address=n7.get_address("n6"),
                ident=1,
                protocol="delay",
                length=1000)
    Sim.scheduler.add(delay=4.2, event=p1, handler=n12.send_packet)
    p3 = Packet(destination_address=n15.get_address("n14"),
                ident=2,
                protocol="delay",
                length=1000)
    Sim.scheduler.add(delay=4.3, event=p3, handler=n11.send_packet)
    p2 = Packet(destination_address=n10.get_address("n1"),
                ident=3,
                protocol="delay",
                length=1000)
    Sim.scheduler.add(delay=4.4, event=p2, handler=n8.send_packet)

    n2 = net.get_node("n2")
    Sim.scheduler.add(delay=4.8, event=None, handler=n2.get_link("n8").down)
    Sim.scheduler.add(delay=4.8, event=None, handler=n8.get_link("n2").down)

    p4 = Packet(destination_address=n10.get_address("n1"),
                ident=4,
                protocol="delay",
                length=1000)
    Sim.scheduler.add(delay=10.4, event=p4, handler=n8.send_packet)

    Sim.scheduler.add(delay=10.8, event=None, handler=n2.get_link("n8").up)
    Sim.scheduler.add(delay=10.8, event=None, handler=n8.get_link("n2").up)

    p5 = Packet(destination_address=n10.get_address("n1"),
                ident=5,
                protocol="delay",
                length=1000)
    Sim.scheduler.add(delay=16.4, event=p5, handler=n8.send_packet)

    # run the simulation
    Sim.scheduler.run()
Esempio n. 22
0
File: q3.py Progetto: joe-eklund/tcp
def setupNetwork():
    # parameters
    Sim.scheduler.reset()

    # setup network
    net = Network('../networks/3.txt')

    # setup routes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
    n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

    return n1, n2, net
Esempio n. 23
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        Sim.set_debug('TCP')
        Sim.set_debug('Plot')

        # setup network
        net = Network('basic.txt')
        net.loss(self.loss)

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        a = AppHandler(self.filename)

        # setup connection
        c1 = TCP(t1,
                 n1.get_address('n2'),
                 1,
                 n2.get_address('n1'),
                 1,
                 a,
                 window=self.window)
        TCP(t2,
            n2.get_address('n1'),
            1,
            n1.get_address('n2'),
            1,
            a,
            window=self.window)

        # send a file
        with open(self.filename, 'rb') as f:
            while True:
                data = f.read()
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)

        Sim.scheduler.run()
Esempio n. 24
0
File: q2.py Progetto: joe-eklund/tcp
def setupNetwork(path):
	# parameters
	Sim.scheduler.reset()

	# setup network
	net = Network(path)

	# setup routes
	n1 = net.get_node('n1')
	n2 = net.get_node('n2')
	n3 = net.get_node('n3')
	n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
	n1.add_forwarding_entry(address=n3.get_address('n2'),link=n1.links[0])
	n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])
	n2.add_forwarding_entry(address=n3.get_address('n2'),link=n2.links[1])
	n3.add_forwarding_entry(address=n1.get_address('n2'),link=n3.links[0])
	n3.add_forwarding_entry(address=n2.get_address('n3'),link=n3.links[0])

	# setup app
	d = DelayHandler()
	net.nodes['n1'].add_protocol(protocol="delay",handler=d)
	net.nodes['n2'].add_protocol(protocol="delay",handler=d)
	net.nodes['n3'].add_protocol(protocol="delay",handler=d)
	return n1, n2, n3, net
Esempio n. 25
0
def run_fifteen_nodes():
    network = Network('./networks/fifteen-nodes.txt')
    n1 = network.get_node('n1')
    n2 = network.get_node('n2')
    n3 = network.get_node('n3')
    n4 = network.get_node('n4')
    n5 = network.get_node('n5')
    n6 = network.get_node('n6')
    n7 = network.get_node('n7')
    n8 = network.get_node('n8')
    n9 = network.get_node('n9')
    n10 = network.get_node('n10')
    n11 = network.get_node('n11')
    n12 = network.get_node('n12')
    n13 = network.get_node('n13')
    n14 = network.get_node('n14')
    n15 = network.get_node('n15')
    run([n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15])
Esempio n. 26
0
def exp3():
    # parameters
    Sim.scheduler.reset()
    Sim.set_debug(True)

    # setup network
    net = Network('../networks/l4e3.txt')

    # get nodes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n3 = net.get_node('n3')
    n4 = net.get_node('n4')
    n5 = net.get_node('n5')
    n6 = net.get_node('n6')
    n7 = net.get_node('n7')
    n8 = net.get_node('n8')
    n9 = net.get_node('n9')
    n10 = net.get_node('n10')
    n11 = net.get_node('n11')
    n12 = net.get_node('n12')
    n13 = net.get_node('n13')
    n14 = net.get_node('n14')
    n15 = net.get_node('n15')

    # setup broadcast application
    p_setup(n1)
    p_setup(n2)
    p_setup(n3)
    p_setup(n4)
    p_setup(n5)
    p_setup(n6)
    p_setup(n7)
    p_setup(n8)
    p_setup(n9)
    p_setup(n10)
    p_setup(n11)
    p_setup(n12)
    p_setup(n13)
    p_setup(n14)
    p_setup(n15)

    # run the simulation
    Sim.scheduler.run()
Esempio n. 27
0
def main():
    # parameters
    Sim.scheduler.reset()

    # setup network
    net = Network('../networks/one-hop.txt')

    # setup routes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
    n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

    # setup app
    d = DelayHandler()
    net.nodes['n2'].add_protocol(protocol="delay", handler=d)

    # send one packet
    p = Packet(destination_address=n2.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=0, event=p, handler=n1.send_packet)

    # take the link down
    Sim.scheduler.add(delay=1, event=None, handler=n1.get_link('n2').down)

    # send one packet (it won't go through)
    p = Packet(destination_address=n2.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=1.1, event=p, handler=n1.send_packet)

    # bring the link up
    Sim.scheduler.add(delay=2, event=None, handler=n1.get_link('n2').up)

    # send one packet (and now it goes through)
    p = Packet(destination_address=n2.get_address('n1'),
               ident=1,
               protocol='delay',
               length=1000)
    Sim.scheduler.add(delay=2.1, event=p, handler=n1.send_packet)

    # run the simulation
    Sim.scheduler.run()
Esempio n. 28
0
    def run(self):
        # parameters
        Sim.scheduler.reset()

        if "a" in self.debug:
            Sim.set_debug('AppHandler')
        if "t" in self.debug:
            Sim.set_debug('TCP')

        # setup network
        net = Network('networks/one-hop.txt')
        net.loss(self.loss)

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        a = AppHandler(self.inputfile)

        # setup connection
        c1 = TCP(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,a,window=self.window,type=self.type)
        c2 = TCP(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,a,window=self.window,type=self.type)

        global original_size
        f = open(self.inputfile, "rb")
        try:
            data = f.read(1000)
            while data != "":
                original_size += len(data)
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)
                data = f.read(1000)
        finally:
            f.close()

        # run the simulation
        Sim.scheduler.run()

        plotter.plot(self.sequencefile);
Esempio n. 29
0
def part3(load):
    Sim.scheduler.reset()
    net = Network('../networks/one-hop.txt')
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')

    n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
    n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

    d = DelayHandler()
    net.nodes['n2'].add_protocol(protocol="delay", handler=d)

    destination = n2.get_address('n1')
    max_rate = 1000000 // (1000 * 8)
    load = load * max_rate
    g = Generator(node=n1, destination=destination, load=load, duration=60)
    Sim.scheduler.add(delay=0, event='generate', handler=g.handle)

    Sim.scheduler.run()
Esempio n. 30
0
    def run(self):
        # parameters
        Sim.scheduler.reset()

        if hasattr(self, 'debug') and "a" in self.debug:
            Sim.set_debug('AppHandler')
        if hasattr(self, 'debug') and "t" in self.debug:
            Sim.set_debug('TCP')

        # setup network
        net = Network('networks/one-hop.txt')
        net.loss(self.loss)

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        a = AppHandler(self.filename)

        # setup connection
        c1 = TCP(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,a,dynamic_rto=self.dynamic_rto)
        c2 = TCP(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,a,dynamic_rto=self.dynamic_rto)

        f = open(self.filename, "rb")
        try:
            data = f.read(1000)
            while data != "":
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)
                data = f.read(1000)
        finally:
            f.close()

        # run the simulation
        Sim.scheduler.run()
Esempio n. 31
0
def main():
    # parameters
    Sim.scheduler.reset()

    # setup network
    net = Network('twonodes3.txt')

    # setup routes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
    n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

    # setup app
    d = DelayHandler()
    net.nodes['n2'].add_protocol(protocol="delay", handler=d)

    # send one packet
    p1 = Packet(destination_address=n2.get_address('n1'),
                ident=1,
                protocol='delay',
                length=1000)
    Sim.scheduler.add(delay=0, event=p1, handler=n1.send_packet)
    p2 = Packet(destination_address=n2.get_address('n1'),
                ident=2,
                protocol='delay',
                length=1000)
    Sim.scheduler.add(delay=0, event=p2, handler=n1.send_packet)
    p3 = Packet(destination_address=n2.get_address('n1'),
                ident=3,
                protocol='delay',
                length=1000)
    Sim.scheduler.add(delay=0, event=p3, handler=n1.send_packet)
    p4 = Packet(destination_address=n2.get_address('n1'),
                ident=4,
                protocol='delay',
                length=1000)
    Sim.scheduler.add(delay=2, event=p4, handler=n1.send_packet)

    # run the simulation
    Sim.scheduler.run()
Esempio n. 32
0
def main():
    global f
    # setup network
    net = Network('./queuetest.txt')

    # setup routes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
    n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

    # setup app
    d = DelayHandler()
    net.nodes['n2'].add_protocol(protocol="delay", handler=d)

    duration = 30
    timer = 0

    for i in range(0, len(network_loads)):
        # parameters
        Sim.scheduler.reset()

        # setup packet generator
        destination = n2.get_address('n1')
        max_rate = 1000000 // (1000 * 8)

        load = network_loads[i] * max_rate
        g = Generator(node=n1,
                      destination=destination,
                      load=load,
                      duration=duration)
        Sim.scheduler.add(delay=0, event='generate', handler=g.handle)

        f = open("queueingtest" + str(i + 1) + ".csv", "w")
        # run the simulation
        Sim.scheduler.run()

        timer += duration

        f.close()
Esempio n. 33
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        Sim.set_debug('TCP')

        # setup network
        net = Network('../networks/one-hop.txt')
        net.loss(self.loss)

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')

        n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])  # n1 -> n2
        n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])  # n1 <- n2

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        tcp_flows = 1
        a1 = AppHandler(self.filename, 1)

        # setup connection
        c1a = TCP(t1, n1.get_address('n2'), 1, n2.get_address('n1'), 1, 3000, a1)
        c2a = TCP(t2, n2.get_address('n1'), 1, n1.get_address('n2'), 1, 3000, a1)

        # send a file
        with open(self.filename,'r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1a.send)

        # run the simulation
        Sim.scheduler.run()
        return tcp_flows
Esempio n. 34
0
def main():
    # parameters
    Sim.scheduler.reset()

    # setup network
    net = Network('../networks/one-hop.txt')

    # setup routes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
    n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

    # setup app
    d = DelayHandler()
    net.nodes['n2'].add_protocol(protocol="delay", handler=d)

    # send one packet
    p = Packet(destination_address=n2.get_address('n1'), ident=1, protocol='delay', length=1000)
    Sim.scheduler.add(delay=0, event=p, handler=n1.send_packet)

    # take the link down
    Sim.scheduler.add(delay=1, event=None, handler=n1.get_link('n2').down)

    # send one packet (it won't go through)
    p = Packet(destination_address=n2.get_address('n1'), ident=1, protocol='delay', length=1000)
    Sim.scheduler.add(delay=1.1, event=p, handler=n1.send_packet)

    # bring the link up
    Sim.scheduler.add(delay=2, event=None, handler=n1.get_link('n2').up)

    # send one packet (and now it goes through)
    p = Packet(destination_address=n2.get_address('n1'), ident=1, protocol='delay', length=1000)
    Sim.scheduler.add(delay=2.1, event=p, handler=n1.send_packet)

    # run the simulation
    Sim.scheduler.run()
Esempio n. 35
0
def main():
    d = DelayHandler()
    for i in range(1, 4):
        print("SIMULATION NO. " + str(i))
        Sim.scheduler.reset()

        net = Network('./twonodes' + str(i) + '.txt')

        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

        net.nodes['n2'].add_protocol(protocol="delay", handler=d)

        if (i == 3):
            for j in range(0, 4):
                packet = Packet(destination_address=n2.get_address('n1'),
                                ident=j,
                                protocol='delay',
                                length=1000)
                if j == 3:
                    delay = 2
                else:
                    delay = 0
                Sim.scheduler.add(delay=delay,
                                  event=packet,
                                  handler=n1.send_packet)
        else:
            packet = Packet(destination_address=n2.get_address('n1'),
                            ident=0,
                            protocol='delay',
                            length=1000)
            Sim.scheduler.add(delay=0, event=packet, handler=n1.send_packet)

        Sim.scheduler.run()
Esempio n. 36
0
def run_simulation(network_file, output_file, utilization=1.0):
    """
    Abstracted method to run a simulation of queuing delay at a specified utilization for the network. Using a network
    configuration file, it creates a network and then writes the results of the simulation to the provided output
    file.
    :param network_file: The path to the network configuration file
    :param output_file: The path to the file to write the result networks to
    :param utilization: A floating point number that specifies at what percentage of the maximum transfer rate the
                        simulation should run the network
    """
    Sim.scheduler.reset()

    network = Network(network_file)

    # setup routes
    n1 = network.get_node('n1')
    n2 = network.get_node('n2')
    n1.add_forwarding_entry(address=n2.get_address('n1'), link=n1.links[0])
    n2.add_forwarding_entry(address=n1.get_address('n2'), link=n2.links[0])

    # setup app
    d = DataWrangler(utilization)
    network.nodes['n2'].add_protocol(protocol="delay", handler=d)

    # setup packet generator
    destination = n2.get_address('n1')
    packet_size = 1000
    max_rate = n1.links[0].bandwidth /  (packet_size * 8)
    load = utilization * max_rate
    g = Generator(node=n1, destination=destination, load=load, duration=10)
    Sim.scheduler.add(delay=0, event='generate', handler=g.handle)

    # run the simulation
    Sim.scheduler.run()

    d.write_to_file(output_file)
Esempio n. 37
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        Sim.set_debug('TCP')

        # setup network
        if self.use_queue:
            net = Network('networks/one-hop-queue.txt')
        else:
            net = Network('networks/one-hop.txt')
        net.loss(self.loss)

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        a = AppHandler(self.filename)

        # setup connection
        c1 = TCP(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,a,window=self.window)
        c2 = TCP(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,a,window=self.window)

        # send a file
        with open(self.filename,'r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)

        # run the simulation
        Sim.scheduler.run()

        # print some results
        print
        print "========== Overall results =========="
        time = Sim.scheduler.current_time()
        print "Total time: %f seconds" % time
        avg = numpy.mean(c2.queueing_delay_list)
        print "Average queueing delay: %f" % avg
        max = numpy.max(c2.queueing_delay_list)
        print "Max queueing delay: %f" % max
        file_size = os.path.getsize(self.filename)
        print "File size: %i" % file_size
        throughput = file_size / time
        print "Throughput: %f" % throughput

        print "%i,%f,%f,%f,%i,%f\n" % (self.window,time,avg,max,file_size,throughput)
        if self.loss == 0.0:
            print "Outputing results to experiment.csv"
            output_fh = open('experiment.csv', 'a')
            output_fh.write("%i,%f,%f,%f,%i,%f\n" % (self.window,time,avg,max,file_size,throughput))
            output_fh.close()
Esempio n. 38
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        #Sim.set_debug('AppHandler')
        #Sim.set_debug('TCP')
        Sim.set_debug('Link')

        net = Network('networks/competing.txt')
        net.loss(self.loss)

        # setup routes
        # n1 - n3 - n4
        #      |
        #     n2
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n3 = net.get_node('n3')
        n4 = net.get_node('n4')

        # n1 forwarding entries
        n1.add_forwarding_entry(address=n3.get_address('n1'),link=n1.links[0])
        n1.add_forwarding_entry(address=n4.get_address('n3'),link=n1.links[0])

        # n2 forwarding entries
        n2.add_forwarding_entry(address=n3.get_address('n2'),link=n2.links[0])
        n2.add_forwarding_entry(address=n4.get_address('n3'),link=n2.links[0])

        # n3 forwarding entries
        n3.add_forwarding_entry(address=n1.get_address('n3'),link=n3.links[0])
        n3.add_forwarding_entry(address=n2.get_address('n3'),link=n3.links[1])
        n3.add_forwarding_entry(address=n4.get_address('n3'),link=n3.links[2])

        # n4 forwarding entries
        n4.add_forwarding_entry(address=n1.get_address('n3'),link=n4.links[0])
        n4.add_forwarding_entry(address=n2.get_address('n3'),link=n4.links[0])
        n4.add_forwarding_entry(address=n3.get_address('n4'),link=n4.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)
        t4 = Transport(n4)

        # setup application
        a1 = AppHandler('test1.txt')
        a2 = AppHandler('test2.txt')

        # setup connection
        c1 = TCP(t1,n1.get_address('n3'),1,n4.get_address('n3'),1,a1,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
        c2 = TCP(t4,n4.get_address('n3'),1,n1.get_address('n3'),1,a1,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)

        c3 = TCP(t2,n2.get_address('n3'),2,n4.get_address('n3'),2,a2,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
        c4 = TCP(t4,n4.get_address('n3'),2,n2.get_address('n3'),2,a2,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)

        # send a file
        with open('test1.txt','r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)
        with open('test2.txt','r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c3.send)

        # run the simulation
        Sim.scheduler.run()

        # print some results
        print
        print "========== Overall results =========="
        time = Sim.scheduler.current_time()
        print "Total time: %f seconds" % time
        avg = numpy.mean(c2.queueing_delay_list)
        print "Average queueing delay: %f" % avg
        max = numpy.max(c2.queueing_delay_list)
        print "Max queueing delay: %f" % max
        file_size = os.path.getsize(self.filename)
        print "File size: %i" % file_size
        throughput = file_size / time
        print "Throughput: %f" % throughput

        # Variables for debugging
        self.c3 = c3
        self.c4 = c4
        self.c2 = c2
        self.c1 = c1
        self.t1 = t1
        self.t2 = t2
        self.net = net
        linkab = n1.links[0]
        self.linkab = linkab
        l = linkab

        # Plotting
        plotter = Plotter()

        # Plot sequence charts
        plotter.clear()
        plotter.create_sequence_plot(c1.x, c1.y, c1.dropX, c1.dropY, c1.ackX, c1.ackY, chart_name='advanced/competingRtt/sequence1.png')
        plotter.clear()
        plotter.create_sequence_plot(c3.x, c3.y, c3.dropX, c3.dropY, c3.ackX, c3.ackY, chart_name='advanced/competingRtt/sequence2.png')

        # Plot receiver rate
        plotter.clear()
        plotter.rateTimePlot(c2.packets_received, Sim.scheduler.current_time(), chart_name=None)
        plotter.rateTimePlot(c4.packets_received, Sim.scheduler.current_time(), chart_name='advanced/competingRtt/rateTime.png')

        # Plot queue size
        plotter.clear()
        plotter.queueSizePlot(l.queue_log_x, l.queue_log_y, l.dropped_packets_x, l.dropped_packets_y, chart_name='advanced/competingRtt/queueSize.png')

        # Plot congestion window
        plotter.clear()
        plotter.windowSizePlot(c1.window_x, c1.window_y, chart_name="advanced/competingRtt/windowSize1.png")
        plotter.clear()
        plotter.windowSizePlot(c3.window_x, c3.window_y, chart_name="advanced/competingRtt/windowSize2.png")
Esempio n. 39
0
if __name__ == '__main__':
    # parameters

    percentages = [.1, .2, .3, .4, .5, .6, .7, .75, .8, .9, .95, .98]

    max_rate = 1000000/(1000*8)

    for percentage in percentages:
        for x in range (0, 3):
            Sim.scheduler.reset()

            # setup network
            net = Network('networks/one-hop.txt')

            # setup routes
            n1 = net.get_node('n1')
            n2 = net.get_node('n2')
            n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
            n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])

            # setup app
            d = DelayHandler(percentage=percentage)
            net.nodes['n2'].add_protocol(protocol="delay",handler=d)

            # setup packet generator
            destination = n2.get_address('n1')
            load = percentage*max_rate
            g = Generator(node=n1,destination=destination,load=load,duration=10)
            Sim.scheduler.add(delay=0, event='generate', handler=g.handle)
    
            # run the simulation
Esempio n. 40
0
	def __init__(self, node):
		self.node = node

    def receive_packet(self,packet):
        print Sim.scheduler.current_time(),packet.ident,packet.created,Sim.scheduler.current_time() - packet.created,packet.transmission_delay,packet.propagation_delay,packet.queueing_delay, self.node.hostname

if __name__ == '__main__':
	# parameters
	Sim.scheduler.reset()
	Sim.set_debug(True)

	# setup network
	net = Network('../networks/five-nodes-line.txt')

	# get nodes
	n1 = net.get_node('n1')
	n2 = net.get_node('n2')
	n3 = net.get_node('n3')
	n4 = net.get_node('n4')
	n5 = net.get_node('n5')

	# setup broadcast application
	b1 = BroadcastApp(n1)
	n1.add_protocol(protocol="broadcast",handler=b1)
	b2 = BroadcastApp(n2)
	n2.add_protocol(protocol="broadcast",handler=b2)
	b3 = BroadcastApp(n3)
	n3.add_protocol(protocol="broadcast",handler=b3)
	b4 = BroadcastApp(n4)
	n4.add_protocol(protocol="broadcast",handler=b4)
	b5 = BroadcastApp(n5)
    def __init__(self, node):
        self.node = node

    def receive_packet(self, packet):
        print "%s - (%s) Packet ARRIVED - Data: %s; Source_Address: %s; Destination_Address: %s" % (Sim.scheduler.current_time(), self.node.hostname, packet.body, packet.source_address, packet.destination_address)

if __name__ == '__main__':
    # parameters
    Sim.scheduler.reset()
    Sim.set_debug(True)

    # setup network
    net = Network('../networks/fifteen-nodes.txt')

    # get nodes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n3 = net.get_node('n3')
    n4 = net.get_node('n4')
    n5 = net.get_node('n5')
    n6 = net.get_node('n6')
    n7 = net.get_node('n7')
    n8 = net.get_node('n8')
    n9 = net.get_node('n9')
    n10 = net.get_node('n10')
    n11 = net.get_node('n11')
    n12 = net.get_node('n12')
    n13 = net.get_node('n13')
    n14 = net.get_node('n14')
    n15 = net.get_node('n15')
Esempio n. 42
0
    def endOutput(self):
        outputFile.close()


if __name__ == "__main__":
    outputFile = open("output-problem2-1b.txt", "w")

    # parameters
    Sim.scheduler.reset()

    # setup network
    net = Network("config-3n-1Gbps-1Gbps-100ms-100ms.txt")

    # setup routes
    n1 = net.get_node("n1")
    n2 = net.get_node("n2")
    n3 = net.get_node("n3")

    # setup forwarding entries
    a2 = n2.get_address("n1")
    a1 = n1.get_address("n2")
    a3 = n3.get_address("n2")

    n1.add_forwarding_entry(address=a2, link=n1.links[0])
    n2.add_forwarding_entry(address=a1, link=n2.links[0])
    n2.add_forwarding_entry(address=a3, link=n2.links[1])
    n3.add_forwarding_entry(address=a2, link=n3.links[0])

    # if packet is going from n1 -> n3
    n1.add_forwarding_entry(address=a3, link=n1.links[0])
Esempio n. 43
0
        f.write("Packet Created:\t\t{:f}\n".format(packet.created))
        f.write("Packet Identifier:\t{:d}\n".format(packet.ident))
        f.write("Time Received:\t\t{:f}\n\n".format(Sim.scheduler.current_time()))
        f.close()

if __name__ == '__main__':
    # ------------------------- 2 nodes, 1Mbps, 1s, 1 packet, 1000 bytes ------------------------- #

    # parameters
    Sim.scheduler.reset()

    # setup network
    net = Network('../../networks/lab1/2-nodes/1Mbps-1s.txt')

    # setup routes
    n1 = net.get_node('n1')
    n2 = net.get_node('n2')
    n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
    n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])

    # setup app
    filename = "../../out/lab1/2-nodes/1Mbps-1s-1packet-1000bytes.txt"
    description = "2 Nodes - 1 packet\n1Mbps, 1s, 1 packet, 1000 bytes\n\n"
    t = TransmitApp(n2, filename, description)
    n2.add_protocol(protocol="delay", handler=t)

    # send one packet
    p = packet.Packet(destination_address=n2.get_address('n1'),ident=1,protocol='delay',length=1000)
    Sim.scheduler.add(delay=0, event=p, handler=n1.send_packet)

    # run the simulation
Esempio n. 44
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        #Sim.set_debug('AppHandler')
        #Sim.set_debug('TCP')
        Sim.set_debug('Link')

        net = Network('networks/one.txt')
        net.loss(self.loss)

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        a1 = AppHandler('test.txt')

        # setup connection
        c1 = TCP(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,a1,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery,aiad=True)
        c2 = TCP(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,a1,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery,aiad=True)

        # send a file
        with open('test.txt','r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)

        # run the simulation
        Sim.scheduler.run()

        # print some results
        print
        print "========== Overall results =========="
        time = Sim.scheduler.current_time()
        print "Total time: %f seconds" % time
        avg = numpy.mean(c2.queueing_delay_list)
        print "Average queueing delay: %f" % avg
        max = numpy.max(c2.queueing_delay_list)
        print "Max queueing delay: %f" % max
        file_size = os.path.getsize(self.filename)
        print "File size: %i" % file_size
        throughput = file_size / time
        print "Throughput: %f" % throughput

        plotter = Plotter()
        print "Saving the sequence plot"
        plotter.create_sequence_plot(c1.x, c1.y, c1.dropX, c1.dropY, c1.ackX, c1.ackY, chart_name='advanced/aiad/sequence.png')

        plotter.clear()
        plotter.rateTimePlot(c2.packets_received, Sim.scheduler.current_time(), 'advanced/aiad/rateTime1.png')

        linkab = n1.links[0]
        self.linkab = linkab
        plotter.clear()
        plotter.queueSizePlot(linkab.queue_log_x, linkab.queue_log_y, linkab.dropped_packets_x, linkab.dropped_packets_y, chart_name='advanced/aiad/queueSize.png')

        plotter.clear()
        plotter.windowSizePlot(c1.window_x, c1.window_y, chart_name="advanced/aiad/windowSize1.png")
Esempio n. 45
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        #Sim.set_debug('AppHandler')
        #Sim.set_debug('TCP')
        Sim.set_debug('Link')

        net = Network('networks/five.txt')
        net.loss(self.loss)

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])
        n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])

        # setup transport
        t1 = Transport(n1)
        t2 = Transport(n2)

        # setup application
        a1 = AppHandler('test1.txt')
        a2 = AppHandler('test2.txt')
        a3 = AppHandler('test3.txt')
        a4 = AppHandler('test4.txt')
        a5 = AppHandler('test5.txt')

        # setup connection
        c1 = TCP(t1,n1.get_address('n2'),1,n2.get_address('n1'),1,a1,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
        c2 = TCP(t2,n2.get_address('n1'),1,n1.get_address('n2'),1,a1,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)

        c3 = TCP(t1,n1.get_address('n2'),2,n2.get_address('n1'),2,a2,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
        c4 = TCP(t2,n2.get_address('n1'),2,n1.get_address('n2'),2,a2,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)

        c5 = TCP(t1,n1.get_address('n2'),3,n2.get_address('n1'),3,a3,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
        c6 = TCP(t2,n2.get_address('n1'),3,n1.get_address('n2'),3,a3,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)

        c7 = TCP(t1,n1.get_address('n2'),4,n2.get_address('n1'),4,a4,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
        c8 = TCP(t2,n2.get_address('n1'),4,n1.get_address('n2'),4,a4,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)

        c9 = TCP(t1,n1.get_address('n2'),5,n2.get_address('n1'),5,a5,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)
        c0 = TCP(t2,n2.get_address('n1'),5,n1.get_address('n2'),5,a5,window=self.window,threshold=self.threshold,fast_recovery=self.fast_recovery)

        # send a file
        with open('test1.txt','r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)
        with open('test2.txt','r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=1.5, event=data, handler=c3.send)
        with open('test3.txt','r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=2, event=data, handler=c5.send)
        with open('test4.txt','r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=2.5, event=data, handler=c7.send)
        with open('test5.txt','r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=3, event=data, handler=c9.send)

        # run the simulation
        Sim.scheduler.run()

        # print some results
        print
        print "========== Overall results =========="
        time = Sim.scheduler.current_time()
        print "Total time: %f seconds" % time
        avg = numpy.mean(c2.queueing_delay_list)
        print "Average queueing delay: %f" % avg
        max = numpy.max(c2.queueing_delay_list)
        print "Max queueing delay: %f" % max
        file_size = os.path.getsize(self.filename)
        print "File size: %i" % file_size
        throughput = file_size / time
        print "Throughput: %f" % throughput

        # Variables for debugging
        self.c3 = c3
        self.c4 = c4
        self.c2 = c2
        self.c1 = c1
        self.t1 = t1
        self.t2 = t2
        self.net = net
        linkab = n1.links[0]
        self.linkab = linkab
        l = linkab

        # Plotting
        plotter = Plotter()

        # Plot sequence charts
        #plotter.clear()
        #plotter.create_sequence_plot(c1.x, c1.y, c1.dropX, c1.dropY, c1.ackX, c1.ackY, chart_name='five/sequence1.png')
        #plotter.clear()
        #plotter.create_sequence_plot(c3.x, c3.y, c3.dropX, c3.dropY, c3.ackX, c3.ackY, chart_name='five/sequence2.png')

        # Plot receiver rate
        plotter.clear()
        plotter.rateTimePlot(c2.packets_received, Sim.scheduler.current_time(), chart_name='five/rateTime1.png')
        plotter.rateTimePlot(c4.packets_received, Sim.scheduler.current_time(), chart_name='five/rateTime2.png')
        plotter.rateTimePlot(c6.packets_received, Sim.scheduler.current_time(), chart_name='five/rateTime3.png')
        plotter.rateTimePlot(c8.packets_received, Sim.scheduler.current_time(), chart_name='five/rateTime4.png')
        plotter.rateTimePlot(c0.packets_received, Sim.scheduler.current_time(), chart_name='five/rateTime5.png')

        # Plot queue size
        plotter.clear()
        plotter.queueSizePlot(l.queue_log_x, l.queue_log_y, l.dropped_packets_x, l.dropped_packets_y, chart_name='five/queueSize.png')
Esempio n. 46
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        Sim.set_debug('AppHandler')
        Sim.set_debug('TCP')

        # setup network
        # net = Network('../networks/one-hop.txt')
        net = Network('../networks/four-nodes.txt')
        net.loss(self.loss)

        # setup routes
        n1 = net.get_node('n1')
        n2 = net.get_node('n2')
        n3 = net.get_node('n3')
        n4 = net.get_node('n4')

        n1.add_forwarding_entry(address=n2.get_address('n1'),link=n1.links[0])  # n1 -> n2
        n2.add_forwarding_entry(address=n1.get_address('n2'),link=n2.links[0])  # n1 <- n2

        n2.add_forwarding_entry(address=n3.get_address('n2'),link=n2.links[1])  # n2 -> n3
        n3.add_forwarding_entry(address=n2.get_address('n3'),link=n3.links[0])  # n2 <- n3

        n2.add_forwarding_entry(address=n4.get_address('n2'),link=n2.links[2])  # n2 -> n4
        n4.add_forwarding_entry(address=n2.get_address('n4'),link=n4.links[0])  # n2 <- n4

        n1.add_forwarding_entry(address=n4.get_address('n2'),link=n1.links[0])  # n1 -> n2 -> n4
        n3.add_forwarding_entry(address=n4.get_address('n2'),link=n3.links[0])  # n3 -> n2 -> n4
        n4.add_forwarding_entry(address=n1.get_address('n2'),link=n4.links[0])  # n4 -> n2 -> n1
        n4.add_forwarding_entry(address=n3.get_address('n2'),link=n4.links[0])  # n4 -> n2 -> n1

        # setup transport
        t1 = Transport(n1)
        t3 = Transport(n3)
        t4 = Transport(n4)

        # setup application
        tcp_flows = 2
        a1 = AppHandler(self.filename,1)
        a2 = AppHandler(self.filename,2)
        # a3 = AppHandler(self.filename, 3)
        # a4 = AppHandler(self.filename, 4)
        # a5 = AppHandler(self.filename, 5)

        # setup connection
        # c1a = TCP(t1, n1.get_address('n2'), 1, n2.get_address('n1'), 1, a1)
        # c2a = TCP(t2, n2.get_address('n1'), 1, n1.get_address('n2'), 1, a1)

        ### 4-node configuration
        c1a = TCP(t1, n1.get_address('n2'), 1, n4.get_address('n2'), 1, a1)
        c2a = TCP(t4, n4.get_address('n2'), 1, n1.get_address('n2'), 1, a1)

        c1b = TCP(t3, n3.get_address('n2'), 2, n4.get_address('n2'), 2, a2)
        c2b = TCP(t4, n4.get_address('n2'), 2, n3.get_address('n2'), 2, a2)

        # c1b = TCP(t1, n1.get_address('n2'), 2, n2.get_address('n1'), 2, a2)
        # c2b = TCP(t2, n2.get_address('n1'), 2, n1.get_address('n2'), 2, a2)

        # c1c = TCP(t1, n1.get_address('n2'), 3, n2.get_address('n1'), 3, a3)
        # c2c = TCP(t2, n2.get_address('n1'), 3, n1.get_address('n2'), 3, a3)
        #
        # c1d = TCP(t1, n1.get_address('n2'), 4, n2.get_address('n1'), 4, a4)
        # c2d = TCP(t2, n2.get_address('n1'), 4, n1.get_address('n2'), 4, a4)
        #
        # c1e = TCP(t1, n1.get_address('n2'), 5, n2.get_address('n1'), 5, a5)
        # c2e = TCP(t2, n2.get_address('n1'), 5, n1.get_address('n2'), 5, a5)

        # send a file
        with open(self.filename,'r') as f:
            while True:
                data = f.read(1000)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1a.send)
                Sim.scheduler.add(delay=0, event=data, handler=c1b.send)
                # Sim.scheduler.add(delay=0, event=data, handler=c1a.send)
                # Sim.scheduler.add(delay=0.1, event=data, handler=c1b.send)
                # Sim.scheduler.add(delay=0.2, event=data, handler=c1c.send)
                # Sim.scheduler.add(delay=0.3, event=data, handler=c1d.send)
                # Sim.scheduler.add(delay=0.4, event=data, handler=c1e.send)


        # run the simulation
        Sim.scheduler.run()
        return tcp_flows