def mpls1_flow(dpath, mod, ofctl, use_metadata=True): """ MPLS1 flow table. """ _LOG.debug("MPLS1 FLow: %d %s %s", dpath.id, mod, ofctl) cmd = fibcapi.flow_mod_cmd(mod.cmd, dpath.ofproto) entry = mod.mpls1 def _match(): match = ofmatch.Match() match.eth_type(fibcapi.ETHTYPE_MPLS) match.mpls_bos(entry.match.bos) match.mpls_label(entry.match.label) return match def _actions(): if not offlow.is_action_needed(dpath, cmd): return [] actions = [ ofaction.goto_table(entry.goto_table), ofaction.dec_mpls_ttl(), ] if entry.goto_table == pb.FlowMod.MPLS_TYPE: actions.append( ofaction.set_mpls_type(fibcapi.MPLSTYPE_PHP, use_metadata)) for action in entry.actions: if action.name == pb.MPLSFlow.Action.POP_LABEL: actions.append(ofaction.pop_mpls(action.value)) elif action.name == pb.MPLSFlow.Action.SET_VRF: actions.append(ofaction.set_vrf(action.value, use_metadata)) return actions def _writes(): if not offlow.is_action_needed(dpath, cmd): return [] if entry.g_type == pb.GroupMod.MPLS_INTERFACE: return [ ofaction.group(fibcapi.mpls_interface_group_id(entry.g_id)) ] if entry.g_type == pb.GroupMod.MPLS_SWAP: return [ofaction.group(fibcapi.mpls_label_group_id(5, entry.g_id))] if entry.g_type == pb.GroupMod.MPLS_FF: return [ofaction.group(fibcapi.mpls_ff_group_id(entry.g_id))] if entry.g_type == pb.GroupMod.MPLS_ECMP: return [ofaction.group(fibcapi.mpls_ecmp_group_id(entry.g_id))] return [] flow = offlow.flow_mod(match=_match, actions=_actions, writes=_writes, table_id=pb.FlowMod.MPLS1, priority=1) ofctl.mod_flow_entry(dpath, flow, cmd)
def termination_mac_flow(dpath, mod, ofctl): """ Termination MAC flow table. """ _LOG.debug("TERM MAC FLow: %d %s %s", dpath.id, mod, ofctl) cmd = fibcapi.flow_mod_cmd(mod.cmd, dpath.ofproto) entry = mod.term_mac match = ofmatch.Match().eth_type(entry.match.eth_type).eth_dst( entry.match.eth_dst) def _actions(): if not offlow.is_action_needed(dpath, cmd): return [] return [ofaction.goto_table(entry.goto_table)] flow = offlow.flow_mod(match=match, actions=_actions, writes=[], table_id=pb.FlowMod.TERM_MAC, priority=fibcapi.PRIORITY_LOW) ofctl.mod_flow_entry(dpath, flow, cmd)
def policy_acl_flow(dpath, mod, ofctl, use_metadata=True): """ Policy ACL flow table. """ _LOG.debug("ACL FLow: %d %s", dpath.id, mod) entry = mod.acl if entry.match.in_port: # openflow mode: # send no flows for a port. # flows for a port are send by setup_flow(). return cmd = fibcapi.flow_mod_cmd(mod.cmd, dpath.ofproto) match = ofmatch.Match().ip_dst(entry.match.ip_dst).vrf( entry.match.vrf, use_metadata) def _actions(): if not offlow.is_action_needed(dpath, cmd): return [] return [ofaction.output(dpath.ofproto.OFPP_CONTROLLER)] flow = offlow.flow_mod(match=match, actions=_actions, writes=[], table_id=pb.FlowMod.POLICY_ACL, priority=fibcapi.PRIORITY_HIGH) ofctl.mod_flow_entry(dpath, flow, cmd)
def unicast_routing_flow(dpath, mod, ofctl, use_metadata=True): """ Create flow_mod for Unicast Routing flow table. """ _LOG.debug("Unicast Routing FLow: %d %s", dpath.id, mod) cmd = fibcapi.flow_mod_cmd(mod.cmd, dpath.ofproto) entry = mod.unicast match = ofmatch.Match().ip_dst(entry.match.ip_dst).vrf( entry.match.vrf, use_metadata) def _actions(): if not offlow.is_action_needed(dpath, cmd): return [] return [ofaction.goto_table(pb.FlowMod.POLICY_ACL)] def _writes(): if not offlow.is_action_needed(dpath, cmd): return [] writes = [ofaction.dec_nw_ttl()] if entry.g_type == pb.GroupMod.L3_UNICAST: writes.append( ofaction.group(fibcapi.l3_unicast_group_id(entry.g_id))) elif entry.g_type == pb.GroupMod.L3_ECMP: writes.append(ofaction.group(fibcapi.l3_ecmp_group_id(entry.g_id))) elif entry.g_type == pb.GroupMod.MPLS_L3_VPN: writes.append( ofaction.group(fibcapi.mpls_label_group_id(2, entry.g_id))) else: pass return writes def _priority_base(): if entry.g_type == pb.GroupMod.MPLS_L3_VPN: return fibcapi.PRIORITY_BASE_VPN return fibcapi.PRIORITY_BASE_UC priority = offlow.priority_for_ipaddr(entry.match.ip_dst, _priority_base()) flow = offlow.flow_mod(match=match, actions=_actions, writes=_writes, table_id=pb.FlowMod.UNICAST_ROUTING, priority=priority) ofctl.mod_flow_entry(dpath, flow, cmd)
def vlan_flow(dpath, mod, ofctl, use_metadata=True): """ VLAN flow table. """ _LOG.debug("VLAN FLow: %d %s", dpath.id, mod) cmd = fibcapi.flow_mod_cmd(mod.cmd, dpath.ofproto) entry = mod.vlan def _match(): match = ofmatch.Match() match.in_port(entry.match.in_port) match.vlan_vid(entry.match.vid, entry.match.vid_mask) return match def _actions(): if not offlow.is_action_needed(dpath, cmd): return [] actions = [] for action in entry.actions: if action.name == pb.VLANFlow.Action.PUSH_VLAN: vlan_vid = action.value | fibcapi.OFPVID_PRESENT actions.append(ofaction.push_vlan(fibcapi.ETHTYPE_VLAN_Q)) actions.append(ofaction.set_field("vlan_vid", vlan_vid)) elif action.name == pb.VLANFlow.Action.SET_VRF: actions.append(ofaction.set_vrf(action.value, use_metadata)) actions.append(ofaction.goto_table(entry.goto_table)) return actions flow = offlow.flow_mod(match=_match, actions=_actions, writes=[], table_id=pb.FlowMod.VLAN, priority=3) ofctl.mod_flow_entry(dpath, flow, cmd)