Skip to content

VLAN application examples

Amy Buck edited this page Nov 28, 2018 · 14 revisions

This information contains VLAN application examples, including verification. cps_config_vlan.py contains examples for adding and deleting VLANs, adding and deleting ports to and from VLANs, and so on (see cps_config_vlan.py).

NOTE: VLAN refers to an NPU VLAN object which is modeled as a Linux bridge.

Create VLAN using Python

1. Import the CPS and CPS object Python library.

import cps_object
import cps

2. Create a CPS object.

cps_obj = cps_object.CPSObject('dell-base-if-cmn/if/interfaces/interface')

3. Define the VLAN ID.

VLAN_ID=100
cps_obj.add_attr("base-if-vlan/if/interfaces/interface/id",VLAN_ID)

4. Define the VLAN type with an L2 or L2 VLAN ID.

cps_obj.add_attr('if/interfaces/interface/type','ianaift:l2vlan')

5. Associate a create operation with the CPS object to create a new VLAN.

cps_update = {'change':cps_obj.get(),'operation': 'create'}

6. Add the CPS operation and object pair to a new CPS transaction.

transaction = cps.transaction([cps_update])

7. Verify the return value.

if not transaction:
   raise RuntimeError ("Error creating Vlan")

See create_vlan.py to view the Python application example.

Verify VLAN creation using CPS get

# cps_get_oid.py dell-opx-if-cmn/if/interfaces/interface if/interfaces/interface/type=ianaift:l2vlan

Key: 1.19.44.2883617.2883612.2883613.
dell-base-if-cmn/if/interfaces/interface/if-index = 40
dell-if/if/interfaces/interface/phys-address =base-if-vlan/if/interfaces/interface/id = 100
if/interfaces/interface/name = br100dell-if/if/interfaces/interface/learning-mode = 1
if/interfaces/interface/enabled = 0

Key: 1.19.44.2883617.2883612.2883613.
dell-base-if-cmn/if/interfaces/interface/if-index = 3
dell-if/if/interfaces/interface/phys-address = 90:b1:1c:f4:ab:ed
base-if-vlan/if/interfaces/interface/id = 0
if/interfaces/interface/name = docker0
dell-if/if/interfaces/interface/learning-mode = 1
if/interfaces/interface/enabled = 0

NOTE: OPX allocates an ifindex for each VLAN created. Further CPS set and get operations can use ifindex as the key.

Verify VLAN creation using Linux

$ brctl show
bridge   name             bridge   id                        STP   enabled             interfaces
br100 

Add VLAN port using Python

1. Import the CPS and CPS object Python library.

import cps
import cps_object

2. Create a CPS object.

cps_obj = cps_object.CPSObject('dell-base-if-cmn/if/interfaces/interface')

3. Define the VLAN interface name.

VLAN_IF_NAME='br100'
cps_obj.add_attr('if/interfaces/interface/name',VLAN_IF_NAME)

4. Define the untagged port to add to the VLAN.

if_port_list=['e101-001-0']
cps_obj.add_attr('dell-if/if/interfaces/interface/untagged-ports',if_port_list)

5. Associate a set operation with the CPS object to modify the property of an existing VLAN.

cps_update = {'change':cps_obj.get(),'operation': 'set'}

6. Add the CPS operation and object pair to a new CPS transaction.

transaction = cps.transaction([cps_update])

7. Verify the return value.

if not transaction:
   raise RuntimeError ("Error adding ports to Vlan")

See add_vlan_port.py to view the Python application example.

Verify VLAN port addition using CPS get

# cps_get_oid.py dell-opx-if-cmn/if/interfaces/interface if/interfaces/interface/type=ianaift:l2vlan

Key: 1.19.44.2883617.2883612.2883613.
dell-base-if-cmn/if/interfaces/interface/if-index = 43
dell-if/if/interfaces/interface/phys-address =
dell-if/if/interfaces/interface/untagged-ports = e101-003-0,e101-002-0,e101-001-0
base-if-vlan/if/interfaces/interface/id = 100
if/interfaces/interface/name = br100
dell-if/if/interfaces/interface/learning-mode = 1
if/interfaces/interface/enabled = 0

Key: 1.19.44.2883617.2883612.2883613.
dell-base-if-cmn/if/interfaces/interface/if-index = 3
dell-if/if/interfaces/interface/phys-address = 90:b1:1c:f4:ab:ed
base-if-vlan/if/interfaces/interface/id = 0
if/interfaces/interface/name = docker0
dell-if/if/interfaces/interface/learning-mode = 1
if/interfaces/interface/enabled = 0

Verify VLAN port addition using Linux

$ brctl show
bridge name   bridge id            STP     enabled interfaces
br100         8000.90b11cf4abee    no      e101-001-0
                                           e101-002-0
                                           e101-003-0

Delete VLAN port using Python

1. Import the CPS and CPS object Python library.

import cps
import cps_object

2. Create a CPS object.

cps_obj = cps_object.CPSObject('dell-base-if-cmn/if/interfaces/interface')

3. Define the VLAN interface name.

VLAN_IF_NAME='br100'
cps_obj.add_attr('if/interfaces/interface/name',VLAN_IF_NAME)

4. Define the untagged port to be included in the VLAN (all other ports will be deleted from the VLAN).

if_port_list=['e101-002-0']
cps_obj.add_attr('dell-if/if/interfaces/interface/untagged-ports',if_port_list)

5. Associate a set operation with the CPS object to modify the property of an existing VLAN.

cps_update = {'change':cps_obj.get(),'operation': 'set'}

6. Add the CPS operation and object pair to a new CPS transaction.

transaction = cps.transaction([cps_update])

7. Verify the return value.

if not transaction:
  raise RuntimeError ("Error in deleting ports to Vlan")
print "successful"

See delete_ports_vlan.py to view the Python application example.

Verify VLAN port deletion using CPS get

# cps_get_oid.py dell-base-if-cmn/if/interfaces/interface if/interfaces/interface/type=ianaift:l2vlan

Key: 1.19.44.2883617.2883612.2883613.
dell-base-if-cmn/if/interfaces/interface/if-index = 47
dell-if/if/interfaces/interface/phys-address =
dell-if/if/interfaces/interface/untagged-ports = e101-002-0
base-if-vlan/if/interfaces/interface/id = 100
if/interfaces/interface/name = br100
dell-if/if/interfaces/interface/learning-mode = 1
if/interfaces/interface/enabled = 0

Key: 1.19.44.2883617.2883612.2883613.
dell-base-if-cmn/if/interfaces/interface/if-index = 3
dell-if/if/interfaces/interface/phys-address = 90:b1:1c:f4:ab:ed
base-if-vlan/if/interfaces/interface/id = 0
if/interfaces/interface/name = docker0
dell-if/if/interfaces/interface/learning-mode = 1
if/interfaces/interface/enabled = 0

Verify VLAN port deletion using Linux

$ brctl show
bridge name bridge id STP enabled interfaces
br100 8000.000000000000 no         e101-002-0

Delete VLAN using Python

1. Import the CPS and CPS object Python library.

import cps
import cps_object

2. Create a CPS object.

cps_obj = cps_object.CPSObject('dell-base-if-cmn/if/interfaces/interface')

3. Define the name of the VLAN interface to delete.

VLAN_IF_NAME='br100'
cps_obj.add_attr('if/interfaces/interface/name',VLAN_IF_NAME)

4. Associate a delete operation with the CPS object to delete an existing VLAN.

cps_update = {'change':cps_obj.get(),'operation': 'delete'}

5. Add the CPS operation and object pair to a new CPS transaction.

transaction = cps.transaction([cps_update])

6. Verify the return value.

if not transaction:
  raise RuntimeError ("Error in deleting Vlan")
print "successful"

See delete_vlan.py to view the Python application example.

Verify VLAN using CPS get

# cps_get_oid.py dell-base-if-cmn/if/interfaces/interface if/interfaces/interface/type=ianaift:l2vlan

Key: 1.19.44.2883617.2883612.2883613.
dell-base-if-cmn/if/interfaces/interface/if-index = 3
dell-if/if/interfaces/interface/phys-address = 90:b1:1c:f4:ab:ed
base-if-vlan/if/interfaces/interface/id = 0
if/interfaces/interface/name = docker0
dell-if/if/interfaces/interface/learning-mode = 1
if/interfaces/interface/enabled = 0

Verify VLAN deletion using Linux

$ brctl show br100
Clone this wiki locally