def push_vlan(vlan_vid): """Push a VLAN tag with optional selection of eth type.""" vid = vlan_vid vlan_eth_type = None if isinstance(vlan_vid, dict): vid = vlan_vid['vid'] if 'eth_type' in vlan_vid: vlan_eth_type = vlan_vid['eth_type'] if vlan_eth_type is None: return valve_of.push_vlan_act(vid) return valve_of.push_vlan_act(vid, eth_type=vlan_eth_type)
def rewrite_vlan(output_dict): vlan_actions = [] if 'pop_vlans' in output_dict: for _ in range(output_dict['pop_vlans']): vlan_actions.append(valve_of.pop_vlan()) # if vlan tag is specified, push it. if 'vlan_vid' in output_dict: vlan_actions.extend(valve_of.push_vlan_act(output_dict['vlan_vid'])) # or, if a list, push them all (all with type Q). elif 'vlan_vids' in output_dict: for vid in output_dict['vlan_vids']: vlan_actions.extend(valve_of.push_vlan_act(vid)) return vlan_actions
def _port_add_vlan_untagged(self, port, vlan, forwarding_table, mirror_act): push_vlan_act = mirror_act + valve_of.push_vlan_act(vlan.vid) push_vlan_inst = [ valve_of.apply_actions(push_vlan_act), valve_of.goto_table(forwarding_table) ] null_vlan = namedtuple('null_vlan', 'vid') null_vlan.vid = ofp.OFPVID_NONE return self._port_add_vlan_rules(port, vlan, null_vlan, push_vlan_inst)
def _port_add_vlan_untagged(self, port, vlan, forwarding_table, mirror_act): push_vlan_act = mirror_act + valve_of.push_vlan_act(vlan.vid) push_vlan_inst = [ valve_of.apply_actions(push_vlan_act), valve_of.goto_table(forwarding_table) ] null_vlan = namedtuple('null_vlan', 'vid') null_vlan.vid = ofp.OFPVID_NONE return self._port_add_vlan_rules(port, null_vlan, push_vlan_inst)
def build_acl_entry(rule_conf, acl_allow_inst, port_num=None, vlan_vid=None): acl_inst = [] match_dict = {} for attrib, attrib_value in rule_conf.items(): if attrib == 'in_port': continue if attrib == 'actions': allow = False allow_specified = False if 'allow' in attrib_value: allow_specified = True if attrib_value['allow'] == 1: allow = True if 'mirror' in attrib_value: port_no = attrib_value['mirror'] acl_inst.append( valve_of.apply_actions([valve_of.output_port(port_no)])) if not allow_specified: allow = True # if output selected, output packet now and exit pipeline. if 'output' in attrib_value: output_dict = attrib_value['output'] output_actions = [] # if destination rewriting selected, rewrite it. if 'dl_dst' in output_dict: output_actions.append( valve_of.set_eth_dst(output_dict['dl_dst'])) # if vlan tag is specified, push it. if 'vlan_vid' in output_dict: output_actions.extend( valve_of.push_vlan_act(output_dict['vlan_vid'])) # output to port port_no = output_dict['port'] output_actions.append(valve_of.output_port(port_no)) acl_inst.append(valve_of.apply_actions(output_actions)) continue if allow: acl_inst.append(acl_allow_inst) else: match_dict[attrib] = attrib_value if port_num is not None: match_dict['in_port'] = port_num if vlan_vid is not None: match_dict['vlan_vid'] = valve_of.vid_present(vlan_vid) acl_match = valve_of.match_from_dict(match_dict) return acl_match, acl_inst
def build_acl_entry(rule_conf, acl_allow_inst, port_num=None, vlan_vid=None): acl_inst = [] match_dict = {} for attrib, attrib_value in rule_conf.iteritems(): if attrib == 'in_port': continue if attrib == 'actions': allow = False allow_specified = False if 'allow' in attrib_value: allow_specified = True if attrib_value['allow'] == 1: allow = True if 'mirror' in attrib_value: port_no = attrib_value['mirror'] acl_inst.append( valve_of.apply_actions([valve_of.output_port(port_no)])) if not allow_specified: allow = True # if output selected, output packet now and exit pipeline. if 'output' in attrib_value: output_dict = attrib_value['output'] output_actions = [] # if destination rewriting selected, rewrite it. if 'dl_dst' in output_dict: output_actions.append( valve_of.set_eth_dst(output_dict['dl_dst'])) # if vlan tag is specified, push it. if 'vlan_vid' in output_dict: output_actions.extend( valve_of.push_vlan_act(output_dict['vlan_vid'])) # output to port port_no = output_dict['port'] output_actions.append(valve_of.output_port(port_no)) acl_inst.append(valve_of.apply_actions(output_actions)) continue if allow: acl_inst.append(acl_allow_inst) else: match_dict[attrib] = attrib_value if port_num is not None: match_dict['in_port'] = port_num if vlan_vid is not None: match_dict['vlan_vid'] = valve_of.vid_present(vlan_vid) acl_match = valve_of.match_from_dict(match_dict) return acl_match, acl_inst