def get_edge_from_admitted_traffic(self, pred, succ, admitted_traffic, edge_sw=None, exclude_inactive=False): edge = PortGraphEdge(pred, succ) # If the edge filter became empty, reflect that. if admitted_traffic.is_empty(): pass else: # Each traffic element has its own edge_data, because of how it might have # traveled through the switch and what modifications it may have accumulated for i, te in enumerate(admitted_traffic.traffic_elements): t = Traffic() t.add_traffic_elements([te]) traffic_paths = None if edge_sw: # Check to see the exact path of this traffic through the switch traffic_paths = edge_sw.port_graph.get_paths( pred, succ, t, [pred], [], []) if len(traffic_paths) == 0: print "Found traffic but no paths to back it up." #raise Exception("Found traffic but no paths to back it up.") else: # IF asked to exclude in-active... # As long as there a single active path and carries the te, then we are good, # otherwise, continue if exclude_inactive: active_path = False for p in traffic_paths: if p.get_max_active_rank() == 0: active_path = True break if not active_path: continue edge_data = NetworkPortGraphEdgeData(t, te.switch_modifications, traffic_paths) edge.add_edge_data(edge_data) return edge
class Flow: def __hash__(self): return hash(str(self.sw.node_id) + str(self.table_id) + str(id(self))) def __init__(self, sw, flow_table, flow_raw): self.sw = sw self.flow_table = flow_table self.flow_raw = flow_raw self.network_graph = sw.network_graph self.network_graph.total_flow_rules += 1 self.written_actions = [] self.applied_actions = [] self.go_to_table = None self.instruction_set = None if self.sw.network_graph.controller == "onos": self.table_id = self.flow_raw["tableId"] self.priority = int(self.flow_raw["priority"]) self.match = Match(match_raw=self.flow_raw["selector"]["criteria"], controller="onos", flow=self) self.instruction_set = InstructionSet(self.sw, self, self.flow_raw["treatment"]) elif self.sw.network_graph.controller == "ryu": self.table_id = self.flow_raw["table_id"] self.priority = int(self.flow_raw["priority"]) self.match = Match(match_raw=self.flow_raw["match"], controller="ryu", flow=self) self.instruction_set = InstructionSet(self.sw, self, self.flow_raw["instructions"]) elif self.sw.network_graph.controller == "grpc": self.priority = self.flow_raw.priority self.match = Match(match_raw=self.flow_raw.flow_rule_match, controller="grpc", flow=self) self.instruction_set = InstructionSet(self.sw, self, self.flow_raw.instructions) else: raise NotImplemented def init_port_graph_state(self): self.traffic_element = TrafficElement(init_match=self.match) self.traffic = Traffic() self.complement_traffic = Traffic() self.applied_traffic = None self.traffic.add_traffic_elements([self.traffic_element]) self.complement_traffic.add_traffic_elements(self.traffic_element.get_complement_traffic_elements()) def get_port_graph_edges(self, port_graph_edges): if self.instruction_set: # Prepare the raw material for edges self.instruction_set.populate_action_sets_for_port_graph_edges() for egress_node, edge_tuple in self.instruction_set.get_applied_port_graph_edges(): port_graph_edges[egress_node].append(edge_tuple) for egress_node, edge_tuple in self.instruction_set.get_written_port_graph_edges(): port_graph_edges[egress_node].append(edge_tuple) if self.instruction_set.goto_table: if self.instruction_set.goto_table < len(self.sw.flow_tables): goto_table_port_graph_node = self.sw.flow_tables[self.instruction_set.goto_table].port_graph_node applied_modifications = self.instruction_set.applied_action_set.get_modified_fields_dict(self.traffic_element) written_modifications = self.instruction_set.written_action_set.get_modified_fields_dict(self.traffic_element) port_graph_edges[goto_table_port_graph_node].append((self.applied_traffic, None, applied_modifications, written_modifications)) else: print "At switch:", self.sw.node_id, ", couldn't find flow table goto:", self.instruction_set.goto_table else: print "Assuming this means to drop."