1 /*! \file fdb_example.py
33 def __init__(self, client):
34 self.clientHandle = client
35 self.m_valn_table = []
39 buf = open_.getByteBuffer(100,
'')
41 print(
"received a TypeError exception from getByteBuffer")
43 except OpENBufferSizeError:
44 print(
"received an OpENBufferSizeError exception")
47 mac = OpEN.open_buffdesc()
51 vlanId = OpEN.new_uint32_tp()
52 OpEN.uint32_tp_assign(vlanId, 1)
54 fdbIfNum = OpEN.new_uint32_tp()
55 OpEN.uint32_tp_assign(fdbIfNum, 1)
57 fdbEntryType = OpEN.new_OPEN_FDB_ADDR_FLAG_tp()
58 fdbEntryType = OpEN.copy_OPEN_FDB_ADDR_FLAG_tp(OpEN.OPEN_FDB_ADDR_FLAG_STATIC)
60 fdbId = OpEN.new_uint32_tp()
61 value = OpEN.new_uint32_tp()
62 vlType = OpEN.new_OPEN_VL_TYPE_tp()
63 vlType = OpEN.copy_OPEN_VL_TYPE_tp(OpEN.OPEN_IVL_TYPE)
65 open_event = OpEN.openapiEventList_t()
66 OpEN.openapiEventListClear(open_event)
68 result = OpEN.openapiEventRegister(self.clientHandle, open_event)
69 if result != OpEN.OPEN_E_NONE:
70 print "Failed to register for OPEN_EVENT_FDB events.\n"
73 print "Successfully registered for OPEN_EVENT_FDB events.\n"
77 ''' Testing of the retrieving the first entry from the forwarding database '''
78 result = OpEN.openapiFdbEntryNextGet(self.clientHandle, mac, vlanId, fdbIfNum, fdbEntryType)
79 if result != OpEN.OPEN_E_NONE:
80 print "Failed to get the first entry from the forwarding database (Result = %d)\n" % result
83 print "Success: Get the first entry from the forwarding database with MAC: %s\n" % buf.cast()
85 ''' Testing of the retrieving the next entry from the forwarding database '''
86 result = OpEN.openapiFdbEntryNextGet(self.clientHandle, mac, vlanId, fdbIfNum, fdbEntryType)
87 if result != OpEN.OPEN_E_NONE:
88 if OpEN.OPEN_E_NOT_FOUND != result:
89 print "Failed to get the next entry from the forwarding database (Result = %d)\n" % result
91 print "Success: Cannot get the next entry from the forwarding database - entry not found (Result = %d)\n" % result
93 print "Success: Get the next entry from the forwarding database with MAC: %s\n" % buf.cast()
95 ''' Testing of the verification is a FDB with the specified ID exists '''
96 result = OpEN.openapiFdbIdGet(self.clientHandle, OpEN.uint32_tp_value(fdbId))
97 if OpEN.OPEN_E_NONE == result:
98 print "Success: FDB with ID %d exists.\n" % OpEN.uint32_tp_value(fdbId)
99 elif OpEN.OPEN_E_NOT_FOUND == result:
100 print "Success: FDB with ID %d is not exists.\n" % OpEN.uint32_tp_value(fdbId)
102 print "Failed to verify is FDB with ID %d exists. (Result = %d)\n" % (OpEN.uint32_tp_value(fdbId), result)
105 ''' Testing Fdb Address Aging Timeout - only if FDB exists '''
106 if OpEN.OPEN_E_NONE == result:
107 result = OpEN.openapiFdbAddrAgingTimeoutGet(self.clientHandle, OpEN.uint32_tp_value(fdbId), value)
108 if OpEN.OPEN_E_NONE == result:
109 print "Success: Fdb Address Aging Timeout is %d.\n" % (OpEN.uint32_tp_value(value))
111 print "Failed to get Fdb Address Aging Timeout for FDB with ID %d. (Result = %d)\n" % (OpEN.uint32_tp_value(fdbId), result)
113 ''' Testing of the Set Fdb Address Aging Timeout '''
114 OpEN.uint32_tp_assign(value, OpEN.uint32_tp_value(value) + 1)
115 OpEN.uint32_tp_assign(value, OpEN.uint32_tp_value(value) + 1)
116 result = OpEN.openapiFdbAddrAgingTimeoutSet(self.clientHandle, OpEN.uint32_tp_value(fdbId), value)
117 if OpEN.OPEN_E_NONE == result:
118 print "Success: Set Fdb Address Aging Timeout value: %d.\n" % (OpEN.uint32_tp_value(value))
120 print "Failed to set Fdb Address Aging Timeout value: %d. (Result = %d)\n" % (OpEN.uint32_tp_value(value), result)
122 ''' Testing maximum number of entries that the FDB table can hold '''
123 result = OpEN.openapiFdbMaxTableEntriesGet(self.clientHandle, value)
124 if OpEN.OPEN_E_NONE == result:
125 print "Success: The maximum number of FDB entries supported on the platform: %d.\n" % (OpEN.uint32_tp_value(value))
127 print "Failed to get maximum number of FDB entries supported on the platform. (Result = %d)\n" % (result)
129 ''' Testing of current number of entries in the FDB table '''
130 result = OpEN.openapiActiveAddrEntriesGet(self.clientHandle, value)
131 if OpEN.OPEN_E_NONE == result:
132 print "Success: The current number of FDB entries: %d.\n" % (value)
134 print "Failed to get the current number of FDB entries. (Result = %d)\n" % (result)
136 ''' Testing of count maximum number of entries in the FDB table '''
137 result = OpEN.openapiFdbMaxCountGet(self.clientHandle, value)
138 if OpEN.OPEN_E_NONE == result:
139 print "Success: The count maximum number of FDB entries: %d.\n" % (value)
141 print "Failed to get the count maximum number of FDB entries. (Result = %d)\n" % (result)
143 ''' Testing the reset of the greatest number of entries in the FDB table '''
144 result = OpEN.openapiMaxCountReset(self.clientHandle)
145 if OpEN.OPEN_E_NONE == result:
146 print "Success: The count greatest number of FDB entries is resetted.\n"
148 print "Failed to reset the greatest number of FDB entries. (Result = %d)\n" % (result)
150 ''' Testing the count of dynamic entries in the L2FDB '''
151 result = OpEN.openapiFdbDynamicEntriesGet(self.clientHandle, value)
152 if OpEN.OPEN_E_NONE == result:
153 print "Success: The count of dynamic entries in the L2FDB: %d.\n" % (value)
155 print "Failed to get the count of dynamic entries in the L2FDB. (Result = %d)\n" % (result)
157 ''' Testing the count of internally added entries in the L2FDB '''
158 result = OpEN.openapiFdbInternalEntriesGet(self.clientHandle, value)
159 if OpEN.OPEN_E_NONE == result:
160 print "Success: The count of internally added entries in the L2FDB: %d.\n" % (value)
162 print "Failed to get the count of internally added entries in the L2FDB. (Result = %d)\n" % (result)
164 ''' Testing of verification is specified MAC is restricted '''
165 result = OpEN.openapiIsRestrFilterMacGet(self.clientHandle, mac)
166 if OpEN.OPEN_E_NONE == result:
167 print "Success: The specified MAC is not restricted.\n"
168 elif OpEN.OPEN_E_DISABLED == result:
169 print "Success: The specified MAC is restricted.\n"
171 print "Failed to verify is specified MAC is restricted. (Result = %d)\n" % (result)
173 ''' Testing the retrieving next entry from the forwarding database based for the specified interface '''
174 result = OpEN.openapiFdbIntfEntryNextGet(self.clientHandle, mac, fdbIfNum, fdbEntryType)
175 if OpEN.OPEN_E_NONE == result:
176 print "Success: Get next entry from the forwarding database for the specified internal interface number: %d.\n" % (fdbIfNum)
178 print "Failed to get next entry from the forwarding database for the specified interface. (Result = %d)\n" % (result)
180 ''' Testing the retrieving next entry from the forwarding database based for the specified VLAN '''
181 result = OpEN.openapiFdbVlanEntryNextGet(self.clientHandle, mac, fdbIfNum, fdbEntryType, vlanId)
182 if OpEN.OPEN_E_NONE == result:
183 print "Success: Get next entry from the forwarding database for the specified VLAN.\n"
185 print "Failed to get next entry from the forwarding database for the specified VLAN. (Result = %d)\n" % (result)
187 ''' Testing the retrieving of the supported VL '''
188 result = OpEN.openapiFdbTypeOfVLGet(self.clientHandle, vlType)
189 if OpEN.OPEN_E_NONE == result:
190 print "Success: Get the supported VLAN learning type: %d.\n" % (vlType)
192 print "Failed to get the supported VL. (Result = %d)\n" % (result)
194 ''' Testing the retrieving of the next fdbID starting from a certain index '''
195 result = OpEN.openapiFdbIdNextGet(self.clientHandle, OpEN.uint32_tp_value(fdbId), value)
196 if OpEN.OPEN_E_NONE == result:
197 print "Success: Get the next fdbID starting from a '%d' index.\n" % (OpEN.uint32_tp_value(fdbId))
199 print "Cannot get the next fdbID starting from a '%d' index. (Result = %d)\n" % (OpEN.uint32_tp_value(fdbId), result)
201 ''' Testing of retrieving the number of failed FDB insert attempts due to failure to allocate space '''
202 result = OpEN.openapiFdbBadAddsGet(self.clientHandle, value)
203 if OpEN.OPEN_E_NONE == result:
204 print "Success: Get the number of failed FDB insert: %d.\n" % (value)
206 print "Failed to get the number of failed FDB insert. (Result = %d)\n" % (result)
208 ''' Testing of retrieving the max limit of MAC entries set in the hardware '''
209 result = OpEN.openapiFdbBadAddsGet(self.clientHandle, value)
210 if OpEN.OPEN_E_NONE == result:
211 print "Success: Get the max limit of MAC entries set in the hardware: %d.\n" % (value)
213 print "Failed to get the max limit of MAC entries set in the hardware. (Result = %d)\n" % (result)
215 ''' Testing of retrieving the value of dynamic entries in the L2FDB for a specific interface '''
216 result = OpEN.openapiFdbIntfDynamicEntriesGet(self.clientHandle, OpEN.uint32_tp_value(fdbIfNum), value)
217 if OpEN.OPEN_E_NONE == result:
218 print "Success: Get the value of dynamic entries in the L2FDB for a %d interface: %d.\n" % (OpEN.uint32_tp_value(fdbIfNum), value)
220 print "Failed to get the value of dynamic entries in the L2FDB for a %d interface. (Result = %d)\n" % (OpEN.uint32_tp_value(fdbIfNum), result)
222 ''' Testing of retrieving the value of dynamic entries in the L2FDB for a specific VLAN '''
223 result = OpEN.openapiFdbVlanDynamicEntriesGet(self.clientHandle, OpEN.uint32_tp_value(vlanId), value)
224 if OpEN.OPEN_E_NONE == result:
225 print "Success: Get the value of dynamic entries in the L2FDB for a VLAN %d: %d.\n" % (OpEN.uint32_tp_value(vlanId), value)
227 print "Failed to get the value of dynamic entries in the L2FDB for a VLAN %d. (Result = %d)\n" % (OpEN.uint32_tp_value(vlanId), result)
229 ''' Testing of retrieving the value of internal entries in the L2FDB for a specific interface '''
230 result = OpEN.openapiFdbIntfInternalEntriesGet(self.clientHandle, OpEN.uint32_tp_value(fdbIfNum), value)
231 if OpEN.OPEN_E_NONE == result:
232 print "Success: Get the value of internal entries in the L2FDB for a %d interface: %d.\n" % (OpEN.uint32_tp_value(fdbIfNum), value)
234 print "Failed to get the value of internal entries in the L2FDB for a %d interface. (Result = %d)\n" % (OpEN.uint32_tp_value(fdbIfNum), result)
236 ''' Testing of retrieving the value of internal entries in the L2FDB for a specific VLAN '''
237 result = OpEN.openapiFdbVlanInternalEntriesGet(self.clientHandle, OpEN.uint32_tp_value(vlanId), value)
238 if OpEN.OPEN_E_NONE == result:
239 print "Success: Get the value of internal entries in the L2FDB for a VLAN %d: %d.\n" % (OpEN.uint32_tp_value(vlanId), value)
241 print "Failed to get the value of internal entries in the L2FDB for a VLAN %d. (Result = %d)\n" % (OpEN.uint32_tp_value(vlanId), result)
243 ''' Testing of flushing all entries in fdb learned on the specified interface '''
244 result = OpEN.openapiFdbFlushByPort(self.clientHandle, OpEN.uint32_tp_value(fdbIfNum))
245 if OpEN.OPEN_E_NONE == result:
246 print "Success: Flushed all entries in fdb learned on the interface %d.\n" % (OpEN.uint32_tp_value(fdbIfNum))
248 print "Failed to flush all entries in fdb learned on the interface %d. (Result = %d)\n" % (OpEN.uint32_tp_value(fdbIfNum), result)
250 ''' Testing of flushing all entries in fdb learned on the specified VLAN '''
251 result = OpEN.openapiFdbFlushByVlan(self.clientHandle, OpEN.uint32_tp_value(vlanId))
252 if OpEN.OPEN_E_NONE == result:
253 print "Success: Flushed all entries in fdb learned on the VLAN %d.\n" % (OpEN.uint32_tp_value(vlanId))
255 print "Failed to flush all entries in fdb learned on the VLAN %d. (Result = %d)\n" % (OpEN.uint32_tp_value(vlanId), result)
257 ''' Testing of flushing all entries in fdb learned on the specified MAC '''
258 result = OpEN.openapiFdbFlushByMac(self.clientHandle, mac)
259 if OpEN.OPEN_E_NONE == result:
260 print "Success: Flushed all entries in fdb learned on the MAC.\n"
262 print "Failed to flush all entries in fdb learned on the MAC. (Result = %d)\n" % (result)
264 ''' Testing of flushing all learned entries from the L2FDB '''
265 result = OpEN.openapiFdbFlush(self.clientHandle)
266 if OpEN.OPEN_E_NONE == result:
267 print "Success: Flushed all learned entries from the L2FDB.\n"
269 print "Failed to flush all learned entries from the L2FDB. (Result = %d)\n" % (result)
273 ret = open_.connect(
"fdb_example")
274 if ret == OpEN.OPEN_E_NONE:
275 open_.getNetworkOSVersion()
276 open_.getAPIVersion()
277 client = open_.get_client()
279 fdbExample = FdbExample(client)
284 print "Unable to connect"
287 if __name__ ==
'__main__': main()