Add PacketTrace parser

Change-Id: I07734febd35b162f7813bed8502441f07d158631
This commit is contained in:
Volodymyr Samotiy 2016-06-20 18:00:54 +03:00
parent 31dbf8e3a1
commit db51326ec1
10 changed files with 2729 additions and 0 deletions

View File

View File

@ -0,0 +1,114 @@
# (C) Copyright Broadcom Corporation 2016
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class ECMPMember():
def __init__(self, id, ip, port):
self._id = id
self._ip = ip
self._port = port
def getId(self):
return self._id
def getIP(self):
return self._ip
def getPort(self):
return self._port
class ECMPLinkResolutionEntry():
def __init__(self):
self.ecmp_group_id = None
self.ecmp_members = []
self.ecmp_dst_member = None
self.ecmp_dst_port = None
self.ecmp_next_hop_ip = None
def getECMPGroupID(self):
return self.ecmp_group_id
def getECMPMembers(self):
return self.ecmp_members
def getECMPDstMember(self):
return self.ecmp_dst_member
def getECMPDstPort(self):
return self.ecmp_dst_port
def getECMPNextHopIP(self):
return self.ecmp_next_hop_ip
def parse(self, data):
ret = True
if "ecmp-group-id" in data:
self.ecmp_group_id = data["ecmp-group-id"]
else:
ret = False
if "ecmp-members" in data and type(data["ecmp-members"]) == list:
for x in data["ecmp-members"]:
val = ECMPMember(x[0], x[1], x[2])
self.ecmp_members.append(val)
else:
ret = False
if "ecmp-dst-member" in data:
self.ecmp_dst_member = data["ecmp-dst-member"]
else:
ret = False
if "ecmp-dst-port" in data:
self.ecmp_dst_port = data["ecmp-dst-port"]
else:
ret = False
if "ecmp-next-hop-ip" in data:
self.ecmp_next_hop_ip = data["ecmp-next-hop-ip"]
else:
ret = False
return ret
class ECMPLinkResolution():
def __init__(self):
self.__table = []
def __init__(self):
self.__table = []
def __iter__(self):
self.__n = 0
return self
def next(self):
if self.__n >= len(self.__table):
raise StopIteration
else:
n = self.__n
self.__n += 1
return self.__table[n]
def parse(self, data):
#print "ECMPLinkResolution {}".format(data)
#print type(data)
ret = True
for x in data:
val = ECMPLinkResolutionEntry()
ret = val.parse(x)
if not ret:
break
else:
self.__table.append(val)
return ret
def __repr__(self):
return "ecmp-link-resolution"

View File

@ -0,0 +1,47 @@
# (C) Copyright Broadcom Corporation 2016
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class LAGLinkResolution():
def __init__(self):
self.lag_id = None
self.lag_members = None
self.dst_lag_member = None
def getLAGID(self):
return self.lag_id
def getLAGMembers(self):
return self.lag_members
def getDstLAGMember(self):
return self.dst_lag_member
def __repr__(self):
return "lag-link-resolution"
def parse(self, data):
ret = True
if "lag-id" in data:
self.lag_id = data["lag-id"]
else:
ret = False
if "lag-members" in data and type(data["lag-members"]) == list:
self.lag_members = data["lag-members"]
else:
ret = False
if "dst-lag-member" in data:
self.dst_lag_member = data["dst-lag-member"]
else:
ret = False
return ret

View File

@ -0,0 +1,79 @@
# (C) Copyright Broadcom Corporation 2016
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class PacketTraceDropCounterReportEntry():
def __init__(self):
self._realm = None
self._port = None
self._count = None
def getRealm(self):
return self._realm
def getPort(self):
return self._port
def getCount(self):
return self._count
class PacketTraceDropCounterReport():
def __init__(self):
self.__table = []
def __iter__(self):
self.__n = 0
return self
def next(self):
if self.__n >= len(self.__table):
raise StopIteration
else:
n = self.__n
self.__n += 1
return self.__table[n]
def __repr__(self):
return "packet-trace-drop-counter-report"
def parse(self, data):
ret = True
while True:
if not "realm" in data:
ret = False
break
else :
realm = data["realm"]
if not "data" in data:
ret = False
break
clean = True
for y in data["data"]:
val = PacketTraceDropCounterReportEntry()
val._realm = realm
if not "port" in y:
clean = False
break
val._port = y["port"]
if not "count" in y:
clean = False
break
val._count = y["count"]
self.__table.append(val)
if not clean:
ret = False
break
return ret

View File

@ -0,0 +1,78 @@
# (C) Copyright Broadcom Corporation 2016
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class PacketTraceDropReason():
def __init__(self):
self._reason = None
self._portList = None
self._sendDroppedPacket = None
self._traceProfile = None
self._packetCount = None
self._packetThreshold = None
def getReason(self):
return self._reason
def getPortList(self):
return self._portList
def getSendDroppedPacket(self):
return self._sendDroppedPacket
def getTraceProfile(self):
return self._traceProfile
def getPacketCount(self):
return self._packetCount
def getPacketThreshold(self):
return self._packetThreshold
def __repr__(self):
return "packet-trace-drop-reason"
def parse(self, data):
ret = True
while True:
if not "reason" in data:
ret = False
break
self._reason = data["reason"]
if not "port-list" in data:
ret = False
break
self._portList = data["port-list"]
if not "send-dropped-packet" in data:
ret = False
break
self._sendDroppedPacket = data["send-dropped-packet"] == 1
if not "trace-profile" in data:
ret = False
break
self._traceProfile = data["trace-profile"] == 1
if not "packet-count" in data:
ret = False
break
self._packetCount = int(data["packet-count"])
if not "packet-threshold" in data:
ret = False
break
self._packetThreshold = int(data["packet-threshold"])
break
return ret

View File

@ -0,0 +1,30 @@
# (C) Copyright Broadcom Corporation 2016
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class PacketTraceDropReasons():
def __init__(self):
self._reasons = []
def getReasons(self):
return self._reasons
def __repr__(self):
return "packet-trace-drop-reasons"
def parse(self, data):
ret = True
self._reasons = data
return ret

View File

@ -0,0 +1,46 @@
# (C) Copyright Broadcom Corporation 2016
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import ecmplinkresolution
class PacketTraceECMPResolution():
def __init__(self):
self._port = None
self._ecmplinkresolution = ecmplinkresolution.ECMPLinkResolution()
def getPort(self):
return self._port
def getECMPLINKResolution(self):
return self._ecmplinkresolution
def __repr__(self):
return "packet-trace-ecmp-resolution"
def parse(self, data, port=None):
ret = True
while True:
if "ecmp-link-resolution" not in data:
ret = False
break
if port != None:
self._port = port
else:
ret = False
break
ret = self._ecmplinkresolution.parse(data["ecmp-link-resolution"])
break
return ret

View File

@ -0,0 +1,37 @@
# (C) Copyright Broadcom Corporation 2016
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import laglinkresolution
class PacketTraceLAGResolution():
def __init__(self):
self._laglinkresolution = laglinkresolution.LAGLinkResolution()
def getPort(self):
return self._port
def getLAGLINKResolution(self):
return self._laglinkresolution
def parse(self, data, port=None):
if port == None:
ret = False
else:
self._port = port
if "lag-link-resolution" in data:
ret = self._laglinkresolution.parse(data["lag-link-resolution"])
else:
ret = False
return ret

View File

@ -0,0 +1,93 @@
# (C) Copyright Broadcom Corporation 2016
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import laglinkresolution
import ecmplinkresolution
class PacketTraceProfileEntry():
def __init__(self):
self._port = None
self._realm = None
self._laglinkresolution = None
self._ecmplinkresolution = None
def getRealm(self):
return self._realm
def getPort(self):
return self._port
def getLAGLINKResolution(self):
return self._laglinkresolution
def getECMPLINKResolution(self):
return self._ecmplinkresolution
class PacketTraceProfile():
def __init__(self):
self.__table = []
def __init__(self):
self.__table = []
def __iter__(self):
self.__n = 0
return self
def next(self):
if self.__n >= len(self.__table):
raise StopIteration
else:
n = self.__n
self.__n += 1
return self.__table[n]
def __repr__(self):
return "packet-trace-profile"
def parse(self, data, port=None):
ret = True
for x in data:
val = PacketTraceProfileEntry()
if port != None:
val._port = port
else:
ret = False
break
if not "realm" in x:
ret = False
break
else:
val._realm = x["realm"]
if not "data" in x:
ret = False
break
if x["realm"] == "lag-link-resolution":
val._laglinkresolution = laglinkresolution.LAGLinkResolution()
if val._laglinkresolution.parse(x["data"]):
self.__table.append(val)
else:
ret = False
break
elif x["realm"] == "ecmp-link-resolution":
val._ecmplinkresolution = ecmplinkresolution.ECMPLinkResolution()
if val._ecmplinkresolution.parse(x["data"]):
self.__table.append(val)
else:
ret = False
break
else:
ret = False
break
return ret

File diff suppressed because it is too large Load Diff