Add packet in/out counters to ofagent
Change-Id: Ib349b36cc330644557ad22cd98cc3efce235b6b2
diff --git a/ofagent/grpc_client.py b/ofagent/grpc_client.py
index 155f18d..018baa9 100644
--- a/ofagent/grpc_client.py
+++ b/ofagent/grpc_client.py
@@ -51,6 +51,9 @@
self.packet_in_queue = DeferredQueue() # queue to receive PacketIn
self.change_event_queue = DeferredQueue() # queue change events
+ self.count_pkt_in = 0
+ self.count_pkt_out = 0
+
def start(self):
self.log.debug('starting', grpc_timeout=self.grpc_timeout)
self.start_packet_out_stream()
@@ -76,6 +79,8 @@
if self.stopped:
return
else:
+ self.count_pkt_out += 1
+ self.log.debug('counters grpc_client OUT - {}'.format(self.count_pkt_out))
yield packet
def stream_packets_out():
@@ -101,6 +106,8 @@
self.log.debug('enqued-packet-in',
packet_in=packet_in,
queue_len=len(self.packet_in_queue.pending))
+ self.count_pkt_in += 1
+ self.log.debug('counters grpc_client IN - {}'.format(self.count_pkt_in))
except _Rendezvous, e:
self.log.error('grpc-exception', status=e.code())
if e.code() == StatusCode.UNAVAILABLE:
diff --git a/ofagent/of_protocol_handler.py b/ofagent/of_protocol_handler.py
index 7deee6d..ec11d0a 100644
--- a/ofagent/of_protocol_handler.py
+++ b/ofagent/of_protocol_handler.py
@@ -50,6 +50,9 @@
self.rpc = rpc
self.role = None
+ self.count_pkt_in = 0
+ self.count_pkt_out = 0
+
@inlineCallbacks
def start(self):
"""A new call is made after a fresh reconnect"""
@@ -190,6 +193,8 @@
def handle_packet_out_request(self, req):
if self.role == ofp.OFPCR_ROLE_MASTER or self.role == ofp.OFPCR_ROLE_EQUAL:
self.rpc.send_packet_out(self.device_id, to_grpc(req))
+ self.count_pkt_out += 1
+ log.debug('counters of_protocol_handler OUT - {}'.format(self.count_pkt_out))
elif self.role == ofp.OFPCR_ROLE_SLAVE:
self.cxn.send(ofp.message.bad_request_error_msg(code=ofp.OFPBRC_IS_SLAVE))
@@ -344,6 +349,8 @@
if self.role == ofp.OFPCR_ROLE_MASTER or self.role == ofp.OFPCR_ROLE_EQUAL:
log.info('sending-packet-in', ofp_packet_in=ofp_packet_in)
self.cxn.send(to_loxi(ofp_packet_in))
+ self.count_pkt_in += 1
+ log.debug('counters of_protocol_handler IN - {}'.format(self.count_pkt_in))
def forward_port_status(self, ofp_port_status):
self.cxn.send(to_loxi(ofp_port_status))