Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2016 the original author or authors. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
| 17 | """ |
| 18 | The gRPC client layer for the OpenFlow agent |
| 19 | """ |
| 20 | from twisted.internet import threads |
| 21 | from twisted.internet.defer import inlineCallbacks, returnValue |
| 22 | |
| 23 | from protos.voltha_pb2 import ID, VolthaLogicalLayerStub, FlowTableUpdate |
| 24 | |
| 25 | |
| 26 | class GrpcClient(object): |
| 27 | |
| 28 | def __init__(self, channel, device_id_map): |
| 29 | self.channel = channel |
| 30 | self.device_id_map = device_id_map |
| 31 | self.logical_stub = VolthaLogicalLayerStub(channel) |
| 32 | |
| 33 | @inlineCallbacks |
| 34 | def get_port_list(self, datapath_id): |
| 35 | device_id = self.device_id_map[datapath_id] |
| 36 | req = ID(id=device_id) |
| 37 | res = yield threads.deferToThread( |
| 38 | self.logical_stub.ListLogicalDevicePorts, req) |
| 39 | returnValue(res.items) |
| 40 | |
| 41 | @inlineCallbacks |
| 42 | def get_device_info(self, datapath_id): |
| 43 | device_id = self.device_id_map[datapath_id] |
| 44 | req = ID(id=device_id) |
| 45 | res = yield threads.deferToThread( |
| 46 | self.logical_stub.GetLogicalDevice, req) |
| 47 | returnValue(res) |
| 48 | |
| 49 | @inlineCallbacks |
| 50 | def update_flow_table(self, datapath_id, flow_mod): |
| 51 | device_id = self.device_id_map[datapath_id] |
| 52 | req = FlowTableUpdate( |
| 53 | id=device_id, |
| 54 | flow_mod=flow_mod |
| 55 | ) |
| 56 | res = yield threads.deferToThread( |
| 57 | self.logical_stub.UpdateFlowTable, req) |
| 58 | returnValue(res) |
| 59 | |
| 60 | @inlineCallbacks |
| 61 | def list_flows(self, datapath_id): |
| 62 | device_id = self.device_id_map[datapath_id] |
| 63 | req = ID(id=device_id) |
| 64 | res = yield threads.deferToThread( |
| 65 | self.logical_stub.ListDeviceFlows, req) |
| 66 | returnValue(res.items) |