Example #1
0
def run_this():
    gen = RandomState(2)
    env = simpy.Environment()

    pkt = Packet(1, size=1, id=1, src="n2", dst="n7")
    pkt2 = Packet(1, size=1, id=2, src="n2", dst="n5")
    pkt3 = Packet(1, size=1, id=3, src="n2", dst="n6")

    myNetwork = Network(env=env, gen=gen)
    myNetwork.add_nodes(["n1", "n2", "n3", "n4", "n5", "n6", "n7"])
    myNetwork.set_routing_algorithm(controller="random")

    links = [["n1", "n2", 1], ["n1", "n3", 1], ["n1", "n4", 1], ["n3", "n2", 1], ["n4", "n6", 1], ["n3", "n6", 2], ["n4", "n7", 1], ["n4", "n5", 1], ["n6", "n7", 1], ["n5", "n7", 10]]
    myNetwork.add_links(links)

    """myNetwork.add_packet(pkt)
    myNetwork.add_packet(pkt2)
    myNetwork.add_packet(pkt3)

    def step(env2):
        env2.run(until=env2.now+1)

    for i in range(30):
        #print("Queue size is " + str(len(env._queue)))
        step(env2=env)
        #print(pkt.current_node.id)
        if i == 3:
            myNetwork.set_routing_algorithm(controller="dijkstra")"""

    print(myNetwork.links)
Example #2
0
    def initial_state(self, packet=None):
        if packet is None:
            src = random.choice(list(self.graph.nodes.keys()))
            dst = random.choice(list(self.graph.nodes.keys()))
            while not dst == src:
                dst = random.choice(list(self.graph.nodes.keys()))

            pkt = Packet(time=self.graph.env.now,
                         size=1,
                         id=1,
                         src=src,
                         dst=dst)
            self.graph.add_packet(pkt=pkt)
        else:
            src = packet[0]
            dst = packet[1]

        pkt = Packet(time=self.graph.env.now, size=1, id=1, src=src, dst=dst)
        self.graph.add_packet(pkt=pkt)

        return (
            self.graph.nodes[src],
            self.graph.nodes[src],
            self.graph.nodes[dst],
        )
    def initial_state(self, broken_links, seed=None, packet=None):
        if seed is None:
            random.seed()
        else:
            random.seed(seed)

        if packet is None:
            src = random.choice(list(self.graph.nodes.keys()))
            dst = random.choice(list(self.graph.nodes.keys()))
            while dst == src:
                dst = random.choice(list(self.graph.nodes.keys()))

        else:
            src = packet[0]
            dst = packet[1]

        pkt = Packet(time=self.graph.env.now, size=1, id=1, src=src, dst=dst)
        self.graph.add_packet(pkt=pkt)

        state = [
            self.graph.nodes[src],
            self.graph.nodes[src],
            self.graph.nodes[dst],
        ]

        #print([state[0].id, state[1].id, state[2].id])
        return state
Example #4
0
def run():
    gen = RandomState(2)
    env = simpy.Environment()
    n1 = Node(env=env, id="n1", gen=gen)
    n2 = Node(env=env, id="n2", gen=gen)
    n3 = Node(env=env, id="n3", gen=gen)
    n4 = Node(env=env, id="n4", gen=gen)
    n5 = Node(env=env, id="n5", gen=gen)
    n6 = Node(env=env, id="n6", gen=gen)
    n1.set_routing_algo()
    n2.set_routing_algo()
    n3.set_routing_algo()
    n4.set_routing_algo()
    n5.set_routing_algo()
    n6.set_routing_algo()

    n1.add_connection(n2,
                      rate=500,
                      qlimit=64,
                      monitor_rate=1,
                      propagation_delay=5)
    n1.add_connection(n3,
                      rate=500,
                      qlimit=64,
                      monitor_rate=1,
                      propagation_delay=5)
    n2.add_connection(n4,
                      rate=500,
                      qlimit=64,
                      monitor_rate=1,
                      propagation_delay=5)
    n4.add_connection(n6,
                      rate=500,
                      qlimit=64,
                      monitor_rate=1,
                      propagation_delay=5)
    n3.add_connection(n5,
                      rate=500,
                      qlimit=64,
                      monitor_rate=1,
                      propagation_delay=5)
    n5.add_connection(n6,
                      rate=500,
                      qlimit=64,
                      monitor_rate=1,
                      propagation_delay=5)

    pkt = Packet(1, size=1, id=1, src=n1.id, dst=n6.id)
    n1.put(pkt)

    env.run(until=100)
Example #5
0
def run():
    gen = RandomState(2)
    env = simpy.Environment()

    pkt = Packet(1, size=1, id=1, src="n2", dst="n7")
    pkt2 = Packet(1, size=1, id=2, src="n2", dst="n5")
    pkt3 = Packet(1, size=1, id=3, src="n2", dst="n6")

    myNetwork = Network(env=env, gen=gen)
    myNetwork.add_nodes(["n1", "n2", "n3", "n4", "n5", "n6", "n7"])
    myNetwork.set_routing_algorithm(controller="random")

    links = [["n1", "n2", 1], ["n1", "n3", 1], ["n1", "n4",
                                                1], ["n3", "n2", 1],
             ["n4", "n6", 1], ["n3", "n6", 2], ["n4", "n7", 1],
             ["n4", "n5", 1], ["n6", "n7", 1], ["n5", "n7", 10]]
    myNetwork.add_links(links)

    myNetwork.add_packet(pkt)
    myNetwork.add_packet(pkt2)
    myNetwork.add_packet(pkt3)
    for i in range(50):
        env.run(until=env.now + 1)
        print("next")
Example #6
0
 def getStats(self):#nOfPktdropped, nOfPktGenerated
     return routing.Network_Components.getStats(), Packet.getStats()
    for i in range(3):
        packet = Packet(env.now, mean_pkt_size, i)
        switch_port.put(packet)
        print(switch_port.getQueueSize())

    print("something")
    switch_port.out = switch_port2
    switch_port.run()'''

    node1 = NetworkNode(env, "NW1", port_rate, adist1, sdist, samp_dist)
    node2 = NetworkNode(env, "NW2", port_rate, adist1, sdist, samp_dist)
    node3 = NetworkNode(env, "NW3", port_rate, adist1, sdist, samp_dist)
    node4 = NetworkNode(env, "NW4", port_rate, adist1, sdist, samp_dist)
    node5 = NetworkNode(env, "NW5", port_rate, adist1, sdist, samp_dist)
    node1.addPort(node2, True)
    node1.addPort(node3, True)
    node3.addPort(node4, True)
    node2.addPort(node4, True)
    node2.addPort(node5, True)
    node4.addPort(node5, True)
    print(node1.getPorts())
    print(node2.getPorts())
    print(node3.getPorts())
    print(node4.getPorts())
    packet = Packet(env.now, mean_pkt_size, 1, "NW1", "NW4")
    #packet2 = Packet(env.now, mean_pkt_size, 1, "NW2", "NW1")
    node1.put(packet)
    #node2.put(packet2)
    env.run(until=40000)
Example #8
0
 def getStats(self):#nOfPktdropped, nOfPktGenerated, mean end to end delay
     return routing.Network_Components.getStats(), Packet.getStats(), Packet.mean_end_to_end_delay()