Beispiel #1
0
 def _handle_PacketIn(self, event):
     """
     Handle arrival of new flow.
     Install routes in both directions using the shortest path metric.
     """
     try:
         if self.done:
             return
         self.net.refresh_network()
         packet = event.parsed
         if packet.find('tcp'):
             ip = packet.next
             tcp = ip.next
             if str(ip.srcip) != '0.0.0.0':
                 log.info("packetin {1}:{3} to {2}:{4} at {0}".format(
                         time.clock(), str(ip.srcip), str(ip.dstip),
                         tcp.srcport, tcp.dstport))
                 there = Flow(6, str(ip.srcip), str(ip.dstip), 
                         tcp.srcport, tcp.dstport)
                 back = Flow(6, str(ip.dstip), str(ip.srcip), 
                         tcp.dstport, tcp.srcport)
                 rules = shortest_path.objective(self.net.graph,
                         [(back,0), (there,0)])
                 self._install_rule_list(rules)
     except Exception as e:
         print str(e)
Beispiel #2
0
 def test_pentagon_graph_two_flows(self):
     G = pentagon_graph()
     f1 = Flow(6, '10.0.0.1', '10.0.0.2', 5001, 5002)
     f2 = Flow(6, '10.0.0.2', '10.0.0.1', 5003, 5004)
     expected = {
         f1: [Hop(1,2), Hop(2,2), Hop(5,1)], 
         f2: [Hop(5,2), Hop(2,1), Hop(1,1)]
     }
     assert objective(G, [(f1,1e6), (f2,1e6)]) == expected
Beispiel #3
0
 def _handle_PacketIn(self, event):
     self.net.refresh_network()
     packet = event.parsed
     if packet.find('tcp'):
         ip = packet.next
         tcp = ip.next
         if str(ip.srcip) != '0.0.0.0':
             log.info("legit packetin {1}:{3} to {2}:{4} at {0}".format(
                     time.clock(), str(ip.srcip), str(ip.dstip),
                     tcp.srcport, tcp.dstport))
             there = Flow(6, str(ip.srcip), str(ip.dstip), 
                     tcp.srcport, tcp.dstport)
             back = Flow(6, str(ip.dstip), str(ip.srcip), 
                     tcp.dstport, tcp.srcport)
             rules = shortest_path.objective(self.net.graph,
                     [(back,0), (there,0)])
             #log.info("got rules {0}".format(rules))
             self._install_rule_list(rules)
Beispiel #4
0
 def test_valid_graph_empty_flows(self):
     assert objective(pentagon_graph(), []) == {}
Beispiel #5
0
 def test_empty_graph_one_flow(self):
     f = Flow(nw_proto=6, nw_src='10.0.0.1', nw_dst='10.0.0.2',
              tp_src=5001, tp_dst=5002)
     assert objective(nx.Graph(), [(f,1e6)]) == {}
Beispiel #6
0
 def test_empty_graph_empty_flows(self):
     assert objective(nx.Graph(), []) == {}