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

Commit 3803c77

Browse files
committed
merge with master
2 parents 3e35d75 + 376f63a commit 3803c77

File tree

6 files changed

+80
-42
lines changed

6 files changed

+80
-42
lines changed

of_client/pox_client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ def _handle_ConnectionUp(self, event):
476476
self.switches[event.dpid]['ports'][port.port_no] = port.hw_addr
477477
CONF_UP = not 'OFPPC_PORT_DOWN' in self.active_ofp_port_config(port.config)
478478
STAT_UP = not 'OFPPS_LINK_DOWN' in self.active_ofp_port_state(port.state)
479-
self.send_to_pyretic(['port','join',event.dpid, port.port_no, CONF_UP, STAT_UP])
479+
PORT_TYPE = self.active_ofp_port_features(port.curr)
480+
self.send_to_pyretic(['port','join',event.dpid, port.port_no, CONF_UP, STAT_UP, PORT_TYPE])
480481

481482
self.send_to_pyretic(['switch','join',event.dpid,'END'])
482483

@@ -577,7 +578,8 @@ def _handle_PortStatus(self, event):
577578
#self.runtime.network.port_joins.signal((event.dpid, event.port))
578579
CONF_UP = not 'OFPPC_PORT_DOWN' in self.active_ofp_port_config(port.config)
579580
STAT_UP = not 'OFPPS_LINK_DOWN' in self.active_ofp_port_state(port.state)
580-
self.send_to_pyretic(['port','join',event.dpid, port.port_no, CONF_UP, STAT_UP])
581+
PORT_TYPE = self.active_ofp_port_features(port.curr)
582+
self.send_to_pyretic(['port','join',event.dpid, port.port_no, CONF_UP, STAT_UP, PORT_TYPE])
581583
elif event.deleted:
582584
try:
583585
del self.switches[event.dpid]['ports'][event.port]
@@ -587,7 +589,8 @@ def _handle_PortStatus(self, event):
587589
elif event.modified:
588590
CONF_UP = not 'OFPPC_PORT_DOWN' in self.active_ofp_port_config(port.config)
589591
STAT_UP = not 'OFPPS_LINK_DOWN' in self.active_ofp_port_state(port.state)
590-
self.send_to_pyretic(['port','mod',event.dpid, event.port, CONF_UP, STAT_UP])
592+
PORT_TYPE = self.active_ofp_port_features(port.curr)
593+
self.send_to_pyretic(['port','join',event.dpid, port.port_no, CONF_UP, STAT_UP, PORT_TYPE])
591594
else:
592595
raise RuntimeException("Unknown port status event")
593596

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/language.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,10 +1544,11 @@ def set_network(self, network):
15441544
if changed:
15451545
self.log.debug("Printing updated MST:\n %s" % str(updated_mst))
15461546
self.policy = parallel([
1547-
match(switch=switch) >>
1548-
parallel(map(xfwd,attrs['ports'].keys()))
1549-
for switch,attrs in self.mst.nodes(data=True)])
1550-
1547+
match(switch=switch) >>
1548+
parallel(map(xfwd,ports))
1549+
for switch,ports
1550+
in self.mst.switch_with_port_ids_list()])
1551+
15511552
def __repr__(self):
15521553
try:
15531554
return "flood on:\n%s" % self.mst

pyretic/core/network.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,12 @@ class MAC(EthAddr):
191191
# Tools
192192
################################################################################
193193
class Port(object):
194-
def __init__(self, port_no, config=True, status=True,linked_to=None):
194+
def __init__(self,port_no,config=True,status=True,port_type=[],linked_to=None):
195195
self.port_no = port_no
196196
self.config = config
197197
self.status = status
198198
self.linked_to = linked_to
199+
self.port_type = port_type
199200

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

216217
def __repr__(self):
217-
return "%d:config_up=%s:status_up=%s:linked_to=%s" % (self.port_no,self.config,self.status,self.linked_to)
218+
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)
218219

219220

220221

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

247+
def switch_list(self):
248+
return self.nodes()
249+
250+
def switch_with_port_ids_list(self):
251+
return [(switch,attrs['ports'].keys())
252+
for switch,attrs in self.nodes(data=True)]
253+
254+
def switch_with_ports_list(self):
255+
return [(switch,attrs['ports'].values())
256+
for switch,attrs in self.nodes(data=True)]
257+
246258
def add_switch(self,switch):
247259
self.add_node(switch, name=switch, ports={})
248260

249-
def add_port(self,switch,port_no,config,status):
250-
self.node[switch]["ports"][port_no] = Port(port_no,config,status)
261+
def add_port(self,switch,port_no,config,status,port_type):
262+
self.node[switch]["ports"][port_no] = Port(port_no,config,status,port_type)
251263

252264
def add_link(self,loc1,loc2):
253265
self.add_edge(loc1.switch, loc2.switch, {loc1.switch: loc1.port_no, loc2.switch: loc2.port_no})
@@ -476,3 +488,12 @@ def copy(self):
476488
network = Network(topology)
477489
network.inject_packet = self.inject_packet
478490
return network
491+
492+
def switch_list(self):
493+
return self.topology.switch_list()
494+
495+
def switch_with_port_ids_list(self):
496+
return self.topology.switch_with_port_ids_list()
497+
498+
def switch_with_ports_list(self):
499+
return self.topology.switch_with_ports_list()

pyretic/core/runtime.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def handle_network_change(self):
223223
with self.network_lock:
224224

225225
# if the topology hasn't changed, ignore
226-
if self.network.topology == self.prev_network.topology:
226+
if self.network == self.prev_network:
227227
return
228228

229229
# otherwise copy the network object
@@ -880,9 +880,7 @@ def nuclear_install(new_rules, curr_classifier_no):
880880
:param classifier: the input classifer
881881
:type classifier: Classifier
882882
"""
883-
switch_attrs_tuples = self.network.topology.nodes(data=True)
884-
switch_to_attrs = { k : v for (k,v) in switch_attrs_tuples }
885-
switches = switch_to_attrs.keys()
883+
switches = self.network.switch_list()
886884

887885
for s in switches:
888886
self.send_barrier(s)
@@ -915,9 +913,7 @@ def add_version(rules, version):
915913
new_rules.append(r + (version,))
916914
return new_rules
917915

918-
switch_attrs_tuples = self.network.topology.nodes(data=True)
919-
switch_to_attrs = { k : v for (k,v) in switch_attrs_tuples }
920-
switches = switch_to_attrs.keys()
916+
switches = self.network.switch_list()
921917

922918
classifier = switchify(classifier,switches)
923919
classifier = concretize(classifier)
@@ -1016,9 +1012,7 @@ def install_diff_lists(diff_lists, classifier_version_no):
10161012
:type classifier_version_no: int
10171013
"""
10181014
(to_add, to_delete, to_modify, to_stay) = diff_lists
1019-
switch_attrs_tuples = self.network.topology.nodes(data=True)
1020-
switch_to_attrs = { k : v for (k,v) in switch_attrs_tuples }
1021-
switches = switch_to_attrs.keys()
1015+
switches = self.network.switch_list()
10221016

10231017
# If the controller just came up, clear out the switches.
10241018
if classifier_version_no == 1 or self.mode == 'proactive0':
@@ -1118,10 +1112,10 @@ def pull_switches_for_preds(self, concrete_preds, bucket):
11181112
if 'switch' in concrete_pred:
11191113
switch_id = concrete_pred['switch']
11201114
if ((not switch_id in switch_list) and
1121-
(switch_id in self.network.topology.nodes())):
1115+
(switch_id in self.network.switch_list())):
11221116
switch_list.append(switch_id)
11231117
else:
1124-
switch_list = self.network.topology.nodes()
1118+
switch_list = self.network.switch_list()
11251119
break
11261120
self.log.info('Pulling stats from switches '
11271121
+ str(switch_list) + ' for bucket ' +
@@ -1282,7 +1276,7 @@ def send_clear(self,switch):
12821276

12831277
def clear_all(self):
12841278
def f():
1285-
switches = self.network.topology.nodes()
1279+
switches = self.network.switch_list()
12861280
for s in switches:
12871281
self.send_barrier(s)
12881282
self.send_clear(s)
@@ -1309,11 +1303,11 @@ def handle_switch_join(self,switch_id):
13091303
def handle_switch_part(self,switch_id):
13101304
self.network.handle_switch_part(switch_id)
13111305

1312-
def handle_port_join(self,switch_id,port_id,conf_up,stat_up):
1313-
self.network.handle_port_join(switch_id,port_id,conf_up,stat_up)
1306+
def handle_port_join(self,switch_id,port_id,conf_up,stat_up,port_type):
1307+
self.network.handle_port_join(switch_id,port_id,conf_up,stat_up,port_type)
13141308

1315-
def handle_port_mod(self, switch, port_no, config, status):
1316-
self.network.handle_port_mod(switch, port_no, config, status)
1309+
def handle_port_mod(self,switch_id,port_id,conf_up,stat_up,port_type):
1310+
self.network.handle_port_mod(switch_id,port_id,conf_up,stat_up,port_type)
13171311

13181312
def handle_port_part(self, switch, port_no):
13191313
self.network.handle_port_part(switch, port_no)
@@ -1569,10 +1563,10 @@ def handle_switch_part(self, switch):
15691563
self.debug_log.debug(str(self.next_topo))
15701564
self.queue_update(self.get_update_no())
15711565

1572-
def handle_port_join(self, switch, port_no, config, status):
1566+
def handle_port_join(self, switch, port_no, config, status, port_type):
15731567
self.debug_log.debug("handle_port_joins %s:%s:%s:%s" % (switch, port_no, config, status))
15741568
this_update_no = self.get_update_no()
1575-
self.next_topo.add_port(switch,port_no,config,status)
1569+
self.next_topo.add_port(switch,port_no,config,status,port_type)
15761570
if config or status:
15771571
self.inject_discovery_packet(switch,port_no)
15781572
self.debug_log.debug(str(self.next_topo))
@@ -1588,12 +1582,13 @@ def handle_port_part(self, switch, port_no):
15881582
except KeyError:
15891583
pass # THE SWITCH HAS ALREADY BEEN REMOVED BY handle_switch_parts
15901584

1591-
def handle_port_mod(self, switch, port_no, config, status):
1585+
def handle_port_mod(self, switch, port_no, config, status, port_type):
15921586
self.debug_log.debug("handle_port_mods %s:%s:%s:%s" % (switch, port_no, config, status))
15931587
# GET PREV VALUES
15941588
try:
15951589
prev_config = self.next_topo.node[switch]["ports"][port_no].config
15961590
prev_status = self.next_topo.node[switch]["ports"][port_no].status
1591+
prev_port_type = self.next_topo.node[switch]["ports"][port_no].port_type
15971592
except KeyError:
15981593
self.log.warning("KeyError CASE!!!!!!!!")
15991594
self.port_down(switch, port_no)
@@ -1602,6 +1597,8 @@ def handle_port_mod(self, switch, port_no, config, status):
16021597
# UPDATE VALUES
16031598
self.next_topo.node[switch]["ports"][port_no].config = config
16041599
self.next_topo.node[switch]["ports"][port_no].status = status
1600+
self.next_topo.node[switch]["ports"][port_no].port_type = port_type
1601+
16051602

16061603
# DETERMINE IF/WHAT CHANGED
16071604
if (prev_config and not config):
@@ -1665,7 +1662,13 @@ def handle_link_update(self, s1, p_no1, s2, p_no2):
16651662
if p1.possibly_up() and p2.possibly_up():
16661663
self.next_topo.node[s1]["ports"][p_no1].linked_to = Location(s2,p_no2)
16671664
self.next_topo.node[s2]["ports"][p_no2].linked_to = Location(s1,p_no1)
1668-
self.next_topo.add_edge(s1, s2, {s1: p_no1, s2: p_no2})
1665+
pt1 = self.next_topo.node[s1]["ports"][p_no1].port_type
1666+
pt2 = self.next_topo.node[s2]["ports"][p_no2].port_type
1667+
if pt1 != pt2:
1668+
print "MISMATCH ",
1669+
print pt1
1670+
print pt2
1671+
self.next_topo.add_edge(s1, s2, {s1: p_no1, s2: p_no2, 'type' : pt1})
16691672

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

pyretic/examples/topology_printer.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,30 @@
1212
class topology_printer(DynamicPolicy):
1313

1414
def __init__(self):
15-
self.topology = None
15+
self.last_topology = None
1616
self.lock = Lock()
1717
super(topology_printer,self).__init__()
1818

1919
def set_network(self, network):
2020
with self.lock:
21-
if self.topology and (self.topology == network.topology):
22-
pass
21+
print '------New Topology Information----------'
22+
print '---Switch ID list'
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)])
31+
print '---Convert network topology object to string'
32+
print network.topology
33+
print '---Has changed: ',
34+
if self.last_topology:
35+
print self.last_topology != network.topology
2336
else:
24-
print self.topology
25-
print network.topology
26-
self.topology = network.topology
27-
print self.topology
28-
37+
print True
38+
self.last_topology = network.topology
2939

3040
def main ():
3141
return topology_printer()

0 commit comments

Comments
 (0)