def on_message_from_bottom(self, eventobj: Event): msg = eventobj.eventcontent hdr = msg.header payload = msg.payload if hdr.messageto == self.componentinstancenumber or hdr.messageto == MessageDestinationIdentifiers.NETWORKLAYERBROADCAST: # Add if broadcast.... self.send_up(Event(self, EventTypes.MFRB, payload)) print( f"I received a message to {hdr.messageto} and I am {self.componentinstancenumber}" ) else: destination = hdr.messageto nexthop = Topology().get_next_hop(self.componentinstancenumber, destination) if nexthop != float('inf'): newhdr = NetworkLayerMessageHeader( NetworkLayerMessageTypes.NETMSG, self.componentinstancenumber, destination, nexthop) newpayload = eventobj.eventcontent.payload msg = GenericMessage(newhdr, newpayload) self.send_down(Event(self, EventTypes.MFRT, msg)) print( f"{self.componentinstancenumber} will FORWARD a message to {destination} over {nexthop}" ) else: print( f"NO PATH {self.componentinstancenumber} will NOT FORWARD a message to {destination} over {nexthop}" )
def on_message_from_bottom(self, eventobj: Event): self.recvcnt = self.recvcnt + 1 self.sentcnt = eventobj.eventcontent.payload print(f"{self.recvcnt / self.sentcnt}") # print(nx.adjacency_matrix(Topology().G).todense()) # print("Progress {:2.2}".format(self.recvcnt/self.sentcnt), end="\r") Topology().shortest_path_to_all(self.componentinstancenumber)
def main(): topo = Topology() topo.construct_single_node(Node, 0) topo.start() while True: pass
def main(): # G = nx.Graph() # G.add_nodes_from([1, 2]) # G.add_edges_from([(1, 2)]) # nx.draw(G, with_labels=True, font_weight='bold') # plt.draw() G = nx.random_geometric_graph(19, 0.5) topo = Topology() topo.construct_from_graph(G, AdHocNode, P2PFIFOFairLossChannel) for ch in topo.channels: topo.channels[ch].setPacketLossProbability(random.random()) topo.channels[ch].setAverageNumberOfDuplicates(0) ComponentRegistry().print_components() topo.start() topo.plot() plt.show() # while (True): pass print(topo.nodecolors)
def on_message_from_top(self, eventobj: Event): # Encapsulate the SDU in network layer PDU applmsg = eventobj.eventcontent destination = applmsg.header.messageto nexthop = Topology().get_next_hop(self.componentinstancenumber, destination) if nexthop != float('inf'): print( f"{self.componentinstancenumber} will SEND a message to {destination} over {nexthop}" ) hdr = NetworkLayerMessageHeader(NetworkLayerMessageTypes.NETMSG, self.componentinstancenumber, destination, nexthop) payload = eventobj.eventcontent msg = GenericMessage(hdr, payload) self.send_down(Event(self, EventTypes.MFRT, msg)) else: print( f"NO PATH: {self.componentinstancenumber} will NOTSEND a message to {destination} over {nexthop}" )
def main(): topo = Topology() topo.construct_sender_receiver(Sender, Receiver, P2PFIFOFairLossChannel) nx.draw(topo.G, with_labels=True, font_weight='bold') plt.draw() topo.channels["0-1"].setPacketLossProbability(0.1) topo.channels["0-1"].setAverageNumberOfDuplicates(0) # topo.computeForwardingTable() topo.start() plt.show() while (True): pass #plt.show() handles this
def main(): # G = nx.Graph() # G.add_nodes_from([1, 2]) # G.add_edges_from([(1, 2)]) # nx.draw(G, with_labels=True, font_weight='bold') # plt.draw() G = nx.random_geometric_graph(19, 0.5) nx.draw(G, with_labels=True, font_weight='bold') plt.draw() topo = Topology() topo.construct_from_graph(G, AdHocNode, P2PFIFOPerfectChannel) topo.start() plt.show() # while (True): pass while (True): pass
def main(): # G: nx.Graph= nx.random_geometric_graph(5, 0.5, seed=3) # G: nx.Graph = nx.random_geometric_graph(14, 0.4, seed=1) # G: nx.Graph = nx.random_geometric_graph(15, 0.4, seed=3) # G: nx.Graph = nx.random_geometric_graph(20, 0.4, seed=3) # G: nx.Graph = nx.random_geometric_graph(10, 0.5, seed=3) # G: nx.Graph = nx.random_geometric_graph(30, 0.35, seed=3) # G: nx.Graph = nx.random_geometric_graph(6, 0.6, seed=3) G: nx.Graph = nx.random_geometric_graph(40, 0.25) for (u, v) in G.edges: G.get_edge_data(u, v)['weight'] = random.randint(1, len(G.nodes)) # u + v + u * v # TODO topo = Topology() topo.construct_from_graph(G, Node, NodeChannel) topo.start() drawGraph(G, isTopologyGraph=True) while True: userInput = input("\nUser Command:\n") processUserCommand(userInput, topo)
def update_topology(self): Topology().nodecolors[self.componentinstancenumber] = 'r' Topology().plot()