VOL-955 Handling of port stats in OFAgent
Change-Id: Ib73bcb539dc573e577e5c9d736e425256c6a8972
diff --git a/ofagent/converter.py b/ofagent/converter.py
index 06b31ba..192a65a 100644
--- a/ofagent/converter.py
+++ b/ofagent/converter.py
@@ -61,6 +61,10 @@
desc=ofp_port_to_loxi_port_desc(pb.desc)
)
+def ofp_port_stats_to_loxi_port_stats(pb):
+ kw = pb2dict(pb)
+ return of13.port_stats_entry(**kw)
+
def make_loxi_field(oxm_field):
assert oxm_field['oxm_class'] == pb2.OFPXMC_OPENFLOW_BASIC
ofb_field = oxm_field['ofb_field']
@@ -225,7 +229,8 @@
'ofp_group_desc': ofp_group_desc_to_loxi_group_desc,
'ofp_bucket_counter': ofp_bucket_counter_to_loxy_bucket_counter,
'ofp_bucket': ofp_bucket_to_loxi_bucket,
- 'ofp_action': make_loxi_action
+ 'ofp_action': make_loxi_action,
+ 'ofp_port_stats': ofp_port_stats_to_loxi_port_stats
}
diff --git a/ofagent/grpc_client.py b/ofagent/grpc_client.py
index 6d01015..af3ffe4 100644
--- a/ofagent/grpc_client.py
+++ b/ofagent/grpc_client.py
@@ -222,3 +222,10 @@
res = yield threads.deferToThread(
self.local_stub.ListLogicalDeviceFlowGroups, req)
returnValue(res.items)
+
+ @inlineCallbacks
+ def list_ports(self, device_id):
+ req = ID(id=device_id)
+ res = yield threads.deferToThread(
+ self.local_stub.ListLogicalDevicePorts, req)
+ returnValue(res.items)
\ No newline at end of file
diff --git a/ofagent/of_protocol_handler.py b/ofagent/of_protocol_handler.py
index d6aa92d..8d09461 100644
--- a/ofagent/of_protocol_handler.py
+++ b/ofagent/of_protocol_handler.py
@@ -249,10 +249,16 @@
def handle_meter_features_request(self, req):
self.cxn.send(ofp.message.bad_request_error_msg())
+ @inlineCallbacks
def handle_port_stats_request(self, req):
- port_stats = [] # see https://jira.opencord.org/browse/CORD-825
- self.cxn.send(ofp.message.port_stats_reply(
- xid=req.xid,entries=port_stats))
+ try:
+ ports = yield self.rpc.list_ports(self.device_id)
+ port_stats = [to_loxi(p.ofp_port_stats) for p in ports]
+ of_message = ofp.message.port_stats_reply(
+ xid=req.xid,entries=port_stats)
+ self.cxn.send(of_message)
+ except:
+ log.exception('failed-port_stats-request', req=req)
@inlineCallbacks
def handle_port_desc_request(self, req):