def action_generate(parent, field_to_mod, mod_field_vals): """ Create an action to modify the field indicated in field_to_mod @param parent Must implement, assertTrue @param field_to_mod The field to modify as a string name @param mod_field_vals Hash of values to use for modified values """ act = None if field_to_mod in ['pktlen']: return None if field_to_mod == 'dl_dst': act = action.action_set_dl_dst() act.dl_addr = parse.parse_mac(mod_field_vals['dl_dst']) elif field_to_mod == 'dl_src': act = action.action_set_dl_src() act.dl_addr = parse.parse_mac(mod_field_vals['dl_src']) elif field_to_mod == 'dl_vlan_enable': if not mod_field_vals['dl_vlan_enable']: # Strip VLAN tag act = action.action_strip_vlan() # Add VLAN tag is handled by dl_vlan field # Will return None in this case elif field_to_mod == 'dl_vlan': act = action.action_set_vlan_vid() act.vlan_vid = mod_field_vals['dl_vlan'] elif field_to_mod == 'dl_vlan_pcp': act = action.action_set_vlan_pcp() act.vlan_pcp = mod_field_vals['dl_vlan_pcp'] elif field_to_mod == 'ip_src': act = action.action_set_nw_src() act.nw_addr = parse.parse_ip(mod_field_vals['ip_src']) elif field_to_mod == 'ip_dst': act = action.action_set_nw_dst() act.nw_addr = parse.parse_ip(mod_field_vals['ip_dst']) elif field_to_mod == 'ip_tos': act = action.action_set_nw_tos() act.nw_tos = mod_field_vals['ip_tos'] elif field_to_mod == 'tcp_sport': act = action.action_set_tp_src() act.tp_port = mod_field_vals['tcp_sport'] elif field_to_mod == 'tcp_dport': act = action.action_set_tp_dst() act.tp_port = mod_field_vals['tcp_dport'] elif field_to_mod == 'udp_sport': act = action.action_set_tp_src() act.tp_port = mod_field_vals['udp_sport'] elif field_to_mod == 'udp_dport': act = action.action_set_tp_dst() act.tp_port = mod_field_vals['udp_dport'] else: parent.assertTrue(0, "Unknown field to modify: " + str(field_to_mod)) return act
def action_generate(parent, field_to_mod, mod_field_vals): """ Create an action to modify the field indicated in field_to_mod @param parent Must implement, assertTrue @param field_to_mod The field to modify as a string name @param mod_field_vals Hash of values to use for modified values """ act = None if field_to_mod in ['pktlen']: return None if field_to_mod == 'dl_dst': act = action.action_set_dl_dst() act.dl_addr = parse.parse_mac(mod_field_vals['dl_dst']) elif field_to_mod == 'dl_src': act = action.action_set_dl_src() act.dl_addr = parse.parse_mac(mod_field_vals['dl_src']) elif field_to_mod == 'dl_vlan_enable': if not mod_field_vals['dl_vlan_enable']: # Strip VLAN tag act = action.action_strip_vlan() # Add VLAN tag is handled by dl_vlan field # Will return None in this case elif field_to_mod == 'dl_vlan': act = action.action_set_vlan_vid() act.vlan_vid = mod_field_vals['dl_vlan'] elif field_to_mod == 'dl_vlan_pcp': act = action.action_set_vlan_pcp() act.vlan_pcp = mod_field_vals['dl_vlan_pcp'] elif field_to_mod == 'ip_src': act = action.action_set_nw_src() act.nw_addr = parse.parse_ip(mod_field_vals['ip_src']) elif field_to_mod == 'ip_dst': act = action.action_set_nw_dst() act.nw_addr = parse.parse_ip(mod_field_vals['ip_dst']) elif field_to_mod == 'ip_tos': act = action.action_set_nw_tos() act.nw_tos = mod_field_vals['ip_tos'] elif field_to_mod == 'tcp_sport': act = action.action_set_tp_src() act.tp_port = mod_field_vals['tcp_sport'] elif field_to_mod == 'tcp_dport': act = action.action_set_tp_dst() act.tp_port = mod_field_vals['tcp_dport'] else: parent.assertTrue(0, "Unknown field to modify: " + str(field_to_mod)) return act
def create_action(**kwargs): a = kwargs.get('action') if a == ofp.OFPAT_OUTPUT: act = action.action_output() act.port = kwargs.get('port', 1) return act if a == ofp.OFPAT_GROUP: act = action.action_group() act.group_id = kwargs.get('group_id', 0) return act if a == ofp.OFPAT_SET_TP_SRC: act = action.action_set_tp_src() act.tp_port = kwargs.get('tp_port', 0) return act if a == ofp.OFPAT_SET_DL_DST: act = action.action_set_dl_dst() dl_tmp = kwargs.get('dl_dst', 1) act.dl_addr = parse.parse_mac(dl_tmp) return act if a == ofp.OFPAT_SET_NW_DST: act = action.action_set_nw_dst() act.nw_addr = parse.parse_ip(kwargs.get('nw_dst', '192.168.3.1' )) return act
def create_action(**kwargs): a = kwargs.get('action') if a == ofp.OFPAT_OUTPUT: act = action.action_output() act.port = kwargs.get('port', 1) return act if a == ofp.OFPAT_GROUP: act = action.action_group() act.group_id = kwargs.get('group_id', 0) return act if a == ofp.OFPAT_SET_TP_SRC: act = action.action_set_tp_src() act.tp_port = kwargs.get('tp_port', 0) return act if a == ofp.OFPAT_SET_DL_DST: act = action.action_set_dl_dst() dl_tmp = kwargs.get('dl_dst', 1) act.dl_addr = parse.parse_mac(dl_tmp) return act if a == ofp.OFPAT_SET_NW_DST: act = action.action_set_nw_dst() act.nw_addr = parse.parse_ip(kwargs.get('nw_dst', '192.168.3.1')) return act