Пример #1
0
def acl_ut_entry_incr_rollback(table_id, entry_id):
    global total, passed
    total.append(sys._getframe().f_code.co_name)

    # Transaction with multiple updates
    upd = []
    # Modify inports
    e = nas_acl.EntryCPSObj(
        table_id=table_id,
        entry_id=entry_id,
        filter_type='IN_PORTS')
    e.set_filter_val([a_utl.get_if_name(4), a_utl.get_if_name(8)])
    upd.append(('set', e.data()))

    # Delete Counter action
    e = nas_acl.EntryCPSObj(
        table_id=table_id,
        entry_id=entry_id,
        action_type='SET_COUNTER')
    upd.append(('delete', e.data()))

    # Modify mirror action
    e = nas_acl.EntryCPSObj(
        table_id=table_id,
        entry_id=entry_id,
        action_type='MIRROR_INGRESS')
    e.set_action_val(
        [{'index': mirror_id_2,
          'data': mir_opq_2},
         {'index': mirror_id_1,
          'data': mir_opq_1}])
    upd.append(('set', e.data()))

    # Delete Meter
    e = nas_acl.EntryCPSObj(
        table_id=table_id,
        entry_id=entry_id,
        action_type='SET_POLICER')
    upd.append(('delete', e.data()))

    # Introduce error - Add IN_PORT filter even though IN_PORTS is already
    # present
    e = nas_acl.EntryCPSObj(
        table_id=table_id,
        entry_id=entry_id,
        filter_type='IN_PORT')
    e.set_filter_val(a_utl.get_if_name(1))
    upd.append(('create', e.data()))

    print upd
    r = cps_utils.CPSTransaction(upd).commit()
    if r == False:
        print "Error adding inport filter (Expected) - Should have rolled back previous updates in transaction"
        raw_input("Check entry is Rolled back and Press Enter to continue...")
        passed.append(sys._getframe().f_code.co_name)
    else:
        print "#### Failed - Adding Inport filter did not give error"
Пример #2
0
def acl_ut_entry_incr_rollback(table_id, entry_id):
    global total, passed
    total.append(sys._getframe().f_code.co_name)

    # Transaction with multiple updates
    upd = []
    # Modify inports
    e = nas_acl.EntryCPSObj(
        table_id=table_id,
        entry_id=entry_id,
        filter_type='IN_PORTS')
    e.set_filter_val([a_utl.get_if_name(4), a_utl.get_if_name(8)])
    upd.append(('set', e.data()))

    # Delete Counter action
    e = nas_acl.EntryCPSObj(
        table_id=table_id,
        entry_id=entry_id,
        action_type='SET_COUNTER')
    upd.append(('delete', e.data()))

    # Modify mirror action
    e = nas_acl.EntryCPSObj(
        table_id=table_id,
        entry_id=entry_id,
        action_type='MIRROR_INGRESS')
    e.set_action_val(
        [{'index': mirror_id_2,
          'data': mir_opq_2},
         {'index': mirror_id_1,
          'data': mir_opq_1}])
    upd.append(('set', e.data()))

    # Delete Meter
    e = nas_acl.EntryCPSObj(
        table_id=table_id,
        entry_id=entry_id,
        action_type='SET_POLICER')
    upd.append(('delete', e.data()))

    # Introduce error - Add IN_PORT filter even though IN_PORTS is already
    # present
    e = nas_acl.EntryCPSObj(
        table_id=table_id,
        entry_id=entry_id,
        filter_type='IN_PORT')
    e.set_filter_val(a_utl.get_if_name(1))
    upd.append(('create', e.data()))

    print upd
    r = cps_utils.CPSTransaction(upd).commit()
    if r == False:
        print "Error adding inport filter (Expected) - Should have rolled back previous updates in transaction"
        raw_input("Check entry is Rolled back and Press Enter to continue...")
        passed.append(sys._getframe().f_code.co_name)
    else:
        print "#### Failed - Adding Inport filter did not give error"
Пример #3
0
def acl_ut_entry_create(table_id, prio=None, counter_id=None):
    global total, passed
    total.append(sys._getframe().f_code.co_name)
    filters = {
        'SRC_IP': {'addr': '23.0.0.1', 'mask': '255.0.0.255'},
        'SRC_MAC': '01:80:c2:00:00:05',
        'IPV6_FLOW_LABEL': 34456,
        'TCP_FLAGS': {'data': '0x17', 'mask': '0x3f'},
        'ECN': {'data': '0x2', 'mask': '0x2'},
        'IP_TYPE': 'IP',
        'IN_PORTS': [a_utl.get_if_name(2), a_utl.get_if_name(3)],
    }

    actions = {
        'SET_SRC_MAC': '01:00:79:08:78:BC',
        'PACKET_ACTION': 'COPY_TO_CPU',
        'REDIRECT_PORT': a_utl.get_if_name(4),
    }
    if (counter_id):
        actions['SET_COUNTER'] = counter_id

    global meter_id
    try:
        meter_id, meter_opaque = a_utl.qos_meter_create(
            m_type='BYTE', cir=300000,
            cbs=800000, pbs=900000)
    except:
        print "Meter install Failed"
        return

    actions['SET_POLICER'] = {'index': meter_id, 'data': meter_opaque}

    global mirror_id_1, mir_opq_1
    global mirror_id_2, mir_opq_2
    try:
        mirror_id_1, mir_opq_1 = a_utl.mirror_create(13)
        mirror_id_2, mir_opq_2 = a_utl.mirror_create(16)
    except:
        print "Mirror Create Failed"
        return

    actions['MIRROR_INGRESS'] = [{'index': mirror_id_1, 'data': mir_opq_1},
                                 {'index': mirror_id_2, 'data': mir_opq_2}]

    try:
        entry_id = nas_acl.create_entry(table_id=table_id, prio=prio,
                                        filter_map=filters, action_map=actions)
    except RuntimeError:
        print (sys._getframe().f_code.co_name + " - Error creating Entry")
        return None

    print (sys._getframe().f_code.co_name +
           " - Created Entry " + str(entry_id))
    raw_input("Check entry is created and Press Enter to continue...")
    passed.append(sys._getframe().f_code.co_name)
    return entry_id
Пример #4
0
def acl_ut_entry_create(table_id, prio=None, counter_id=None):
    global total, passed
    total.append(sys._getframe().f_code.co_name)
    filters = {
        'SRC_IP': {'addr': '23.0.0.1', 'mask': '255.0.0.255'},
        'SRC_MAC': '01:80:c2:00:00:05',
        'IPV6_FLOW_LABEL': 34456,
        'TCP_FLAGS': {'data': '0x17', 'mask': '0x3f'},
        'ECN': {'data': '0x2', 'mask': '0x2'},
        'IP_TYPE': 'IP',
        'IN_PORTS': [a_utl.get_if_name(2), a_utl.get_if_name(3)],
    }

    actions = {
        'SET_SRC_MAC': '01:00:79:08:78:BC',
        'PACKET_ACTION': 'COPY_TO_CPU',
        'REDIRECT_PORT': a_utl.get_if_name(4),
    }
    if (counter_id):
        actions['SET_COUNTER'] = counter_id

    global meter_id
    try:
        meter_id, meter_opaque = a_utl.qos_meter_create(
            m_type='BYTE', cir=300000,
            cbs=800000, pbs=900000)
    except:
        print "Meter install Failed"
        return

    actions['SET_POLICER'] = {'index': meter_id, 'data': meter_opaque}

    global mirror_id_1, mir_opq_1
    global mirror_id_2, mir_opq_2
    try:
        mirror_id_1, mir_opq_1 = a_utl.mirror_create(13)
        mirror_id_2, mir_opq_2 = a_utl.mirror_create(16)
    except:
        print "Mirror Create Failed"
        return

    actions['MIRROR_INGRESS'] = [{'index': mirror_id_1, 'data': mir_opq_1},
                                 {'index': mirror_id_2, 'data': mir_opq_2}]

    try:
        entry_id = nas_acl.create_entry(table_id=table_id, prio=prio,
                                        filter_map=filters, action_map=actions)
    except RuntimeError:
        print (sys._getframe().f_code.co_name + " - Error creating Entry")
        return None

    print (sys._getframe().f_code.co_name +
           " - Created Entry " + str(entry_id))
    raw_input("Check entry is created and Press Enter to continue...")
    passed.append(sys._getframe().f_code.co_name)
    return entry_id
Пример #5
0
def acl_ut_entry_modify1(table_id, entry_id):
    global total, passed
    total.append(sys._getframe().f_code.co_name)
    e = nas_acl.EntryCPSObj(table_id=table_id, entry_id=entry_id)
    filters = {
        'DST_IP': '56.0.0.1',
        'IPV6_FLOW_LABEL': {'data': '34456', 'mask': '0xff'},
        'TCP_FLAGS': {'data': '0x17', 'mask': '0x3f'},
        'ECN': {'data': '0x2', 'mask': '0x2'},
        'IP_TYPE': 'IP',
        'IN_PORTS': [a_utl.get_if_name(3)],
    }
    actions = {
        'SET_DST_MAC': '01:00:79:08:78:BC',
        'MIRROR_INGRESS': {'index': mirror_id_1, 'data': mir_opq_1},
    }

    try:
        nas_acl.replace_entry_filter_list(
            table_id=table_id, entry_id=entry_id,
            filter_map=filters)
        nas_acl.replace_entry_action_list(
            table_id=table_id, entry_id=entry_id,
            action_map=actions)
    except RuntimeError:
        print (sys._getframe().f_code.co_name + " - Error Modifying Entry")
        return None

    print (sys._getframe().f_code.co_name +
           " - Modified Entry " + str(entry_id))
    raw_input(
        "Check entry is modified (Del SRCIP,SRCMAC,Redirect port. Changed IPv6Flowlabel mask,IN PORTS,Packet Action. Add DSTIP, DST-MAC action. Press Enter to continue...")
    passed.append(sys._getframe().f_code.co_name)
    return entry_id
Пример #6
0
def acl_ut_entry_modify1(table_id, entry_id):
    global total, passed
    total.append(sys._getframe().f_code.co_name)
    e = nas_acl.EntryCPSObj(table_id=table_id, entry_id=entry_id)
    filters = {
        'DST_IP': '56.0.0.1',
        'IPV6_FLOW_LABEL': {'data': '34456', 'mask': '0xff'},
        'TCP_FLAGS': {'data': '0x17', 'mask': '0x3f'},
        'ECN': {'data': '0x2', 'mask': '0x2'},
        'IP_TYPE': 'IP',
        'IN_PORTS': [a_utl.get_if_name(3)],
    }
    actions = {
        'SET_DST_MAC': '01:00:79:08:78:BC',
        'MIRROR_INGRESS': {'index': mirror_id_1, 'data': mir_opq_1},
    }

    try:
        nas_acl.replace_entry_filter_list(
            table_id=table_id, entry_id=entry_id,
            filter_map=filters)
        nas_acl.replace_entry_action_list(
            table_id=table_id, entry_id=entry_id,
            action_map=actions)
    except RuntimeError:
        print (sys._getframe().f_code.co_name + " - Error Modifying Entry")
        return None

    print (sys._getframe().f_code.co_name +
           " - Modified Entry " + str(entry_id))
    raw_input(
        "Check entry is modified (Del SRCIP,SRCMAC,Redirect port. Changed IPv6Flowlabel mask,IN PORTS,Packet Action. Add DSTIP, DST-MAC action. Press Enter to continue...")
    passed.append(sys._getframe().f_code.co_name)
    return entry_id
Пример #7
0
def acl_ut_entry_modify_rollback(table_id, entry_id):
    global total, passed
    total.append(sys._getframe().f_code.co_name)

    e = nas_acl.EntryCPSObj(table_id=table_id, entry_id=entry_id)
    e.add_match_filter(
        filter_type='ECN',
        filter_val={
            'data': '0x3',
            'mask': '0x3'})
    e.add_match_filter(filter_type='IP_TYPE', filter_val='IPV6ANY')
    e.add_match_filter(
        filter_type='IN_PORTS',
        filter_val=[a_utl.get_if_name(1),
                    a_utl.get_if_name(5)])
    e.add_action(action_type='SET_DST_MAC', action_val='01:00:79:08:78:BC')
    e.add_action(
        action_type='REDIRECT_PORT',
        action_val=a_utl.get_if_name(6))

    upd = []
    upd.append(('set', e.data()))

    e = nas_acl.EntryCPSObj(table_id=table_id, entry_id=entry_id)
    e.add_match_filter(
        filter_type='IN_PORTS',
        filter_val=[a_utl.get_if_name(1),
                    a_utl.get_if_name(5)])
    e.add_match_filter(
        filter_type='IN_PORT',
        filter_val=a_utl.get_if_name(1))
    upd.append(('set', e.data()))

    r = cps_utils.CPSTransaction(upd).commit()

    if r:
        print (sys._getframe().f_code.co_name + " - NO Error Modifying Entry")
        return None

    print (sys._getframe().f_code.co_name +
           " - Rolled back Entry " + str(entry_id))
    raw_input("Check entry is reverted back. Press Enter to continue...")
    passed.append(sys._getframe().f_code.co_name)
    return entry_id
Пример #8
0
def acl_ut_entry_modify_rollback(table_id, entry_id):
    global total, passed
    total.append(sys._getframe().f_code.co_name)

    e = nas_acl.EntryCPSObj(table_id=table_id, entry_id=entry_id)
    e.add_match_filter(
        filter_type='ECN',
        filter_val={
            'data': '0x3',
            'mask': '0x3'})
    e.add_match_filter(filter_type='IP_TYPE', filter_val='IPV6ANY')
    e.add_match_filter(
        filter_type='IN_PORTS',
        filter_val=[a_utl.get_if_name(1),
                    a_utl.get_if_name(5)])
    e.add_action(action_type='SET_DST_MAC', action_val='01:00:79:08:78:BC')
    e.add_action(
        action_type='REDIRECT_PORT',
        action_val=a_utl.get_if_name(6))

    upd = []
    upd.append(('set', e.data()))

    e = nas_acl.EntryCPSObj(table_id=table_id, entry_id=entry_id)
    e.add_match_filter(
        filter_type='IN_PORTS',
        filter_val=[a_utl.get_if_name(1),
                    a_utl.get_if_name(5)])
    e.add_match_filter(
        filter_type='IN_PORT',
        filter_val=a_utl.get_if_name(1))
    upd.append(('set', e.data()))

    r = cps_utils.CPSTransaction(upd).commit()

    if r:
        print (sys._getframe().f_code.co_name + " - NO Error Modifying Entry")
        return None

    print (sys._getframe().f_code.co_name +
           " - Rolled back Entry " + str(entry_id))
    raw_input("Check entry is reverted back. Press Enter to continue...")
    passed.append(sys._getframe().f_code.co_name)
    return entry_id
Пример #9
0
#

filters = {
    'SRC_MAC': '01:80:c2:00:00:05',
    # Auto apply default mask
    'IPV6_FLOW_LABEL': '34456',

    'SRC_IP': {'addr': '23.0.0.1', 'mask': '255.0.0.255'},
    # Specify mask explicitly
    'TCP_FLAGS': {'data': '0x17', 'mask': '0x3f'},
    'ECN': {'data': '0x2', 'mask': '0x2'},

    'IP_TYPE': 'IP',
    # Filters where Mask is N/A
    'IN_PORT':
    a_utl.get_if_name(3),                     # Takes name or ifindex
}

actions = {
    'SET_SRC_MAC': '01:00:79:08:78:BC',
    'REDIRECT_PORT': a_utl.get_if_name(6),              # Takes name or ifindex
    'PACKET_ACTION': 'COPY_TO_CPU',
    'SET_COUNTER': counter_id,
    # Attach internal object to
                                                        # ACL action
    'MIRROR_INGRESS':
    {'index': mirr_id_1, 'data': mirr_opq_1}  # Attaching external obj
    # to ACL action
}

# Create an ACL entry with above filters and actions
Пример #10
0
def acl_ut_entry_modify2(table_id, entry_id, counter_id):
    global total, passed
    total.append(sys._getframe().f_code.co_name)

    # Using the internal CPS Obj instead of the convenience wrapper

    e = nas_acl.EntryCPSObj(table_id=table_id, entry_id=entry_id)
    e.add_match_filter(
        filter_type='SRC_IP',
        filter_val={
            'addr': '23.0.0.1',
            'mask': '255.0.0.255'})
    e.add_match_filter(
        filter_type='SRC_MAC',
        filter_val={'addr': '01:80:c2:00:00:05'})
    e.add_match_filter(
        filter_type='IPV6_FLOW_LABEL',
        filter_val={'data': '34456'})
    e.add_match_filter(
        filter_type='TCP_FLAGS',
        filter_val={
            'data': '0x17',
            'mask': '0x3f'})
    e.add_match_filter(
        filter_type='ECN',
        filter_val={
            'data': '0x2',
            'mask': '0x2'})
    e.add_match_filter(filter_type='IP_TYPE', filter_val='IP')
    e.add_match_filter(
        filter_type='IN_PORTS',
        filter_val=a_utl.get_if_name(2))
    e.add_action(action_type='SET_SRC_MAC', action_val='01:00:79:08:78:BC')
    e.add_action(action_type='PACKET_ACTION', action_val='COPY_TO_CPU')
    e.add_action(
        action_type='REDIRECT_PORT',
        action_val=a_utl.get_if_name(4))
    if (counter_id):
        e.add_action(action_type='SET_COUNTER', action_val=counter_id)

    global meter_id
    meter_opaque = a_utl.qos_meter_get_opaque_data(meter_id)
    if meter_opaque is None:
        return

    e.add_action(action_type='SET_POLICER',
                 action_val={'index': meter_id, 'data': meter_opaque})

    print e.data()
    upd = ('set', e.data())
    r = cps_utils.CPSTransaction([upd]).commit()

    if r == False:
        print (sys._getframe().f_code.co_name + " - Error modifying Entry")
        return None

    e = nas_acl.EntryCPSObj(cps_data=r[0])
    entry_id = e.extract_id()
    print (sys._getframe().f_code.co_name +
           " - Modified Entry " + str(entry_id))
    raw_input(
        "Check entry is modified (Add SRCIP,SRCMAC,Redirect port. Changed IPv6Flowlabel mask,IN PORTS,Packet Action. Del DSTIP, DST-MAC action. Press Enter to continue...")
    passed.append(sys._getframe().f_code.co_name)
    return entry_id
Пример #11
0
    'SRC_IP': {
        'addr': '23.0.0.1',
        'mask': '255.0.0.255'
    },
    # Specify mask explicitly
    'TCP_FLAGS': {
        'data': '0x17',
        'mask': '0x3f'
    },
    'ECN': {
        'data': '0x2',
        'mask': '0x2'
    },
    'IP_TYPE': 'IP',
    # Filters where Mask is N/A
    'IN_PORT': a_utl.get_if_name(3),  # Takes name or ifindex
}

actions = {
    'SET_SRC_MAC': '01:00:79:08:78:BC',
    'REDIRECT_PORT': a_utl.get_if_name(6),  # Takes name or ifindex
    'PACKET_ACTION': 'COPY_TO_CPU',
    'SET_COUNTER': counter_id,
    # Attach internal object to
    # ACL action
    'MIRROR_INGRESS': {
        'index': mirr_id_1,
        'data': mirr_opq_1
    }  # Attaching external obj
    # to ACL action
}
Пример #12
0
def acl_ut_entry_modify2(table_id, entry_id, counter_id):
    global total, passed
    total.append(sys._getframe().f_code.co_name)

    # Using the internal CPS Obj instead of the convenience wrapper

    e = nas_acl.EntryCPSObj(table_id=table_id, entry_id=entry_id)
    e.add_match_filter(
        filter_type='SRC_IP',
        filter_val={
            'addr': '23.0.0.1',
            'mask': '255.0.0.255'})
    e.add_match_filter(
        filter_type='SRC_MAC',
        filter_val={'addr': '01:80:c2:00:00:05'})
    e.add_match_filter(
        filter_type='IPV6_FLOW_LABEL',
        filter_val={'data': '34456'})
    e.add_match_filter(
        filter_type='TCP_FLAGS',
        filter_val={
            'data': '0x17',
            'mask': '0x3f'})
    e.add_match_filter(
        filter_type='ECN',
        filter_val={
            'data': '0x2',
            'mask': '0x2'})
    e.add_match_filter(filter_type='IP_TYPE', filter_val='IP')
    e.add_match_filter(
        filter_type='IN_PORTS',
        filter_val=a_utl.get_if_name(2))
    e.add_action(action_type='SET_SRC_MAC', action_val='01:00:79:08:78:BC')
    e.add_action(action_type='PACKET_ACTION', action_val='COPY_TO_CPU')
    e.add_action(
        action_type='REDIRECT_PORT',
        action_val=a_utl.get_if_name(4))
    if (counter_id):
        e.add_action(action_type='SET_COUNTER', action_val=counter_id)

    global meter_id
    meter_opaque = a_utl.qos_meter_get_opaque_data(meter_id)
    if meter_opaque is None:
        return

    e.add_action(action_type='SET_POLICER',
                 action_val={'index': meter_id, 'data': meter_opaque})

    print e.data()
    upd = ('set', e.data())
    r = cps_utils.CPSTransaction([upd]).commit()

    if r == False:
        print (sys._getframe().f_code.co_name + " - Error modifying Entry")
        return None

    e = nas_acl.EntryCPSObj(cps_data=r[0])
    entry_id = e.extract_id()
    print (sys._getframe().f_code.co_name +
           " - Modified Entry " + str(entry_id))
    raw_input(
        "Check entry is modified (Add SRCIP,SRCMAC,Redirect port. Changed IPv6Flowlabel mask,IN PORTS,Packet Action. Del DSTIP, DST-MAC action. Press Enter to continue...")
    passed.append(sys._getframe().f_code.co_name)
    return entry_id