1 /*! \file pbvlan_example.py
11 def __init__(self, client):
14 ''' Creates new Protocol-Based Group with specified group ID '''
15 def pbvlanGroupCreate(self, groupId):
16 result = OpEN.openapiPbVlanGroupCreate(self.client, groupId)
17 if result == OpEN.OPEN_E_NONE:
18 print "The new Protocol-Based VLAN group with specified ID (%d) has been successfully created. (result = %d)" % (groupId, result)
19 elif result == OpEN.OPEN_E_EXISTS:
20 print "Protocol-Based VLAN group with specified ID (%d) already exists. (result = %d)" % (groupId, result)
21 elif result == OpEN.OPEN_E_PARAM:
22 print "Invalid parameter was passed. (result = %d)" % (result)
24 print "Failed to created new Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (groupId, result)
28 ''' Deletes Protocol-Based Group with specified group ID '''
29 def pbvlanGroupDelete(self, groupId):
30 result = OpEN.openapiPbVlanGroupDelete(self.client, groupId)
31 if result == OpEN.OPEN_E_NONE:
32 print "Protocol-Based VLAN group with specified ID (%d) has been successfully deleted. (result = %d)" % (groupId, result)
33 elif result == OpEN.OPEN_E_NOT_FOUND:
34 print "Protocol-Based VLAN group with specified ID (%d) was not found. (result = %d)" % (groupId, result)
35 elif result == OpEN.OPEN_E_PARAM:
36 print "Invalid parameter was passed. (result = %d)" % (result)
38 print "Failed to delete Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (groupId, result)
42 ''' Demonstrates how to set/get a name of the Protocol-Based Group with specified group ID '''
43 def pbvlanNameExample(self, groupId, groupName):
44 result = self.pbvlanGroupCreate(groupId)
45 if (result != OpEN.OPEN_E_NONE)
and (result != OpEN.OPEN_E_EXISTS):
48 buffdesc = OpEN.open_buffdesc()
50 buf_set = open_.getStringBuffer(len(groupName) + 1, groupName)
51 except OpENBufferSizeError:
52 print(
"pbvlanNameExample: getStringBuffer raised OpENBufferSizeError")
55 print(
"pbvlanNameExample: getStringBuffer raised TypeError")
57 buffdesc.pstart = buf_set
58 buffdesc.size = len(groupName) + 1
60 result = OpEN.openapiPbVlanGroupNameSet(self.client, groupId, buffdesc)
61 if result == OpEN.OPEN_E_NONE:
62 print "The name (%s) of the Protocol-Based VLAN group with specified ID (%d) has been successfully set. (result = %d)" % (buf_set.cast(), groupId, result)
63 elif result == OpEN.OPEN_E_NOT_FOUND:
64 print "Protocol-Based VLAN group with specified ID (%d) was not found. (result = %d)" % (groupId, result)
65 elif result == OpEN.OPEN_E_PARAM:
66 print "Invalid parameter was passed. (result = %d)" % (result)
68 print "Failed to set the name (%s) of the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (buf_set.cast(), groupId, result)
70 if result == OpEN.OPEN_E_NONE:
71 group_name = OpEN.open_buffdesc()
72 group_name.size = OpEN.OPENAPI_PBVLAN_MAX_GROUP_NAME + 1
74 buf_get = open_.getStringBuffer(group_name.size)
75 except OpENBufferSizeError:
76 print(
"pbvlanNameExample: getStringBuffer raised OpENBufferSizeError")
79 print(
"pbvlanNameExample: getStringBuffer raised TypeError")
81 group_name.pstart = buf_get
83 result = OpEN.openapiPbVlanGroupNameGet(self.client, groupId, group_name)
84 if result == OpEN.OPEN_E_NONE:
85 print "The name of the Protocol-Based VLAN group with specified ID (%d) is %s. (result = %d)" % (groupId, buf_get.cast(), result)
86 elif result == OpEN.OPEN_E_NOT_FOUND:
87 print "Protocol-Based VLAN group with specified ID (%d) was not found. (result = %d)" % (groupId, result)
88 elif result == OpEN.OPEN_E_PARAM:
89 print "Invalid parameter was passed. (result = %d)" % (result)
91 print "Failed to get the name of the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (groupId, result)
93 self.pbvlanGroupDelete(groupId)
97 ''' Demonstrates how to add/get/delete VLAN ID of the Protocol-Based Group with specified group ID '''
98 def pbvlanVlanExample(self, groupId, vlanId):
99 result = self.pbvlanGroupCreate(groupId)
100 if (result != OpEN.OPEN_E_NONE)
and (result != OpEN.OPEN_E_EXISTS):
103 result = OpEN.openapiPbVlanGroupVlanIDAdd(self.client, groupId, vlanId)
104 if result == OpEN.OPEN_E_NONE:
105 print "The VLAN (%d) has been successfully added to the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (vlanId, groupId, result)
106 elif result == OpEN.OPEN_E_NOT_FOUND:
107 print "Protocol-Based VLAN group with specified ID (%d) was not found. (result = %d)" % (groupId, result)
108 elif result == OpEN.OPEN_E_PARAM:
109 print "Invalid parameter was passed. (result = %d)" % (str.cast(), result)
111 print "Failed to add the VLAN (%d) to the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (vlanId, groupId, result)
113 if result == OpEN.OPEN_E_NONE:
114 newVlanId_p = OpEN.new_uint32_tp()
116 result = OpEN.openapiPbVlanGroupVlanIDGet(self.client, groupId, newVlanId_p)
117 if result == OpEN.OPEN_E_NONE:
118 print "The VLAN ID of the Protocol-Based VLAN group with specified ID (%d) is %d. (result = %d)" % (groupId, OpEN.uint32_tp_value(newVlanId_p), result)
119 elif result == OpEN.OPEN_E_NOT_FOUND:
120 print "Protocol-Based VLAN group with specified ID (%d) was not found. (result = %d)" % (groupId, result)
121 elif result == OpEN.OPEN_E_PARAM:
122 print "Invalid parameter was passed. (result = %d)" % (result)
124 print "Failed to get the VLAN ID of the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (groupId, result)
126 result = OpEN.openapiPbVlanGroupVlanIDDelete(self.client, groupId, vlanId)
127 if result == OpEN.OPEN_E_NONE:
128 print "The VLAN (%d) has been successfully deleted from the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (vlanId, groupId, result)
129 elif result == OpEN.OPEN_E_NOT_FOUND:
130 print "Protocol-Based VLAN group with specified ID (%d) was not found. (result = %d)" % (groupId, result)
131 elif result == OpEN.OPEN_E_ERROR:
132 print "VLAN (%d) was not found in the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (vlanId, groupId, result)
133 elif result == OpEN.OPEN_E_PARAM:
134 print "Invalid parameter was passed. (result = %d)" % (result)
136 print "Failed to delete the VLAN (%d) from the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (vlanId, groupId, result)
138 OpEN.delete_uint32_tp(newVlanId_p)
140 self.pbvlanGroupDelete(groupId)
143 ''' Demonstrates how to add/get/delete a protocol of the Protocol-Based Group with specified group ID '''
144 def pbvlanProtocolExample(self, groupId, prot, protType):
145 result = self.pbvlanGroupCreate(groupId)
146 if (result != OpEN.OPEN_E_NONE)
and (result != OpEN.OPEN_E_EXISTS):
149 result = OpEN.openapiPbVlanGroupProtocolAdd(self.client, groupId, prot, protType)
150 if result == OpEN.OPEN_E_NONE:
151 print "The protocol (%d) has been successfully added to the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (prot, groupId, result)
152 elif result == OpEN.OPEN_E_NOT_FOUND:
153 print "Protocol-Based VLAN group with specified ID (%d) was not found. (result = %d)" % (groupId, result)
154 elif result == OpEN.OPEN_E_EXISTS:
155 print "Protocol (%d) is already added to the group with specified ID (%d). (result = %d)" % (prot, groupId, result)
156 elif result == OpEN.OPEN_E_PARAM:
157 print "Invalid parameter was passed. (result = %d)" % (result)
159 print "Failed to add the protocol (%d) to the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (prot, groupId, result)
161 if (result == OpEN.OPEN_E_NONE)
or (result == OpEN.OPEN_E_EXISTS):
162 newProt_p = OpEN.new_uint32_tp()
164 result = OpEN.openapiPbVlanGroupProtocolGetNext(self.client, groupId, 0, newProt_p)
165 if result == OpEN.OPEN_E_NONE:
166 print "The first protocol of the Protocol-Based VLAN group with specified ID (%d) is %d. (result = %d)" % (groupId, OpEN.uint32_tp_value(newProt_p), result)
167 elif result == OpEN.OPEN_E_NOT_FOUND:
168 print "Protocol-Based VLAN group with specified ID (%d) was not found. (result = %d)" % (groupId, result)
169 elif result == OpEN.OPEN_E_PARAM:
170 print "Invalid parameter was passed. (result = %d)" % (result)
172 print "Failed to get the first protocol of the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (groupId, result)
174 result = OpEN.openapiPbVlanGroupProtocolDelete(self.client, groupId, prot)
175 if result == OpEN.OPEN_E_NONE:
176 print "The protocol (%d) has been successfully deleted from the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (prot, groupId, result)
177 elif result == OpEN.OPEN_E_NOT_FOUND:
178 print "Protocol-Based VLAN group with specified ID (%d) was not found. (result = %d)" % (groupId, result)
179 elif result == OpEN.OPEN_E_ERROR:
180 print "Protocol (%d) was not found in the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (prot, groupId, result)
181 elif result == OpEN.OPEN_E_PARAM:
182 print "Invalid parameter was passed. (result = %d)" % (result)
184 print "Failed to delete the protocol (%d) from the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (prot, groupId, result)
186 OpEN.delete_uint32_tp(newProt_p)
188 self.pbvlanGroupDelete(groupId)
191 ''' Demonstrates how to add/get/delete an interface of the Protocol-Based Group with specified group ID '''
192 def pbvlanPortExample(self, groupId, ifNum):
193 result = self.pbvlanGroupCreate(groupId)
194 if (result != OpEN.OPEN_E_NONE)
and (result != OpEN.OPEN_E_EXISTS):
197 result = OpEN.openapiPbVlanIntfValidate(self.client, ifNum)
198 if result == OpEN.OPEN_E_NONE:
199 print "The interface (%d) could be used for the Protocol-Based VLAN configuration. (result = %d)" % (ifNum, result)
200 elif result == OpEN.OPEN_E_PARAM:
201 print "Invalid parameter was passed. (result = %d)" % (result)
203 print "The interface (%d) could not be used for the Protocol-Based VLAN configuration. (result = %d)" % (ifNum, result)
205 result = OpEN.openapiPbVlanGroupPortAdd(self.client, groupId, ifNum)
206 if result == OpEN.OPEN_E_NONE:
207 print "The interface (%d) has been successfully added to the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (ifNum, groupId, result)
208 elif result == OpEN.OPEN_E_NOT_FOUND:
209 print "Protocol-Based VLAN group with specified ID (%d) was not found. (result = %d)" % (groupId, result)
210 elif result == OpEN.OPEN_E_PARAM:
211 print "Invalid parameter was passed. (result = %d)" % (result)
213 print "Failed to add the protocol (%d) to the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (ifNum, groupId, result)
215 if result == OpEN.OPEN_E_NONE:
216 newIfNum_p = OpEN.new_uint32_tp()
218 result = OpEN.openapiPbVlanGroupPortGetNext(self.client, groupId, 0, newIfNum_p)
219 if result == OpEN.OPEN_E_NONE:
220 print "The first interface of the Protocol-Based VLAN group with specified ID (%d) is %d. (result = %d)" % (groupId, OpEN.uint32_tp_value(newIfNum_p), result)
221 elif result == OpEN.OPEN_E_NOT_FOUND:
222 print "Protocol-Based VLAN group with specified ID (%d) was not found. (result = %d)" % (groupId, result)
223 elif result == OpEN.OPEN_E_PARAM:
224 print "Invalid parameter was passed. (result = %d)" % (result)
226 print "Failed to get the first interface of the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (groupId, result)
228 result = OpEN.openapiPbVlanGroupPortDelete(self.client, groupId, ifNum)
229 if result == OpEN.OPEN_E_NONE:
230 print "The interface (%d) has been successfully deleted from the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (ifNum, groupId, result)
231 elif result == OpEN.OPEN_E_NOT_FOUND:
232 print "Protocol-Based VLAN group with specified ID (%d) was not found. (result = %d)" % (groupId, result)
233 elif result == OpEN.OPEN_E_ERROR:
234 print "Interface (%d) was not found in the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (ifNum, groupId, result)
235 elif result == OpEN.OPEN_E_PARAM:
236 print "Invalid parameter was passed. (result = %d)" % (result)
238 print "Failed to delete the protocol (%d) from the Protocol-Based VLAN group with specified ID (%d). (result = %d)" % (ifNum, groupId, result)
240 OpEN.delete_uint32_tp(newIfNum_p)
242 self.pbvlanGroupDelete(groupId)
246 ret = open_.connect(
"pbvlan_example")
247 if ret == OpEN.OPEN_E_NONE :
248 open_.getNetworkOSVersion()
249 client = open_.get_client()
251 example = pbvlanExample(client)
252 example.pbvlanNameExample(10,
"test_name")
253 example.pbvlanVlanExample(10, 10)
254 example.pbvlanProtocolExample(10, 0x0800, OpEN.OPENAPI_PBVLAN_NUM_PROT_TYPE)
255 example.pbvlanPortExample(10, 1)
259 print "Unable to connect"
261 if __name__ ==
'__main__': main()