def _get_vlan_egress_flow_msgs( dp, table_no, ip, out_port=None, priority=0, direction=Direction.IN, ): """ Install egress flows Args: dp datapath table_no table to install flow out_port specify egress port, if None reg value is used priority flow priority direction packet direction. """ msgs = [] if out_port: output_reg = None else: output_reg = TUN_PORT_REG # Pass non vlan packet as it is. match = MagmaMatch( direction=direction, eth_type=ether_types.ETH_TYPE_IP, vlan_vid=(0x0000, 0x1000), ipv4_dst=ip, ) msgs.append( flows.get_add_output_flow_msg( dp, table_no, match, [], priority=priority, output_reg=output_reg, output_port=out_port, ), ) # remove vlan header for out_port. match = MagmaMatch( direction=direction, eth_type=ether_types.ETH_TYPE_IP, vlan_vid=(0x1000, 0x1000), ipv4_dst=ip, ) actions_vlan_pop = [dp.ofproto_parser.OFPActionPopVlan()] msgs.append( flows.get_add_output_flow_msg( dp, table_no, match, actions_vlan_pop, priority=priority, output_reg=output_reg, output_port=out_port, ), ) return msgs
def _get_proxy_flow_msgs(self, dp): """ Install egress flows Args: dp datapath table_no table to install flow out_port specify egress port, if None reg value is used priority flow priority direction packet direction. """ if self.config.he_proxy_port <= 0: return [] parser = dp.ofproto_parser match = MagmaMatch(proxy_tag=PROXY_TAG_TO_PROXY) actions = [ parser.NXActionRegLoad2(dst='eth_dst', value=self.config.he_proxy_eth_mac) ] return [ flows.get_add_output_flow_msg( dp, self._egress_tbl_num, match, priority=flows.UE_FLOW_PRIORITY, actions=actions, output_port=self.config.he_proxy_port) ]
def _get_default_egress_flow_msgs(self, dp, mac_addr: str = "", vlan: str = ""): """ Egress table is the last table that a packet touches in the pipeline. Output downlink traffic to gtp port, uplink trafic to LOCAL Args: mac_addr: In Non NAT mode, this is upstream internet GW mac address vlan: in multi APN this is vlan_id of the upstream network. Raises: MagmaOFError if any of the default flows fail to install. """ msgs = [] if self.config.setup_type == 'LTE': msgs.extend( _get_vlan_egress_flow_msgs(dp, self._egress_tbl_num, "0.0.0.0/0")) msgs.extend(self._get_proxy_flow_msgs(dp)) else: # Use regular match for Non LTE setup. downlink_match = MagmaMatch(direction=Direction.IN) msgs.append( flows.get_add_output_flow_msg( dp, self._egress_tbl_num, downlink_match, [], output_port=self.config.gtp_port)) if vlan.isdigit(): vid = 0x1000 | int(vlan) uplink_match = MagmaMatch(direction=Direction.OUT, vlan_vid=(vid)) else: uplink_match = MagmaMatch(direction=Direction.OUT) actions = [] # avoid resetting mac address on switch connect event. if mac_addr == "": mac_addr = self._current_upstream_mac_map.get(vlan, "") if mac_addr == "" and self.config.enable_nat is False and \ self.config.setup_type == 'LTE': mac_addr = self.config.uplink_gw_mac if mac_addr != "": parser = dp.ofproto_parser actions.append( parser.NXActionRegLoad2(dst='eth_dst', value=mac_addr)) if self._current_upstream_mac_map.get(vlan, "") != mac_addr: self.logger.info("Using GW: mac: %s match %s actions: %s", mac_addr, str(uplink_match.ryu_match), str(actions)) self._current_upstream_mac_map[vlan] = mac_addr if vlan.isdigit(): priority = flows.UE_FLOW_PRIORITY elif mac_addr != "": priority = flows.DEFAULT_PRIORITY else: priority = flows.MINIMUM_PRIORITY msgs.append( flows.get_add_output_flow_msg(dp, self._egress_tbl_num, uplink_match, priority=priority, actions=actions, output_port=self.config.uplink_port)) return msgs
def _get_vlan_egress_flow_msgs( dp, table_no, eth_type, ip, out_port=None, priority=0, direction=Direction.IN, dst_mac=None, ): """ Install egress flows Args: dp datapath table_no table to install flow out_port specify egress port, if None reg value is used priority flow priority direction packet direction. """ msgs = [] if out_port: output_reg = None else: output_reg = TUN_PORT_REG # Pass non vlan packet as it is. # TODO: add support to match IPv6 address if ip: match = MagmaMatch( direction=direction, eth_type=eth_type, vlan_vid=(0x0000, 0x1000), ipv4_dst=ip, ) else: match = MagmaMatch( direction=direction, eth_type=eth_type, vlan_vid=(0x0000, 0x1000), ) actions = [] if dst_mac: actions.append( dp.ofproto_parser.NXActionRegLoad2(dst='eth_dst', value=dst_mac)) msgs.append( flows.get_add_output_flow_msg( dp, table_no, match, actions, priority=priority, output_reg=output_reg, output_port=out_port, ), ) # remove vlan header for out_port. if ip: match = MagmaMatch( direction=direction, eth_type=eth_type, vlan_vid=(0x1000, 0x1000), ipv4_dst=ip, ) else: match = MagmaMatch( direction=direction, eth_type=eth_type, vlan_vid=(0x1000, 0x1000), ) actions = [dp.ofproto_parser.OFPActionPopVlan()] if dst_mac: actions.append( dp.ofproto_parser.NXActionRegLoad2(dst='eth_dst', value=dst_mac)) msgs.append( flows.get_add_output_flow_msg( dp, table_no, match, actions, priority=priority, output_reg=output_reg, output_port=out_port, ), ) return msgs