Beispiel #1
0
    def scenario2(self, first_table=0, second_table=1, tos1=4, tos2=8):
        """
        Add flow entries:
        First Table; Match IP Src A; set ToS = tos1, goto Second Table
        First Table; Match IP Src B; set ToS = tos2, goto Second Table
        Second Table; Match IP Src A; send to 1
        Second Table; Match IP Src B; send to 1

        Then send packets:
        IP A;  expect port 1 with ToS = tos1
        IP B;  expect port 1 with ToS = tos2

        @param self object instance
        @param first_table first table
        @param second_table second table
        @param tos1 ToS value to be set for first flow
        @param tos2 ToS value to be set for second flow
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up flow match in table A: set ToS
        t_act = action.action_set_nw_tos()
        t_act.nw_tos = tos1
        write_goto_action(self,
                          first_table,
                          second_table,
                          t_act,
                          ip_src='192.168.1.10')
        t_act.nw_tos = tos2
        write_goto_action(self,
                          first_table,
                          second_table,
                          t_act,
                          ip_src='192.168.1.30')

        # Set up flow matches in table B: routing
        write_output(self, second_table, of_ports[1], ip_src="192.168.1.10")
        write_output(self, second_table, of_ports[1], ip_src="192.168.1.30")

        # Generate packets and check them
        exp_pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10',
                                              tcp_sport=10,
                                              ip_tos=tos1)
        reply_check_dp(self,
                       ip_src='192.168.1.10',
                       tcp_sport=10,
                       exp_pkt=exp_pkt,
                       ing_port=of_ports[2],
                       egr_port=of_ports[1])

        exp_pkt = testutils.simple_tcp_packet(ip_src='192.168.1.30',
                                              tcp_sport=10,
                                              ip_tos=tos2)
        reply_check_dp(self,
                       ip_src='192.168.1.30',
                       tcp_sport=10,
                       exp_pkt=exp_pkt,
                       ing_port=of_ports[2],
                       egr_port=of_ports[1])
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
    def scenario2(self, first_table = 0, second_table = 1, tos1 = 4, tos2 = 8):
        """
        Add flow entries:
        First Table; Match IP Src A; set ToS = tos1, goto Second Table
        First Table; Match IP Src B; set ToS = tos2, goto Second Table
        Second Table; Match IP Src A; send to 1
        Second Table; Match IP Src B; send to 1

        Then send packets:
        IP A;  expect port 1 with ToS = tos1
        IP B;  expect port 1 with ToS = tos2

        @param self object instance
        @param first_table first table
        @param second_table second table
        @param tos1 ToS value to be set for first flow
        @param tos2 ToS value to be set for second flow
        """
        of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger)

        # Set up flow match in table A: set ToS
        t_act = action.action_set_nw_tos()
        t_act.nw_tos = tos1
        write_goto_action(self, first_table, second_table, t_act,
                          ip_src='192.168.1.10')
        t_act.nw_tos = tos2
        write_goto_action(self, first_table, second_table, t_act,
                          ip_src='192.168.1.30')

        # Set up flow matches in table B: routing
        write_output(self, second_table, of_ports[1], ip_src="192.168.1.10")
        write_output(self, second_table, of_ports[1], ip_src="192.168.1.30")

        # Generate packets and check them
        exp_pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10',
                                              tcp_sport=10, ip_tos=tos1)
        reply_check_dp(self, ip_src='192.168.1.10', tcp_sport=10,
                 exp_pkt=exp_pkt, ing_port=of_ports[2], egr_port=of_ports[1])

        exp_pkt = testutils.simple_tcp_packet(ip_src='192.168.1.30',
                                              tcp_sport=10, ip_tos=tos2)
        reply_check_dp(self, ip_src='192.168.1.30', tcp_sport=10,
                 exp_pkt=exp_pkt, ing_port=of_ports[2], egr_port=of_ports[1])