Remove the workaround for endianness in VPP; Remove the --disable-lcp flag. Catch connect exceptions for VPPStats and VPP API
This commit is contained in:
@ -33,8 +33,12 @@ class Agent(object):
|
|||||||
|
|
||||||
def _update(self):
|
def _update(self):
|
||||||
ds = self.update()
|
ds = self.update()
|
||||||
|
if not ds:
|
||||||
|
return False
|
||||||
|
|
||||||
self._net.update(ds._data)
|
self._net.update(ds._data)
|
||||||
self._lastupdate = time.time()
|
self._lastupdate = time.time()
|
||||||
|
return True
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.logger.info('Calling setup')
|
self.logger.info('Calling setup')
|
||||||
@ -51,7 +55,9 @@ class Agent(object):
|
|||||||
self._net.start(self._oid_list)
|
self._net.start(self._oid_list)
|
||||||
|
|
||||||
if time.time() - self._lastupdate > self._update_period:
|
if time.time() - self._lastupdate > self._update_period:
|
||||||
self._update()
|
if not self._update():
|
||||||
|
self.logger.warning('Update failed, last successful update was %s' % self._lastupdate)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._net.run()
|
self._net.run()
|
||||||
|
@ -47,13 +47,19 @@ class MyAgent(agentx.Agent):
|
|||||||
except:
|
except:
|
||||||
self.logger.error("Couldn't read config from %s" % args.config)
|
self.logger.error("Couldn't read config from %s" % args.config)
|
||||||
|
|
||||||
self.logger.info("Connecting to VPP Stats Segment")
|
try:
|
||||||
vppstat = VPPStats(socketname='/run/vpp/stats.sock', timeout=2)
|
self.logger.info("Connecting to VPP Stats Segment")
|
||||||
vppstat.connect()
|
vppstat = VPPStats(socketname='/run/vpp/stats.sock', timeout=2)
|
||||||
|
vppstat.connect()
|
||||||
|
except:
|
||||||
|
self.logger.error("Could not connect to VPPStats segment")
|
||||||
|
return False
|
||||||
|
|
||||||
vpp = VPPApi(clientname='vpp-snmp-agent')
|
try:
|
||||||
if not vpp.connect():
|
vpp = VPPApi(clientname='vpp-snmp-agent')
|
||||||
logger.error("Can't connect to VPP API, bailing")
|
vpp.connect()
|
||||||
|
except:
|
||||||
|
self.logger.error("Could not connect to VPP API")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.register('1.3.6.1.2.1.2.2.1')
|
self.register('1.3.6.1.2.1.2.2.1')
|
||||||
@ -64,15 +70,23 @@ class MyAgent(agentx.Agent):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
global vppstat, vpp, args
|
global vppstat, vpp, args
|
||||||
vppstat.connect()
|
|
||||||
vpp.connect()
|
try:
|
||||||
|
vppstat.connect()
|
||||||
|
except:
|
||||||
|
self.logger.error("Could not connect to VPPStats segment")
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
vpp.connect()
|
||||||
|
except:
|
||||||
|
self.logger.error("Could not connect to VPP API")
|
||||||
|
return False
|
||||||
|
|
||||||
ds = agentx.DataSet()
|
ds = agentx.DataSet()
|
||||||
ifaces = vpp.get_ifaces()
|
ifaces = vpp.get_ifaces()
|
||||||
if args.disable_lcp:
|
lcp = vpp.get_lcp()
|
||||||
lcp = []
|
|
||||||
else:
|
|
||||||
lcp = vpp.get_lcp()
|
|
||||||
num_ifaces=len(ifaces)
|
num_ifaces=len(ifaces)
|
||||||
num_vppstat=len(vppstat['/if/names'])
|
num_vppstat=len(vppstat['/if/names'])
|
||||||
num_lcp=len(lcp)
|
num_lcp=len(lcp)
|
||||||
@ -80,7 +94,8 @@ class MyAgent(agentx.Agent):
|
|||||||
self.logger.debug("Retrieved Interfaces: vppapi=%d vppstats=%d lcp=%d" % (num_ifaces, num_vppstat, num_lcp))
|
self.logger.debug("Retrieved Interfaces: vppapi=%d vppstats=%d lcp=%d" % (num_ifaces, num_vppstat, num_lcp))
|
||||||
|
|
||||||
if num_ifaces != num_vppstat:
|
if num_ifaces != num_vppstat:
|
||||||
self.logger.warning("Interfaces count mismatch: vppapi=%d vppstats=%d" % (num_ifaces, num_vppstat))
|
self.logger.error("Interfaces count mismatch: vppapi=%d vppstats=%d" % (num_ifaces, num_vppstat))
|
||||||
|
return False
|
||||||
|
|
||||||
for i in range(len(vppstat['/if/names'])):
|
for i in range(len(vppstat['/if/names'])):
|
||||||
ifname = vppstat['/if/names'][i]
|
ifname = vppstat['/if/names'][i]
|
||||||
@ -91,7 +106,7 @@ class MyAgent(agentx.Agent):
|
|||||||
ifName=ifname
|
ifName=ifname
|
||||||
ifAlias=None
|
ifAlias=None
|
||||||
try:
|
try:
|
||||||
if (not args.disable_lcp) and self.config and ifname.startswith('tap'):
|
if self.config and ifname.startswith('tap'):
|
||||||
host_sw_if_index = ifaces[ifname].sw_if_index
|
host_sw_if_index = ifaces[ifname].sw_if_index
|
||||||
lip = get_lcp_by_host_sw_if_index(lcp, host_sw_if_index)
|
lip = get_lcp_by_host_sw_if_index(lcp, host_sw_if_index)
|
||||||
if lip:
|
if lip:
|
||||||
@ -215,7 +230,6 @@ def main():
|
|||||||
global args
|
global args
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
|
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
|
||||||
parser.add_argument('-disable-lcp', dest='disable_lcp', action='store_true', help="""Disable Linux Control Plane integration""")
|
|
||||||
parser.add_argument('-a', dest='address', default="localhost:705", type=str, help="""Location of the SNMPd agent (unix-path or host:port), default localhost:705""")
|
parser.add_argument('-a', dest='address', default="localhost:705", type=str, help="""Location of the SNMPd agent (unix-path or host:port), default localhost:705""")
|
||||||
parser.add_argument('-p', dest='period', type=int, default=30, help="""Period to poll VPP, default 30 (seconds)""")
|
parser.add_argument('-p', dest='period', type=int, default=30, help="""Period to poll VPP, default 30 (seconds)""")
|
||||||
parser.add_argument('-c', dest='config', type=str, help="""Optional YAML configuration file, default empty""")
|
parser.add_argument('-c', dest='config', type=str, help="""Optional YAML configuration file, default empty""")
|
||||||
|
25
vppapi.py
25
vppapi.py
@ -88,7 +88,6 @@ class VPPApi():
|
|||||||
if not self.connected:
|
if not self.connected:
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lcp_list = self.vpp.api.lcp_itf_pair_get()
|
lcp_list = self.vpp.api.lcp_itf_pair_get()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -97,30 +96,10 @@ class VPPApi():
|
|||||||
self.connected = False
|
self.connected = False
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
if not lcp_list or not lcp_list[1]:
|
if not lcp_list:
|
||||||
logger.error("Can't get LCP list")
|
logger.error("Can't get LCP list")
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
## TODO(pim) - fix upstream, the indexes are in network byte order and
|
|
||||||
## the message is messed up. This hack allows for both little endian and
|
|
||||||
## big endian responses, and will be removed once VPP's LinuxCP is updated
|
|
||||||
## and rolled out to AS8298
|
|
||||||
for lcp in lcp_list[1]:
|
for lcp in lcp_list[1]:
|
||||||
if lcp.phy_sw_if_index > 65535 or lcp.host_sw_if_index > 65535 or lcp.vif_index > 65535:
|
ret[lcp.host_if_name] = lcp
|
||||||
i = {
|
|
||||||
'phy_sw_if_index': socket.ntohl(lcp.phy_sw_if_index),
|
|
||||||
'host_sw_if_index': socket.ntohl(lcp.host_sw_if_index),
|
|
||||||
'vif_index': socket.ntohl(lcp.vif_index),
|
|
||||||
'host_if_name': lcp.host_if_name,
|
|
||||||
'namespace': lcp.namespace
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
i = {
|
|
||||||
'phy_sw_if_index': lcp.phy_sw_if_index,
|
|
||||||
'host_sw_if_index': lcp.host_sw_if_index,
|
|
||||||
'vif_index': lcp.vif_index,
|
|
||||||
'host_if_name': lcp.host_if_name,
|
|
||||||
'namespace': lcp.namespace
|
|
||||||
}
|
|
||||||
ret[lcp.host_if_name] = i
|
|
||||||
return ret
|
return ret
|
||||||
|
Reference in New Issue
Block a user