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

Commit 6651643

Browse files
author
Joshua Reich
committed
improve interface to topology info
1 parent 6d3fd86 commit 6651643

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

pyretic/core/language.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,10 +1107,11 @@ def set_network(self, network):
11071107
changed = True
11081108
if changed:
11091109
self.policy = parallel([
1110-
match(switch=switch) >>
1111-
parallel(map(xfwd,attrs['ports'].keys()))
1112-
for switch,attrs in self.mst.nodes(data=True)])
1113-
1110+
match(switch=switch) >>
1111+
parallel(map(xfwd,ports))
1112+
for switch,ports
1113+
in self.mst.switches(with_ports=True)])
1114+
11141115
def __repr__(self):
11151116
try:
11161117
return "flood on:\n%s" % self.mst

pyretic/core/network.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ def exact_edge_match(e1,e2):
242242
return e1 == e2
243243
return nx.is_isomorphic(self,other,node_match=exact_node_match,edge_match=exact_edge_match)
244244

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()
251+
245252
def add_switch(self,switch):
246253
self.add_node(switch, name=switch, ports={})
247254

@@ -475,3 +482,6 @@ def copy(self):
475482
network = Network(topology)
476483
network.inject_packet = self.inject_packet
477484
return network
485+
486+
def switches(self,**kwargs):
487+
return self.topology.switches(**kwargs)

pyretic/core/runtime.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def handle_network_change(self):
172172
with self.network_lock:
173173

174174
# if the topology hasn't changed, ignore
175-
if self.network.topology == self.prev_network.topology:
175+
if self.network == self.prev_network:
176176
return
177177

178178
# otherwise copy the network object
@@ -656,9 +656,7 @@ def nuclear_install(classifier):
656656
:param classifier: the input classifer
657657
:type classifier: Classifier
658658
"""
659-
switch_attrs_tuples = self.network.topology.nodes(data=True)
660-
switch_to_attrs = { k : v for (k,v) in switch_attrs_tuples }
661-
switches = switch_to_attrs.keys()
659+
switches = self.network.switches()
662660
classifier = switchify(classifier,switches)
663661
classifier = concretize(classifier)
664662
classifier = check_OF_rules(classifier)
@@ -699,9 +697,7 @@ def install_diff_rules(classifier):
699697
"""
700698
with self.old_rules_lock:
701699
old_rules = self.old_rules
702-
switch_attrs_tuples = self.network.topology.nodes(data=True)
703-
switch_to_attrs = { k : v for (k,v) in switch_attrs_tuples }
704-
switches = switch_to_attrs.keys()
700+
switches = self.network.switches()
705701
classifier = switchify(classifier,switches)
706702
classifier = concretize(classifier)
707703
classifier = OF_inportize(classifier)
@@ -786,7 +782,7 @@ def pull_bucket_stats():
786782
if 'switch' in concrete_pred:
787783
switch_list.append(concrete_pred['switch'])
788784
else:
789-
switch_list = self.network.topology.nodes()
785+
switch_list = self.network.switches()
790786
break
791787
for s in switch_list:
792788
bucket.add_outstanding_switch_query(s)
@@ -889,7 +885,7 @@ def send_clear(self,switch):
889885

890886
def clear_all(self):
891887
def f():
892-
switches = self.network.topology.nodes()
888+
switches = self.network.switches()
893889
for s in switches:
894890
self.send_barrier(s)
895891
self.send_clear(s)

0 commit comments

Comments
 (0)