Skip to content

MAC address table application examples

Amy Buck edited this page Nov 29, 2018 · 5 revisions

This information contains MAC address table application examples, including verification.

  • cps_config_mac.py contains examples for creating and deleting MAC entries, as well as manipulating MAC tables for VLANs (see cps_config_mac.py).

  • nas_mac_unittest.cpp contains examples of MAC operations in C++ (see nas_mac_unittest.cpp).

NOTE: Refer to the dell-base-l2-mac.yang model which defines the MAC address object and attributes before you configure MAC address table settings.

Create MAC address table entry

1. Import the CPS object Python library.

import cps_utils

2. Register the attribute type to convert between the string and byte-array format.

cps_utils.add_attr_type("base-mac/table/mac-address", "mac")

3. Define the MAC address, interface index, and VLAN attributes.

d = {"mac-address": "00:0a:0b:cc:0d:0e","ifindex": 18,"vlan": "100"}

4. Create a CPS object.

obj = cps_utils.CPSObject('base-mac/table',data= d)

5. Associate the operation to the CPS object.

tr_obj = ('create', obj.get())

6. Create a transaction object.

transaction = cps_utils.CPSTransaction([tr_obj])

7. Verify the return value.

ret = transaction.commit()
if not ret:
  raise RuntimeError ("Error creating MAC Table Entry")

NOTE: When you do not enter a key qualifier, the target is used by default when creating an object.

See create_mac_table_entry.py to view the Python application example, or see create_mac_table_entry.c to view the C application example.

Verify MAC address table entry creation using CPS get

# cps_get_oid.py base-mac/query

Key:   1.16.1048594.
base-mac/query/ifindex   =  18
base-mac/query/actions   =  2
base-mac/query/static   =  1
base-mac/query/mac-address   =  000a0bcc0d0e
base-mac/query/vlan   =  100

Request MAC address table entry

1. Import the CPS and CPS object Python library.

import cps_utils
import cps

2 Register the attribute type to convert between string and byte-array format.

cps_utils.add_attr_type("base-mac/query/mac-address", "mac")

3. Define the MAC address request type.

d = {"mac-address": "00:0a:0b:cc:0d:0e","request-type":"2"}

4. Associate a get operation with the CPS object.

obj = cps_utils.CPSObject('base-mac/query',data= d)

5. Create an object filter list.

filter_list = []

6. Add the filter object.

filter_list.append(obj.get())

7. Create a list for the response.

lst = []

8. Verify objects returned.

if cps.get(filter_list,lst):

# Check if get returned objects in the response list
if lst:
  for ret_obj in lst:
      #  Print the returned Objects
      cps_utils.print_obj(ret_obj)
  else:
      # Empty list
  else:
      print "No objects found"
      raise RuntimeError ("Error Getting MAC Table Entries")

See get_mac_table_entry.py to view the Python application example, or see get_mac_table_entry.c to view the C application example.

Delete MAC address table entry

1. Import the CPS object Python library.

import cps_utils

2. Register the attribute type to convert between string and byte-array format.

cps_utils.add_attr_type("base-mac/table/mac-address", "mac")

3. Define the MAC address, interface index, and VLAN to delete the static address entry.

d = {"mac-address": "00:0a:0b:cc:0d:0e", "ifindex": 18, "vlan": "100"}

4. Create a CPS object.

obj = cps_utils.CPSObject('base-mac/table',data= d)

5. Add the operation to the CPS object.

tr_obj = ('delete', obj.get())

6. Create a transaction object.

transaction = cps_utils.CPSTransaction([tr_obj])

7. Verify the return value.

ret = transaction.commit()
if not ret:
  raise RuntimeError("Error deleting entry from MAC Table")

See delete_mac_table_entry.py to view the Python application example, or see delete_mac_table_entry.c to view the C application example.

To delete the MAC address from all VLANs, specify the vlan attribute and its value in the object. To delete all MAC entries from an interface, specify the ifindex attribute and its value in the object. To delete MAC entries from both a VLAN and member interface, specify the vlan and ifindex attributes and their values in the object.

NOTE: Deletion of static entries based only on VLAN, interface or a VLAN/interface combinations are not supported. To delete a static entry, you must add the mac-address, vlan, and ifindex attributes and their values to the object.

Delete MAC address table entries from multiple VLANs

1. Import the CPS object Python library.

import cps_utils

2. Define the VLANs to remove MAC address entries from.

vlan_list=[1,2,3,4,5]

3. Create the CPS object.

obj = cps_utils.CPSObject('base-mac/flush')

4. Add the VLAN list to the CPS object.

count  = 0
el = ["input/filter","0","vlan"]
for vlan in vlan_list:
  obj.add_embed_attr(el,   vlan)
  count = count + 1
el[1] = str(count)

5. Associate the operation to the CPS object.

tr_obj = ('rpc', obj.get())

6. Create a transaction object.

transaction = cps_utils.CPSTransaction([tr_obj])

7. Verify the return value.

ret = transaction.commit()
if not ret:
  raise RuntimeError("Error Flushing entries from MAC Table")

See remove_mac_table_entries_from_multiple_vlans.py to view the Python application example, or see remove_mac_table_entries_from_multiple_vlans.c to view the C application example.

Clone this wiki locally