예제 #1
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()
예제 #2
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        logging.getLogger('app').setLevel(logging.INFO)
        logging.getLogger('bene.link.queue').setLevel(logging.DEBUG)
        logging.getLogger('bene.tcp.sequence').setLevel(logging.DEBUG)
        logging.getLogger('bene.tcp.cwnd').setLevel(logging.DEBUG)
        if self.debug:
            logging.getLogger('bene.tcp').setLevel(logging.DEBUG)
            logging.getLogger('bene.tcp.sender').setLevel(logging.DEBUG)
            logging.getLogger('bene.tcp.receiver').setLevel(logging.DEBUG)

        # 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(n2.get_address('n1'), n1.links[0])
        n2.add_forwarding_entry(n1.get_address('n2'), n2.links[0])

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

        # setup application
        a = AppHandler(self.filename)

        window = 1000

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

        # 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()
예제 #3
0
def run1(filename):
    Sim.scheduler.reset()
    net = Network(filename)
    # setup routes
    a = net.get_node('a')
    b = net.get_node('b')
    c = net.get_node('c')
    a.add_forwarding_entry(c.get_address('b'), a.links[0])
    b.add_forwarding_entry(c.get_address('b'), b.links[1])
    # setup app
    PH = PacketHandler()
    net.nodes['c'].add_protocol(protocol="delay", handler=PH)
    amount_data = 8 * 1000000
    packet_size = 8 * 1000
    packet2send = amount_data / packet_size
    delay_amount = packet_size / a.links[0].bandwidth
    count = 0
    for i in range(int(packet2send)):
        count += 1
        p = Packet(destination_address=c.get_address('b'),
                   protocol='delay',
                   ident=i + 1,
                   length=1000)
        Sim.scheduler.add(delay=(i * delay_amount),
                          event=p,
                          handler=a.send_packet)
    Sim.scheduler.run()
예제 #4
0
def generic_3node(file_name, time_to_send_packet):
    # parameters
    Sim.scheduler.reset()

    # setup network
    net = Network(file_name)

    # 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=n2.get_address('n3'), link=n2.links[0])

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

    # send 10,000 packets
    for i in range(1, 10001):
        p = Packet(destination_address=n3.get_address('n2'), ident=i, protocol='delay', length=1000)
        calc_delay = (i - 1) * time_to_send_packet
        Sim.scheduler.add(delay=calc_delay, event=p, handler=n1.send_packet)




    # run the simulation
    Sim.scheduler.run()
예제 #5
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=BROADCAST_IP_ADDRESS,
               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=BROADCAST_IP_ADDRESS,
               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=BROADCAST_IP_ADDRESS,
               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()
예제 #6
0
def five_line():
    # parameters
    Sim.scheduler.reset()

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

    for n in net.nodes:
        net.nodes[n].add_protocol(protocol="dvrouting",
                                  handler=RoutingApp(net.nodes[n]))

    Sim.scheduler.add(delay=11, event=None, handler=end_simulation)

    # send packet from n2 to n5 and from n5 to n2
    p = Packet(destination_address=net.nodes['n5'].get_address('n4'),
               length=100)
    Sim.scheduler.add(10.1, event=p, handler=net.nodes['n2'].send_packet)
    p = Packet(destination_address=net.nodes['n2'].get_address('n3'),
               length=100)
    Sim.scheduler.add(10.2, event=p, handler=net.nodes['n5'].send_packet)

    # send packet from n2 to n4 and from n4 to n2
    p = Packet(destination_address=net.nodes['n4'].get_address('n3'),
               length=100)
    Sim.scheduler.add(10.3, event=p, handler=net.nodes['n2'].send_packet)
    p = Packet(destination_address=net.nodes['n2'].get_address('n3'),
               length=100)
    Sim.scheduler.add(10.4, event=p, handler=net.nodes['n4'].send_packet)

    # run the simulation
    Sim.scheduler.run()
예제 #7
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()
예제 #8
0
def five_ring():
    # parameters
    Sim.scheduler.reset()
    logging.getLogger('bene.node').setLevel(logging.INFO)

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

    for n in net.nodes:
        net.nodes[n].add_protocol(protocol="dvrouting",
                                  handler=RoutingApp(net.nodes[n]))

    Sim.scheduler.add(delay=20, event=None, handler=end_simulation)

    # send packet from n2 to n5 and from n5 to n2
    p = Packet(destination_address=net.nodes['n5'].get_address('n4'),
               length=100)
    Sim.scheduler.add(10.1, event=p, handler=net.nodes['n2'].send_packet)
    p = Packet(destination_address=net.nodes['n2'].get_address('n3'),
               length=100)
    Sim.scheduler.add(10.2, event=p, handler=net.nodes['n5'].send_packet)

    # send packet from n4 to n2 and from n4 to n2
    p = Packet(destination_address=net.nodes['n4'].get_address('n3'),
               length=100)
    Sim.scheduler.add(10.3, event=p, handler=net.nodes['n2'].send_packet)
    p = Packet(destination_address=net.nodes['n2'].get_address('n3'),
               length=100)
    Sim.scheduler.add(10.4, event=p, handler=net.nodes['n4'].send_packet)

    # at t = 11, bring down (both sides of) link between n5 and n1
    Sim.scheduler.add(11,
                      event=None,
                      handler=net.nodes['n5'].get_link('n1').down)
    Sim.scheduler.add(11,
                      event=None,
                      handler=net.nodes['n1'].get_link('n5').down)

    # send packet from n2 to n5 and from n5 to n2 - should fail
    p = Packet(destination_address=net.nodes['n5'].get_address('n4'),
               length=100)
    Sim.scheduler.add(12.1, event=p, handler=net.nodes['n2'].send_packet)
    p = Packet(destination_address=net.nodes['n2'].get_address('n3'),
               length=100)
    Sim.scheduler.add(12.2, event=p, handler=net.nodes['n5'].send_packet)

    # send packet from n2 to n5 and from n5 to n2 - should take different path
    p = Packet(destination_address=net.nodes['n5'].get_address('n4'),
               length=100)
    Sim.scheduler.add(15.1, event=p, handler=net.nodes['n2'].send_packet)
    p = Packet(destination_address=net.nodes['n2'].get_address('n3'),
               length=100)
    Sim.scheduler.add(15.2, event=p, handler=net.nodes['n5'].send_packet)

    # run the simulation
    Sim.scheduler.run()
예제 #9
0
파일: delay.py 프로젝트: brasm94/oldschool
def run1(filename, packetsize, p, file):
    Sim.scheduler.reset()
    net = Network(filename)
    a = net.get_node('a')
    b = net.get_node('b')
    c = net.get_node('c')
    a.add_forwarding_entry(c.get_address('b'), a.links[0])
    b.add_forwarding_entry(c.get_address('b'), b.links[1])
    d = DelayHandler(file)
    net.nodes['c'].add_protocol(protocol="delay", handler=d)

    bandwidth = a.links[0].bandwidth
    service_rate = bandwidth / (packetsize * 8)
    arrival_rate = p * service_rate

    destination = c.get_address('b')
    g = Generator(node=a,
                  destination=destination,
                  load=arrival_rate,
                  duration=600)
    Sim.scheduler.add(delay=0, event='generate', handler=g.handle)
    Sim.scheduler.run()
예제 #10
0
def generic_1packet(file_name):
    # parameters
    Sim.scheduler.reset()

    # setup network
    net = Network(file_name)

    # 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()
예제 #11
0
def generic_3node(p, csv_file_name):
    # parameters
    Sim.scheduler.reset()

    # setup network
    net = Network('../lab1b/networks/fast-fast.txt')

    # 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=n2.get_address('n3'), link=n2.links[0])

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

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

    # run the simulation
    Sim.scheduler.run()

    #write out results
    d.write_out()
예제 #12
0
def fifteen():
    # parameters
    Sim.scheduler.reset()

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

    for n in net.nodes:
        net.nodes[n].add_protocol(protocol="dvrouting",
                                  handler=RoutingApp(net.nodes[n]))

    Sim.scheduler.add(delay=40, event=None, handler=end_simulation)

    # send packet from n9 to n10 and from n10 to n9
    p = Packet(destination_address=net.nodes['n10'].get_address('n1'),
               length=100)
    Sim.scheduler.add(20.0, event=p, handler=net.nodes['n9'].send_packet)
    p = Packet(destination_address=net.nodes['n9'].get_address('n6'),
               length=100)
    Sim.scheduler.add(20.1, event=p, handler=net.nodes['n10'].send_packet)

    # send packet from n9 to n11 and from n11 to n9
    p = Packet(destination_address=net.nodes['n11'].get_address('n4'),
               length=100)
    Sim.scheduler.add(20.2, event=p, handler=net.nodes['n9'].send_packet)
    p = Packet(destination_address=net.nodes['n9'].get_address('n6'),
               length=100)
    Sim.scheduler.add(20.3, event=p, handler=net.nodes['n11'].send_packet)

    # send packet from n9 to n12 and from n12 to n9
    p = Packet(destination_address=net.nodes['n12'].get_address('n5'),
               length=100)
    Sim.scheduler.add(20.4, event=p, handler=net.nodes['n9'].send_packet)
    p = Packet(destination_address=net.nodes['n9'].get_address('n6'),
               length=100)
    Sim.scheduler.add(20.5, event=p, handler=net.nodes['n12'].send_packet)

    # send packet from n9 to n13 and from n13 to n9
    p = Packet(destination_address=net.nodes['n13'].get_address('n5'),
               length=100)
    Sim.scheduler.add(20.6, event=p, handler=net.nodes['n9'].send_packet)
    p = Packet(destination_address=net.nodes['n9'].get_address('n6'),
               length=100)
    Sim.scheduler.add(20.7, event=p, handler=net.nodes['n13'].send_packet)

    # send packet from n9 to n14 and from n14 to n9
    p = Packet(destination_address=net.nodes['n14'].get_address('n2'),
               length=100)
    Sim.scheduler.add(20.8, event=p, handler=net.nodes['n9'].send_packet)
    p = Packet(destination_address=net.nodes['n9'].get_address('n6'),
               length=100)
    Sim.scheduler.add(20.9, event=p, handler=net.nodes['n14'].send_packet)

    # send packet from n7 to n15 and from n15 to n7
    p = Packet(destination_address=net.nodes['n15'].get_address('n14'),
               length=100)
    Sim.scheduler.add(21.0, event=p, handler=net.nodes['n7'].send_packet)
    p = Packet(destination_address=net.nodes['n7'].get_address('n8'),
               length=100)
    Sim.scheduler.add(21.1, event=p, handler=net.nodes['n15'].send_packet)

    # at t = 22, bring down link between n2 and n8
    Sim.scheduler.add(22,
                      event=None,
                      handler=net.nodes['n8'].get_link('n2').down)
    Sim.scheduler.add(22,
                      event=None,
                      handler=net.nodes['n2'].get_link('n8').down)

    # send packet from n7 to n15 and from n15 to n7 - these should fail
    p = Packet(destination_address=net.nodes['n15'].get_address('n14'),
               length=100)
    Sim.scheduler.add(23.1, event=p, handler=net.nodes['n7'].send_packet)
    p = Packet(destination_address=net.nodes['n7'].get_address('n8'),
               length=100)
    Sim.scheduler.add(23.2, event=p, handler=net.nodes['n15'].send_packet)

    # send packet from n7 to n15 and from n15 to n7 - these should get there through new paths
    p = Packet(destination_address=net.nodes['n15'].get_address('n14'),
               length=100)
    Sim.scheduler.add(30.1, event=p, handler=net.nodes['n7'].send_packet)
    p = Packet(destination_address=net.nodes['n7'].get_address('n8'),
               length=100)
    Sim.scheduler.add(30.2, event=p, handler=net.nodes['n15'].send_packet)

    # run the simulation
    Sim.scheduler.run()
예제 #13
0
    def run(self, size):
        # parameters
        Sim.scheduler.reset()
        logging.getLogger('app').setLevel(logging.INFO)
        logging.getLogger('bene.link.queue').setLevel(logging.DEBUG)
        logging.getLogger('bene.tcp.sequence').setLevel(logging.DEBUG)
        logging.getLogger('bene.tcp.cwnd').setLevel(logging.DEBUG)
        if self.debug:
            logging.getLogger('bene.tcp').setLevel(logging.DEBUG)
            logging.getLogger('bene.tcp.sender').setLevel(logging.DEBUG)
            logging.getLogger('bene.tcp.receiver').setLevel(logging.DEBUG)

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

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

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

        # setup application
        a = AppHandler(self.filename)

        window = size

        # setup connection
        drop = []
        filen = ("data/queue-%i.csv" % size)
        fd = open(filen, "w")
        fd.write("Time_stamp,qDelay\n")
        c1 = TCP(t1,
                 n1.get_address('n2'),
                 1,
                 n2.get_address('n1'),
                 1,
                 a,
                 window=window,
                 drop=drop,
                 retran=self.retran)
        c2 = TCP(t2,
                 n2.get_address('n1'),
                 1,
                 n1.get_address('n2'),
                 1,
                 a,
                 window=window,
                 fd=fd)
        # send a file
        time_before = Sim.scheduler.current_time()
        count = 0
        with open(self.filename, 'rb') as f:
            while True:
                data = f.read(1000)
                count += len(data)
                # print("0",count)
                if not data:
                    break
                Sim.scheduler.add(delay=0, event=data, handler=c1.send)
            Sim.scheduler.run()
        time_after = Sim.scheduler.current_time()
        Sim.scheduler.reset()
        fd.close()
        return (time_after - time_before), count
예제 #14
0
    def run(self):
        # parameters
        Sim.scheduler.reset()
        logging.getLogger('app').setLevel(logging.INFO)
        logging.getLogger('bene.link.queue').setLevel(logging.DEBUG)
        logging.getLogger('bene.tcp.sequence').setLevel(logging.DEBUG)
        logging.getLogger('bene.tcp.cwnd').setLevel(logging.DEBUG)
        if self.debug:
            logging.getLogger('bene.tcp').setLevel(logging.DEBUG)
            logging.getLogger('bene.tcp.sender').setLevel(logging.DEBUG)
            logging.getLogger('bene.tcp.receiver').setLevel(logging.DEBUG)

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

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

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

        # setup application
        a = AppHandler(self.filename)

        window = self.wsize

        # setup connection
        drop = []
        c1 = TCP(t1,
                 n1.get_address('n2'),
                 1,
                 n2.get_address('n1'),
                 1,
                 a,
                 window=window,
                 drop=drop,
                 retran=self.retran)
        c2 = TCP(t2,
                 n2.get_address('n1'),
                 1,
                 n1.get_address('n2'),
                 1,
                 a,
                 window=window)
        # send a file
        strin = ""
        times = []
        for i in range(5):
            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)
                # break
            Sim.scheduler.run()
            times.append(Sim.scheduler.current_time())
            Sim.scheduler.reset()
        times.append(sum(times) / len(times))
        with open("report/w10000_TESTING.txt", 'w') as f2:
            f2.writelines(["%s\n" % item for item in times])