Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

Commit 7524720

Browse files
author
Joshua Reich
committed
adding port features to topology
1 parent 4238132 commit 7524720

File tree

5 files changed

+60
-32
lines changed

5 files changed

+60
-32
lines changed

of_client/pox_client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ def _handle_ConnectionUp(self, event):
417417
self.switches[event.dpid]['ports'][port.port_no] = port.hw_addr
418418
CONF_UP = not 'OFPPC_PORT_DOWN' in self.active_ofp_port_config(port.config)
419419
STAT_UP = not 'OFPPS_LINK_DOWN' in self.active_ofp_port_state(port.state)
420-
self.send_to_pyretic(['port','join',event.dpid, port.port_no, CONF_UP, STAT_UP])
420+
PORT_TYPE = self.active_ofp_port_features(port.curr)
421+
self.send_to_pyretic(['port','join',event.dpid, port.port_no, CONF_UP, STAT_UP, PORT_TYPE])
421422

422423
self.send_to_pyretic(['switch','join',event.dpid,'END'])
423424

@@ -518,7 +519,8 @@ def _handle_PortStatus(self, event):
518519
#self.runtime.network.port_joins.signal((event.dpid, event.port))
519520
CONF_UP = not 'OFPPC_PORT_DOWN' in self.active_ofp_port_config(port.config)
520521
STAT_UP = not 'OFPPS_LINK_DOWN' in self.active_ofp_port_state(port.state)
521-
self.send_to_pyretic(['port','join',event.dpid, port.port_no, CONF_UP, STAT_UP])
522+
PORT_TYPE = self.active_ofp_port_features(port.curr)
523+
self.send_to_pyretic(['port','join',event.dpid, port.port_no, CONF_UP, STAT_UP, PORT_TYPE])
522524
elif event.deleted:
523525
try:
524526
del self.switches[event.dpid]['ports'][event.port]
@@ -528,7 +530,8 @@ def _handle_PortStatus(self, event):
528530
elif event.modified:
529531
CONF_UP = not 'OFPPC_PORT_DOWN' in self.active_ofp_port_config(port.config)
530532
STAT_UP = not 'OFPPS_LINK_DOWN' in self.active_ofp_port_state(port.state)
531-
self.send_to_pyretic(['port','mod',event.dpid, event.port, CONF_UP, STAT_UP])
533+
PORT_TYPE = self.active_ofp_port_features(port.curr)
534+
self.send_to_pyretic(['port','join',event.dpid, port.port_no, CONF_UP, STAT_UP, PORT_TYPE])
532535
else:
533536
raise RuntimeException("Unknown port status event")
534537

pyretic/backend/backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ def found_terminator(self):
9494
print "ERROR: Bad switch event"
9595
elif msg[0] == 'port':
9696
if msg[1] == 'join':
97-
self.backend.runtime.handle_port_join(msg[2],msg[3],msg[4],msg[5])
97+
self.backend.runtime.handle_port_join(msg[2],msg[3],msg[4],msg[5],msg[6])
9898
elif msg[1] == 'mod':
99-
self.backend.runtime.handle_port_mod(msg[2],msg[3],msg[4],msg[5])
99+
self.backend.runtime.handle_port_mod(msg[2],msg[3],msg[4],msg[5],msg[6])
100100
elif msg[1] == 'part':
101101
self.backend.runtime.handle_port_part(msg[2],msg[3])
102102
else:

pyretic/core/network.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,12 @@ class MAC(EthAddr):
190190
# Tools
191191
################################################################################
192192
class Port(object):
193-
def __init__(self, port_no, config=True, status=True,linked_to=None):
193+
def __init__(self,port_no,config=True,status=True,port_type=[],linked_to=None):
194194
self.port_no = port_no
195195
self.config = config
196196
self.status = status
197197
self.linked_to = linked_to
198+
self.port_type = port_type
198199

199200
def definitely_down(self):
200201
return not self.config and not self.status
@@ -213,7 +214,7 @@ def __eq__(self,other):
213214
self.linked_to == other.linked_to)
214215

215216
def __repr__(self):
216-
return "%d:config_up=%s:status_up=%s:linked_to=%s" % (self.port_no,self.config,self.status,self.linked_to)
217+
return "%d:config_up=%s:status_up=%s:linked_to=%s:port_type=%s" % (self.port_no,self.config,self.status,self.linked_to,self.port_type)
217218

218219

219220

@@ -242,18 +243,22 @@ def exact_edge_match(e1,e2):
242243
return e1 == e2
243244
return nx.is_isomorphic(self,other,node_match=exact_node_match,edge_match=exact_edge_match)
244245

245-
def switches(self,with_ports=False):
246-
if with_ports:
247-
return [(switch,attrs['ports'].keys())
248-
for switch,attrs in self.nodes(data=True)]
249-
else:
250-
return self.nodes()
246+
def switch_list(self):
247+
return self.nodes()
248+
249+
def switch_with_port_ids_list(self):
250+
return [(switch,attrs['ports'].keys())
251+
for switch,attrs in self.nodes(data=True)]
252+
253+
def switch_with_ports_list(self):
254+
return [(switch,attrs['ports'].values())
255+
for switch,attrs in self.nodes(data=True)]
251256

252257
def add_switch(self,switch):
253258
self.add_node(switch, name=switch, ports={})
254259

255-
def add_port(self,switch,port_no,config,status):
256-
self.node[switch]["ports"][port_no] = Port(port_no,config,status)
260+
def add_port(self,switch,port_no,config,status,port_type):
261+
self.node[switch]["ports"][port_no] = Port(port_no,config,status,port_type)
257262

258263
def add_link(self,loc1,loc2):
259264
self.add_edge(loc1.switch, loc2.switch, {loc1.switch: loc1.port_no, loc2.switch: loc2.port_no})
@@ -483,5 +488,11 @@ def copy(self):
483488
network.inject_packet = self.inject_packet
484489
return network
485490

486-
def switches(self,**kwargs):
487-
return self.topology.switches(**kwargs)
491+
def switch_list(self):
492+
return self.topology.switch_list()
493+
494+
def switch_with_port_ids_list(self):
495+
return self.topology.switch_with_port_ids_list()
496+
497+
def switch_with_ports_list(self):
498+
return self.topology.switch_with_ports_list()

pyretic/core/runtime.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ def nuclear_install(classifier):
656656
:param classifier: the input classifer
657657
:type classifier: Classifier
658658
"""
659-
switches = self.network.switches()
659+
switches = self.network.switch_list()
660660
classifier = switchify(classifier,switches)
661661
classifier = concretize(classifier)
662662
classifier = check_OF_rules(classifier)
@@ -697,7 +697,7 @@ def install_diff_rules(classifier):
697697
"""
698698
with self.old_rules_lock:
699699
old_rules = self.old_rules
700-
switches = self.network.switches()
700+
switches = self.network.switch_list()
701701
classifier = switchify(classifier,switches)
702702
classifier = concretize(classifier)
703703
classifier = OF_inportize(classifier)
@@ -782,7 +782,7 @@ def pull_bucket_stats():
782782
if 'switch' in concrete_pred:
783783
switch_list.append(concrete_pred['switch'])
784784
else:
785-
switch_list = self.network.switches()
785+
switch_list = self.network.switch_list()
786786
break
787787
for s in switch_list:
788788
bucket.add_outstanding_switch_query(s)
@@ -885,7 +885,7 @@ def send_clear(self,switch):
885885

886886
def clear_all(self):
887887
def f():
888-
switches = self.network.switches()
888+
switches = self.network.switch_list()
889889
for s in switches:
890890
self.send_barrier(s)
891891
self.send_clear(s)
@@ -912,11 +912,11 @@ def handle_switch_join(self,switch_id):
912912
def handle_switch_part(self,switch_id):
913913
self.network.handle_switch_part(switch_id)
914914

915-
def handle_port_join(self,switch_id,port_id,conf_up,stat_up):
916-
self.network.handle_port_join(switch_id,port_id,conf_up,stat_up)
915+
def handle_port_join(self,switch_id,port_id,conf_up,stat_up,port_type):
916+
self.network.handle_port_join(switch_id,port_id,conf_up,stat_up,port_type)
917917

918-
def handle_port_mod(self, switch, port_no, config, status):
919-
self.network.handle_port_mod(switch, port_no, config, status)
918+
def handle_port_mod(self,switch_id,port_id,conf_up,stat_up,port_type):
919+
self.network.handle_port_mod(switch_id,port_id,conf_up,stat_up,port_type)
920920

921921
def handle_port_part(self, switch, port_no):
922922
self.network.handle_port_part(switch, port_no)
@@ -1074,10 +1074,10 @@ def handle_switch_part(self, switch):
10741074
self.debug_log.debug(str(self.next_topo))
10751075
self.queue_update(self.get_update_no())
10761076

1077-
def handle_port_join(self, switch, port_no, config, status):
1077+
def handle_port_join(self, switch, port_no, config, status, port_type):
10781078
self.debug_log.debug("handle_port_joins %s:%s:%s:%s" % (switch, port_no, config, status))
10791079
this_update_no = self.get_update_no()
1080-
self.next_topo.add_port(switch,port_no,config,status)
1080+
self.next_topo.add_port(switch,port_no,config,status,port_type)
10811081
if config or status:
10821082
self.inject_discovery_packet(switch,port_no)
10831083
self.debug_log.debug(str(self.next_topo))
@@ -1093,12 +1093,13 @@ def handle_port_part(self, switch, port_no):
10931093
except KeyError:
10941094
pass # THE SWITCH HAS ALREADY BEEN REMOVED BY handle_switch_parts
10951095

1096-
def handle_port_mod(self, switch, port_no, config, status):
1096+
def handle_port_mod(self, switch, port_no, config, status, port_type):
10971097
self.debug_log.debug("handle_port_mods %s:%s:%s:%s" % (switch, port_no, config, status))
10981098
# GET PREV VALUES
10991099
try:
11001100
prev_config = self.next_topo.node[switch]["ports"][port_no].config
11011101
prev_status = self.next_topo.node[switch]["ports"][port_no].status
1102+
prev_port_type = self.next_topo.node[switch]["ports"][port_no].port_type
11021103
except KeyError:
11031104
self.log.warning("KeyError CASE!!!!!!!!")
11041105
self.port_down(switch, port_no)
@@ -1107,6 +1108,8 @@ def handle_port_mod(self, switch, port_no, config, status):
11071108
# UPDATE VALUES
11081109
self.next_topo.node[switch]["ports"][port_no].config = config
11091110
self.next_topo.node[switch]["ports"][port_no].status = status
1111+
self.next_topo.node[switch]["ports"][port_no].port_type = port_type
1112+
11101113

11111114
# DETERMINE IF/WHAT CHANGED
11121115
if (prev_config and not config):
@@ -1170,7 +1173,13 @@ def handle_link_update(self, s1, p_no1, s2, p_no2):
11701173
if p1.possibly_up() and p2.possibly_up():
11711174
self.next_topo.node[s1]["ports"][p_no1].linked_to = Location(s2,p_no2)
11721175
self.next_topo.node[s2]["ports"][p_no2].linked_to = Location(s1,p_no1)
1173-
self.next_topo.add_edge(s1, s2, {s1: p_no1, s2: p_no2})
1176+
pt1 = self.next_topo.node[s1]["ports"][p_no1].port_type
1177+
pt2 = self.next_topo.node[s2]["ports"][p_no2].port_type
1178+
if pt1 != pt2:
1179+
print "MISMATCH ",
1180+
print pt1
1181+
print pt2
1182+
self.next_topo.add_edge(s1, s2, {s1: p_no1, s2: p_no2, 'type' : pt1})
11741183

11751184
# IF REACHED, WE'VE REMOVED AN EDGE, OR ADDED ONE, OR BOTH
11761185
self.debug_log.debug(self.next_topo)

pyretic/examples/topology_printer.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ def set_network(self, network):
2020
with self.lock:
2121
print '------New Topology Information----------'
2222
print '---Switch ID list'
23-
print network.switches()
24-
print '---Switch ID paired with port ID list'
25-
print network.switches(with_ports=True)
23+
print network.switch_list()
24+
print '---List of every switch ID paired with port ID'
25+
print network.switch_with_port_ids_list()
26+
print '---List of every switch ID paired with port type'
27+
print [(sid,[(port.port_no,port.port_type) for port in ports])
28+
for (sid,ports) in network.switch_with_ports_list()]
29+
print '---Edges'
30+
print '\n'.join(['s%s[%s]---s%s[%s]\ttype=%s' % (s1,data[s1],s2,data[s2],data['type']) for (s1,s2,data) in network.topology.edges(data=True)])
2631
print '---Convert network topology object to string'
2732
print network.topology
2833
print '---Has changed: ',

0 commit comments

Comments
 (0)