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 OpEN.uint32_tp_assign(fdbId, 0)
62 value = OpEN.new_uint32_tp()
63 vlType = OpEN.new_OPEN_VL_TYPE_tp()
64 vlType = OpEN.copy_OPEN_VL_TYPE_tp(OpEN.OPEN_IVL_TYPE)
68 ''' Testing of the retrieving the first entry from the forwarding database '''
69 result = OpEN.openapiFdbEntryNextGet(self.clientHandle, mac, vlanId, fdbIfNum, fdbEntryType)
70 if result != OpEN.OPEN_E_NONE:
71 print "Failed to get the first entry from the forwarding database (Result = %d)\n" % result
74 print "Success: Get the first entry from the forwarding database with MAC: %s\n" % buf.cast()
76 ''' Testing of the retrieving the next entry from the forwarding database '''
77 result = OpEN.openapiFdbEntryNextGet(self.clientHandle, mac, vlanId, fdbIfNum, fdbEntryType)
78 if result != OpEN.OPEN_E_NONE:
79 if OpEN.OPEN_E_NOT_FOUND != result:
80 print "Failed to get the next entry from the forwarding database (Result = %d)\n" % result
82 print "Success: Cannot get the next entry from the forwarding database - entry not found (Result = %d)\n" % result
84 print "Success: Get the next entry from the forwarding database with MAC: %s\n" % buf.cast()
86 ''' Testing of the verification is a FDB with the specified ID exists '''
87 result = OpEN.openapiFdbIdGet(self.clientHandle, OpEN.uint32_tp_value(fdbId))
88 if OpEN.OPEN_E_NONE == result:
89 print "Success: FDB with ID %d exists.\n" % OpEN.uint32_tp_value(fdbId)
90 elif OpEN.OPEN_E_NOT_FOUND == result:
91 print "Success: FDB with ID %d is not exists.\n" % OpEN.uint32_tp_value(fdbId)
93 print "Failed to verify is FDB with ID %d exists. (Result = %d)\n" % (OpEN.uint32_tp_value(fdbId), result)
96 ''' Testing Fdb Address Aging Timeout - only if FDB exists '''
97 if OpEN.OPEN_E_NONE == result:
98 result = OpEN.openapiFdbAddrAgingTimeoutGet(self.clientHandle, OpEN.uint32_tp_value(fdbId), value)
99 if OpEN.OPEN_E_NONE == result:
100 print "Success: Fdb Address Aging Timeout is %d.\n" % (OpEN.uint32_tp_value(value))
102 print "Failed to get Fdb Address Aging Timeout for FDB with ID %d. (Result = %d)\n" % (OpEN.uint32_tp_value(fdbId), result)
104 ''' Testing of the Set Fdb Address Aging Timeout '''
105 OpEN.uint32_tp_assign(value, OpEN.uint32_tp_value(value) + 1)
106 result = OpEN.openapiFdbAddrAgingTimeoutSet(self.clientHandle, OpEN.uint32_tp_value(fdbId), OpEN.uint32_tp_value(value))
107 if OpEN.OPEN_E_NONE == result:
108 print "Success: Set Fdb Address Aging Timeout value: %d.\n" % (OpEN.uint32_tp_value(value))
110 print "Failed to set Fdb Address Aging Timeout value: %d. (Result = %d)\n" % (OpEN.uint32_tp_value(value), result)
112 ''' Testing maximum number of entries that the FDB table can hold '''
113 result = OpEN.openapiFdbMaxTableEntriesGet(self.clientHandle, value)
114 if OpEN.OPEN_E_NONE == result:
115 print "Success: The maximum number of FDB entries supported on the platform: %d.\n" % (OpEN.uint32_tp_value(value))
117 print "Failed to get maximum number of FDB entries supported on the platform. (Result = %d)\n" % (result)
119 ''' Testing of current number of entries in the FDB table '''
120 result = OpEN.openapiActiveAddrEntriesGet(self.clientHandle, value)
121 if OpEN.OPEN_E_NONE == result:
122 print "Success: The current number of FDB entries: %d.\n" % (OpEN.uint32_tp_value(value))
124 print "Failed to get the current number of FDB entries. (Result = %d)\n" % (result)
126 ''' Testing of count maximum number of entries in the FDB table '''
127 result = OpEN.openapiFdbMaxCountGet(self.clientHandle, value)
128 if OpEN.OPEN_E_NONE == result:
129 print "Success: The count maximum number of FDB entries: %d.\n" % (OpEN.uint32_tp_value(value))
131 print "Failed to get the count maximum number of FDB entries. (Result = %d)\n" % (result)
133 ''' Testing the reset of the greatest number of entries in the FDB table '''
134 result = OpEN.openapiMaxCountReset(self.clientHandle)
135 if OpEN.OPEN_E_NONE == result:
136 print "Success: The count greatest number of FDB entries is resetted.\n"
138 print "Failed to reset the greatest number of FDB entries. (Result = %d)\n" % (result)
140 ''' Testing the count of dynamic entries in the L2FDB '''
141 result = OpEN.openapiFdbDynamicEntriesGet(self.clientHandle, value)
142 if OpEN.OPEN_E_NONE == result:
143 print "Success: The count of dynamic entries in the L2FDB: %d.\n" % (OpEN.uint32_tp_value(value))
145 print "Failed to get the count of dynamic entries in the L2FDB. (Result = %d)\n" % (result)
147 ''' Testing the count of internally added entries in the L2FDB '''
148 result = OpEN.openapiFdbInternalEntriesGet(self.clientHandle, value)
149 if OpEN.OPEN_E_NONE == result:
150 print "Success: The count of internally added entries in the L2FDB: %d.\n" % (OpEN.uint32_tp_value(value))
152 print "Failed to get the count of internally added entries in the L2FDB. (Result = %d)\n" % (result)
154 ''' Testing of verification is specified MAC is restricted '''
155 result = OpEN.openapiIsRestrFilterMacGet(self.clientHandle, mac)
156 if OpEN.OPEN_E_NONE == result:
157 print "Success: The specified MAC is not restricted.\n"
158 elif OpEN.OPEN_E_DISABLED == result:
159 print "Success: The specified MAC is restricted.\n"
161 print "Failed to verify is specified MAC is restricted. (Result = %d)\n" % (result)
163 ''' Testing the retrieving of the supported VL '''
164 result = OpEN.openapiFdbTypeOfVLGet(self.clientHandle, vlType)
165 if OpEN.OPEN_E_NONE == result:
166 print "Success: Get the supported VLAN learning type: %d.\n" % (OpEN.OPEN_VL_TYPE_tp_value(vlType))
168 print "Failed to get the supported VL. (Result = %d)\n" % (result)
170 ''' Testing the retrieving of the next fdbID starting from a certain index '''
171 result = OpEN.openapiFdbIdNextGet(self.clientHandle, OpEN.uint32_tp_value(fdbId), value)
172 if OpEN.OPEN_E_NONE == result:
173 print "Success: Get the next fdbID starting from a '%d' index.\n" % (OpEN.uint32_tp_value(fdbId))
175 print "Cannot get the next fdbID starting from a '%d' index. (Result = %d)\n" % (OpEN.uint32_tp_value(fdbId), result)
177 ''' Testing of retrieving the number of failed FDB insert attempts due to failure to allocate space '''
178 result = OpEN.openapiFdbBadAddsGet(self.clientHandle, value)
179 if OpEN.OPEN_E_NONE == result:
180 print "Success: Get the number of failed FDB insert: %d.\n" % (OpEN.uint32_tp_value(value))
182 print "Failed to get the number of failed FDB insert. (Result = %d)\n" % (result)
184 ''' Testing of retrieving the max limit of MAC entries set in the hardware '''
185 result = OpEN.openapiFdbMacMaxHwLimitGet(self.clientHandle, value)
186 if OpEN.OPEN_E_NONE == result:
187 print "Success: Get the max limit of MAC entries set in the hardware: %d.\n" % (OpEN.uint32_tp_value(value))
189 print "Failed to get the max limit of MAC entries set in the hardware. (Result = %d)\n" % (result)
191 ''' Testing of retrieving the value of dynamic entries in the L2FDB for a specific interface '''
192 result = OpEN.openapiFdbIntfDynamicEntriesGet(self.clientHandle, OpEN.uint32_tp_value(fdbIfNum), value)
193 if OpEN.OPEN_E_NONE == result:
194 print "Success: Get the value of dynamic entries in the L2FDB for a %d interface: %d.\n" % (OpEN.uint32_tp_value(fdbIfNum), OpEN.uint32_tp_value(value))
196 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)
198 ''' Testing of retrieving the value of dynamic entries in the L2FDB for a specific VLAN '''
199 result = OpEN.openapiFdbVlanDynamicEntriesGet(self.clientHandle, OpEN.uint32_tp_value(vlanId), value)
200 if OpEN.OPEN_E_NONE == result:
201 print "Success: Get the value of dynamic entries in the L2FDB for a VLAN %d: %d.\n" % (OpEN.uint32_tp_value(vlanId), OpEN.uint32_tp_value(value))
203 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)
205 ''' Testing of retrieving the value of internal entries in the L2FDB for a specific interface '''
206 result = OpEN.openapiFdbIntfInternalEntriesGet(self.clientHandle, OpEN.uint32_tp_value(fdbIfNum), value)
207 if OpEN.OPEN_E_NONE == result:
208 print "Success: Get the value of internal entries in the L2FDB for a %d interface: %d.\n" % (OpEN.uint32_tp_value(fdbIfNum), OpEN.uint32_tp_value(value))
210 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)
212 ''' Testing of retrieving the value of internal entries in the L2FDB for a specific VLAN '''
213 result = OpEN.openapiFdbVlanInternalEntriesGet(self.clientHandle, OpEN.uint32_tp_value(vlanId), value)
214 if OpEN.OPEN_E_NONE == result:
215 print "Success: Get the value of internal entries in the L2FDB for a VLAN %d: %d.\n" % (OpEN.uint32_tp_value(vlanId), OpEN.uint32_tp_value(value))
217 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)
219 ''' Testing of flushing all entries in fdb learned on the specified interface '''
220 result = OpEN.openapiFdbFlushByPort(self.clientHandle, OpEN.uint32_tp_value(fdbIfNum))
221 if OpEN.OPEN_E_NONE == result:
222 print "Success: Flushed all entries in fdb learned on the interface %d.\n" % (OpEN.uint32_tp_value(fdbIfNum))
224 print "Failed to flush all entries in fdb learned on the interface %d. (Result = %d)\n" % (OpEN.uint32_tp_value(fdbIfNum), result)
226 ''' Testing of flushing all entries in fdb learned on the specified VLAN '''
227 result = OpEN.openapiFdbFlushByVlan(self.clientHandle, OpEN.uint32_tp_value(vlanId))
228 if OpEN.OPEN_E_NONE == result:
229 print "Success: Flushed all entries in fdb learned on the VLAN %d.\n" % (OpEN.uint32_tp_value(vlanId))
231 print "Failed to flush all entries in fdb learned on the VLAN %d. (Result = %d)\n" % (OpEN.uint32_tp_value(vlanId), result)
233 ''' Testing of flushing all entries in fdb learned on the specified MAC '''
234 result = OpEN.openapiFdbFlushByMac(self.clientHandle, mac)
235 if OpEN.OPEN_E_NONE == result:
236 print "Success: Flushed all entries in fdb learned on the MAC.\n"
238 print "Failed to flush all entries in fdb learned on the MAC. (Result = %d)\n" % (result)
240 ''' Testing of flushing all learned entries from the L2FDB '''
241 result = OpEN.openapiFdbFlush(self.clientHandle)
242 if OpEN.OPEN_E_NONE == result:
243 print "Success: Flushed all learned entries from the L2FDB.\n"
245 print "Failed to flush all learned entries from the L2FDB. (Result = %d)\n" % (result)
251 ret = open_.connect(
"fdb_example")
252 if ret == OpEN.OPEN_E_NONE:
253 open_.getNetworkOSVersion()
254 open_.getAPIVersion()
255 client = open_.get_client()
257 fdbExample = FdbExample(client)
262 print "Unable to connect"
265 if __name__ ==
'__main__': main()