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 | |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 23 | from protos.voltha_pb2 import ID, VolthaLogicalLayerStub, FlowTableUpdate, \ |
| 24 | GroupTableUpdate |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 25 | |
| 26 | |
| 27 | class GrpcClient(object): |
| 28 | |
| 29 | def __init__(self, channel, device_id_map): |
| 30 | self.channel = channel |
| 31 | self.device_id_map = device_id_map |
| 32 | self.logical_stub = VolthaLogicalLayerStub(channel) |
| 33 | |
| 34 | @inlineCallbacks |
| 35 | def get_port_list(self, datapath_id): |
| 36 | device_id = self.device_id_map[datapath_id] |
| 37 | req = ID(id=device_id) |
| 38 | res = yield threads.deferToThread( |
| 39 | self.logical_stub.ListLogicalDevicePorts, req) |
| 40 | returnValue(res.items) |
| 41 | |
| 42 | @inlineCallbacks |
| 43 | def get_device_info(self, datapath_id): |
| 44 | device_id = self.device_id_map[datapath_id] |
| 45 | req = ID(id=device_id) |
| 46 | res = yield threads.deferToThread( |
| 47 | self.logical_stub.GetLogicalDevice, req) |
| 48 | returnValue(res) |
| 49 | |
| 50 | @inlineCallbacks |
| 51 | def update_flow_table(self, datapath_id, flow_mod): |
| 52 | device_id = self.device_id_map[datapath_id] |
| 53 | req = FlowTableUpdate( |
| 54 | id=device_id, |
| 55 | flow_mod=flow_mod |
| 56 | ) |
| 57 | res = yield threads.deferToThread( |
| 58 | self.logical_stub.UpdateFlowTable, req) |
| 59 | returnValue(res) |
| 60 | |
| 61 | @inlineCallbacks |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 62 | def update_group_table(self, datapath_id, group_mod): |
| 63 | device_id = self.device_id_map[datapath_id] |
| 64 | req = GroupTableUpdate( |
| 65 | id=device_id, |
| 66 | group_mod=group_mod |
| 67 | ) |
| 68 | res = yield threads.deferToThread( |
| 69 | self.logical_stub.UpdateGroupTable, req) |
| 70 | returnValue(res) |
| 71 | |
| 72 | @inlineCallbacks |
Zsolt Haraszti | 023ea7c | 2016-10-16 19:30:34 -0700 | [diff] [blame] | 73 | def list_flows(self, datapath_id): |
| 74 | device_id = self.device_id_map[datapath_id] |
| 75 | req = ID(id=device_id) |
| 76 | res = yield threads.deferToThread( |
| 77 | self.logical_stub.ListDeviceFlows, req) |
| 78 | returnValue(res.items) |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 79 | |
| 80 | @inlineCallbacks |
Zsolt Haraszti | 9125b1a | 2016-10-24 22:54:33 -0700 | [diff] [blame^] | 81 | def list_groups(self, datapath_id): |
Zsolt Haraszti | 8a77438 | 2016-10-24 18:25:54 -0700 | [diff] [blame] | 82 | device_id = self.device_id_map[datapath_id] |
| 83 | req = ID(id=device_id) |
| 84 | res = yield threads.deferToThread( |
| 85 | self.logical_stub.ListDeviceFlowGroups, req) |
| 86 | returnValue(res.items) |