Shad Ansari | 0d83c94 | 2017-07-05 21:30:38 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2017 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 | |
Rajeswara Rao | b2b369a | 2017-09-08 11:44:15 +0530 | [diff] [blame] | 17 | from twisted.internet.defer import inlineCallbacks, returnValue |
Shad Ansari | 1831fcc | 2017-08-11 16:41:44 -0700 | [diff] [blame] | 18 | from voltha.adapters.asfvolt16_olt.protos import bal_pb2, \ |
rshetty | e4bd2ed | 2017-07-19 16:38:11 +0530 | [diff] [blame] | 19 | bal_model_types_pb2, bal_model_ids_pb2 |
Shad Ansari | 0d83c94 | 2017-07-05 21:30:38 -0700 | [diff] [blame] | 20 | from voltha.adapters.asfvolt16_olt.grpc_client import GrpcClient |
rshetty | 1cc7398 | 2017-09-02 03:31:12 +0530 | [diff] [blame] | 21 | from common.utils.nethelpers import get_my_primary_local_ipv4 |
Rajeswara Rao | 8af144c | 2017-08-18 14:01:06 +0530 | [diff] [blame] | 22 | import os |
Shad Ansari | 0d83c94 | 2017-07-05 21:30:38 -0700 | [diff] [blame] | 23 | |
Rajeswara Rao | 8af144c | 2017-08-18 14:01:06 +0530 | [diff] [blame] | 24 | """ |
| 25 | ASFVOLT Adapter port is 60001 |
| 26 | """ |
| 27 | ADAPTER_PORT = 60001 |
rshetty | c26a3c3 | 2017-07-27 11:06:38 +0530 | [diff] [blame] | 28 | |
rshetty | 1cc7398 | 2017-09-02 03:31:12 +0530 | [diff] [blame] | 29 | |
Shad Ansari | 0d83c94 | 2017-07-05 21:30:38 -0700 | [diff] [blame] | 30 | class Bal(object): |
rshetty | e4bd2ed | 2017-07-19 16:38:11 +0530 | [diff] [blame] | 31 | def __init__(self, olt, log): |
Shad Ansari | 0d83c94 | 2017-07-05 21:30:38 -0700 | [diff] [blame] | 32 | self.log = log |
| 33 | self.grpc_client = GrpcClient(self.log) |
rshetty | e4bd2ed | 2017-07-19 16:38:11 +0530 | [diff] [blame] | 34 | self.stub = None |
| 35 | self.device_id = None |
| 36 | self.olt = olt |
Shad Ansari | 0d83c94 | 2017-07-05 21:30:38 -0700 | [diff] [blame] | 37 | |
| 38 | @inlineCallbacks |
rshetty | e4bd2ed | 2017-07-19 16:38:11 +0530 | [diff] [blame] | 39 | def connect_olt(self, host_and_port, device_id): |
rshetty | e4bd2ed | 2017-07-19 16:38:11 +0530 | [diff] [blame] | 40 | self.device_id = device_id |
Shad Ansari | 0d83c94 | 2017-07-05 21:30:38 -0700 | [diff] [blame] | 41 | self.grpc_client.connect(host_and_port) |
| 42 | self.stub = bal_pb2.BalStub(self.grpc_client.channel) |
| 43 | init = bal_pb2.BalInit() |
Rajeswara Rao | 8af144c | 2017-08-18 14:01:06 +0530 | [diff] [blame] | 44 | try: |
| 45 | os.environ["SERVICE_HOST_IP"] |
| 46 | adapter_ip = os.environ["SERVICE_HOST_IP"] |
| 47 | except Exception as e: |
| 48 | self.log.info('voltha is running in non docker container environment') |
| 49 | adapter_ip = get_my_primary_local_ipv4() |
| 50 | |
| 51 | ip_port = [] |
| 52 | ip_port.append(str(adapter_ip)) |
rshetty | f4bf19e | 2017-09-19 01:28:27 +0530 | [diff] [blame] | 53 | #ip_port.append("192.168.140.34") |
Rajeswara Rao | 8af144c | 2017-08-18 14:01:06 +0530 | [diff] [blame] | 54 | ip_port.append(":") |
| 55 | ip_port.append(str(ADAPTER_PORT)) |
| 56 | init.voltha_adapter_ip_port ="".join(ip_port) |
| 57 | self.log.info('Adapter port Ip', init.voltha_adapter_ip_port) |
| 58 | |
Shad Ansari | 0d83c94 | 2017-07-05 21:30:38 -0700 | [diff] [blame] | 59 | ''' |
| 60 | TODO: Need to determine out what information |
| 61 | needs to be sent to the OLT at this stage. |
| 62 | ''' |
rshetty | 1cc7398 | 2017-09-02 03:31:12 +0530 | [diff] [blame] | 63 | self.log.info('connecting-olt', host_and_port=host_and_port, |
| 64 | init_details=init) |
Shad Ansari | 0d83c94 | 2017-07-05 21:30:38 -0700 | [diff] [blame] | 65 | yield self.stub.BalApiInit(init) |
| 66 | |
rshetty | e4bd2ed | 2017-07-19 16:38:11 +0530 | [diff] [blame] | 67 | def activate_olt(self): |
Shad Ansari | 0d83c94 | 2017-07-05 21:30:38 -0700 | [diff] [blame] | 68 | self.log.info('activating-olt') |
rshetty | e4bd2ed | 2017-07-19 16:38:11 +0530 | [diff] [blame] | 69 | self.set_access_terminal_admin_state(bal_model_types_pb2.BAL_STATE_UP) |
Shad Ansari | 0d83c94 | 2017-07-05 21:30:38 -0700 | [diff] [blame] | 70 | |
| 71 | @inlineCallbacks |
rshetty | e4bd2ed | 2017-07-19 16:38:11 +0530 | [diff] [blame] | 72 | def set_access_terminal_admin_state(self, admin_state): |
rshetty | e4bd2ed | 2017-07-19 16:38:11 +0530 | [diff] [blame] | 73 | obj = bal_pb2.BalCfg() |
| 74 | obj.device_id = self.device_id.encode('ascii', 'ignore') |
| 75 | obj.hdr.obj_type = bal_model_ids_pb2.BAL_OBJ_ID_ACCESS_TERMINAL |
| 76 | obj.cfg.key.access_term_id = 0 |
| 77 | obj.cfg.data.admin_state = admin_state |
rshetty | 1cc7398 | 2017-09-02 03:31:12 +0530 | [diff] [blame] | 78 | self.log.info('Activating-Access-Terminal-Device', |
| 79 | admin_state=admin_state, device_id=self.device_id, |
| 80 | access_terminal_details=obj) |
rshetty | c26a3c3 | 2017-07-27 11:06:38 +0530 | [diff] [blame] | 81 | yield self.stub.BalCfgSet(obj) |
rshetty | e4bd2ed | 2017-07-19 16:38:11 +0530 | [diff] [blame] | 82 | |
| 83 | @inlineCallbacks |
| 84 | def activate_pon_port(self, olt_no, pon_port): |
rshetty | e4bd2ed | 2017-07-19 16:38:11 +0530 | [diff] [blame] | 85 | try: |
| 86 | obj = bal_pb2.BalCfg() |
rshetty | c26a3c3 | 2017-07-27 11:06:38 +0530 | [diff] [blame] | 87 | # Fill Header details |
rshetty | e4bd2ed | 2017-07-19 16:38:11 +0530 | [diff] [blame] | 88 | obj.device_id = self.device_id.encode('ascii', 'ignore') |
| 89 | obj.hdr.obj_type = bal_model_ids_pb2.BAL_OBJ_ID_INTERFACE |
rshetty | c26a3c3 | 2017-07-27 11:06:38 +0530 | [diff] [blame] | 90 | # Fill Access Terminal Details |
rshetty | e4bd2ed | 2017-07-19 16:38:11 +0530 | [diff] [blame] | 91 | obj.interface.key.intf_id = pon_port |
| 92 | obj.interface.key.intf_type = bal_model_types_pb2.BAL_INTF_TYPE_PON |
| 93 | obj.interface.data.admin_state = bal_model_types_pb2.BAL_STATE_UP |
Suhas Rao | eba61c2 | 2017-08-10 11:42:32 -0700 | [diff] [blame] | 94 | obj.interface.data.transceiver_type = \ |
| 95 | bal_model_types_pb2.BAL_TRX_TYPE_XGPON_LTH_7226_PC |
rshetty | 1cc7398 | 2017-09-02 03:31:12 +0530 | [diff] [blame] | 96 | self.log.info('activating-pon-port-in-olt', |
| 97 | olt=olt_no, pon_port=pon_port, |
| 98 | pon_port_details=obj) |
rshetty | c26a3c3 | 2017-07-27 11:06:38 +0530 | [diff] [blame] | 99 | yield self.stub.BalCfgSet(obj) |
rshetty | e4bd2ed | 2017-07-19 16:38:11 +0530 | [diff] [blame] | 100 | except Exception as e: |
| 101 | self.log.info('activating-pon-port in olt-exception', exc=str(e)) |
| 102 | return |
Suhas Rao | c926fc1 | 2017-07-28 11:17:49 +0530 | [diff] [blame] | 103 | |
| 104 | @inlineCallbacks |
| 105 | def send_omci_request_message(self, proxy_address, msg): |
Suhas Rao | c926fc1 | 2017-07-28 11:17:49 +0530 | [diff] [blame] | 106 | try: |
| 107 | obj = bal_pb2.BalCfg() |
rshetty | c26a3c3 | 2017-07-27 11:06:38 +0530 | [diff] [blame] | 108 | # Fill Header details |
Suhas Rao | c926fc1 | 2017-07-28 11:17:49 +0530 | [diff] [blame] | 109 | obj.device_id = self.device_id.encode('ascii', 'ignore') |
| 110 | obj.hdr.obj_type = bal_model_ids_pb2.BAL_OBJ_ID_PACKET |
rshetty | c26a3c3 | 2017-07-27 11:06:38 +0530 | [diff] [blame] | 111 | # Fill packet Details |
| 112 | obj.packet.key.packet_send_dest.type = \ |
| 113 | bal_model_types_pb2.BAL_DEST_TYPE_ITU_OMCI_CHANNEL |
| 114 | obj.packet.key.packet_send_dest.itu_omci_channel.sub_term_id = \ |
Suhas Rao | eba61c2 | 2017-08-10 11:42:32 -0700 | [diff] [blame] | 115 | proxy_address.onu_id |
Rajeswara Rao | cd7d8dd | 2017-08-14 11:51:22 +0530 | [diff] [blame] | 116 | obj.packet.key.packet_send_dest.itu_omci_channel.intf_id = \ |
rshetty | c26a3c3 | 2017-07-27 11:06:38 +0530 | [diff] [blame] | 117 | proxy_address.channel_id |
Suhas Rao | c926fc1 | 2017-07-28 11:17:49 +0530 | [diff] [blame] | 118 | obj.packet.data.pkt = msg |
rshetty | 1cc7398 | 2017-09-02 03:31:12 +0530 | [diff] [blame] | 119 | self.log.info('send_omci_request_message', |
| 120 | proxy_address=proxy_address.channel_id, |
| 121 | omci_msg_details=obj) |
rshetty | c26a3c3 | 2017-07-27 11:06:38 +0530 | [diff] [blame] | 122 | yield self.stub.BalCfgSet(obj) |
Suhas Rao | c926fc1 | 2017-07-28 11:17:49 +0530 | [diff] [blame] | 123 | except Exception as e: |
| 124 | self.log.info('send-proxied_message-exception', exc=str(e)) |
| 125 | return |
rshetty | c26a3c3 | 2017-07-27 11:06:38 +0530 | [diff] [blame] | 126 | |
| 127 | @inlineCallbacks |
| 128 | def activate_onu(self, onu_info): |
rshetty | c26a3c3 | 2017-07-27 11:06:38 +0530 | [diff] [blame] | 129 | try: |
| 130 | obj = bal_pb2.BalCfg() |
| 131 | # Fill Header details |
| 132 | obj.device_id = self.device_id.encode('ascii', 'ignore') |
| 133 | obj.hdr.obj_type = bal_model_ids_pb2.BAL_OBJ_ID_SUBSCRIBER_TERMINAL |
| 134 | # Fill Access Terminal Details |
| 135 | obj.terminal.key.intf_id = onu_info['pon_id'] |
| 136 | obj.terminal.key.sub_term_id = onu_info['onu_id'] |
| 137 | obj.terminal.data.admin_state = bal_model_types_pb2.BAL_STATE_UP |
| 138 | obj.terminal.data.serial_number.vendor_id = onu_info['vendor'] |
| 139 | obj.terminal.data.serial_number.vendor_specific = \ |
| 140 | onu_info['vendor_specific'] |
| 141 | obj.terminal.data.registration_id = \ |
| 142 | '202020202020202020202020202020202020202020202020202020202020202020202020' |
rshetty | 1cc7398 | 2017-09-02 03:31:12 +0530 | [diff] [blame] | 143 | self.log.info('activating-ONU-in-olt', |
| 144 | onu_details=obj) |
rshetty | c26a3c3 | 2017-07-27 11:06:38 +0530 | [diff] [blame] | 145 | yield self.stub.BalCfgSet(obj) |
| 146 | except Exception as e: |
| 147 | self.log.info('activating-ONU-exception', |
| 148 | onu_info['onu_id'], exc=str(e)) |
| 149 | return |
Shad Ansari | 1831fcc | 2017-08-11 16:41:44 -0700 | [diff] [blame] | 150 | |
| 151 | @inlineCallbacks |
rshetty | f4bf19e | 2017-09-19 01:28:27 +0530 | [diff] [blame] | 152 | def packet_out(self, pkt, pkt_info): |
Shad Ansari | 1831fcc | 2017-08-11 16:41:44 -0700 | [diff] [blame] | 153 | obj = bal_pb2.BalCfg() |
rshetty | f4bf19e | 2017-09-19 01:28:27 +0530 | [diff] [blame] | 154 | obj.device_id = self.device_id.encode('ascii', 'ignore') |
| 155 | obj.hdr.obj_type = bal_model_ids_pb2.BAL_OBJ_ID_PACKET |
| 156 | if pkt_info['dest_type'] == 'onu': |
| 157 | # Set the destination ONU info |
| 158 | obj.packet.key.packet_send_dest.type = bal_model_types_pb2.BAL_DEST_TYPE_SUB_TERM |
| 159 | obj.packet.key.packet_send_dest.sub_term.sub_term_id = pkt_info['onu_id'] |
| 160 | # TODO: Need to provide correct values for sub_term_uni and int_id |
| 161 | #obj.packet.key.packet_send_dest.sub_term.sub_term_uni = egress_port |
| 162 | obj.packet.key.packet_send_dest.sub_term.intf_id = pkt_info['intf_id'] |
| 163 | obj.packet.data.intf_type = bal_model_types_pb2.BAL_INTF_TYPE_PON |
| 164 | elif pkt_info['dest_type'] == 'gem_port': |
| 165 | obj.packet.key.packet_send_dest.type = bal_model_types_pb2.BAL_DEST_TYPE_SVC_PORT |
| 166 | obj.packet.key.packet_send_dest.svc_port.svc_port_id = pkt_info['gem_port'] |
| 167 | obj.packet.key.packet_send_dest.svc_port.intf_id = pkt_info['intf_id'] |
| 168 | obj.packet.data.intf_type = bal_model_types_pb2.BAL_INTF_TYPE_PON |
| 169 | elif pkt_info['dest_type'] == 'nni': |
| 170 | obj.packet.key.packet_send_dest.type = bal_model_types_pb2.BAL_DEST_TYPE_NNI |
| 171 | obj.packet.key.packet_send_dest.nni.intf_id = pkt_info['intf_id'] |
| 172 | else: |
| 173 | self.log.error('unsupported-dest-type', dest_type=pkt_info['dest_type']) |
Shad Ansari | 1831fcc | 2017-08-11 16:41:44 -0700 | [diff] [blame] | 174 | |
| 175 | # Set the Packet-out info |
Shad Ansari | 1831fcc | 2017-08-11 16:41:44 -0700 | [diff] [blame] | 176 | # TODO: Need to provide correct value for intf_id |
Shad Ansari | 1831fcc | 2017-08-11 16:41:44 -0700 | [diff] [blame] | 177 | obj.packet.data.pkt = pkt |
rshetty | f4bf19e | 2017-09-19 01:28:27 +0530 | [diff] [blame] | 178 | self.log.info('sending-packet-out', |
rshetty | 1cc7398 | 2017-09-02 03:31:12 +0530 | [diff] [blame] | 179 | packet_out_details=obj) |
Shad Ansari | 1831fcc | 2017-08-11 16:41:44 -0700 | [diff] [blame] | 180 | yield self.stub.BalCfgSet(obj) |
rshetty | 1cc7398 | 2017-09-02 03:31:12 +0530 | [diff] [blame] | 181 | |
| 182 | @inlineCallbacks |
| 183 | def add_flow(self, onu_id, intf_id, flow_id, gem_port, |
| 184 | classifier_info, is_downstream, |
| 185 | action_info=None, sched_id=None): |
| 186 | try: |
| 187 | obj = bal_pb2.BalCfg() |
| 188 | # Fill Header details |
| 189 | obj.device_id = self.device_id.encode('ascii', 'ignore') |
| 190 | obj.hdr.obj_type = bal_model_ids_pb2.BAL_OBJ_ID_FLOW |
| 191 | # Fill Access Terminal Details |
| 192 | # To-DO flow ID need to be retrieved from flow details |
| 193 | obj.flow.key.flow_id = flow_id |
| 194 | if is_downstream is False: |
| 195 | obj.flow.key.flow_type = \ |
| 196 | bal_model_types_pb2.BAL_FLOW_TYPE_UPSTREAM |
| 197 | obj.flow.data.dba_tm_sched_id = sched_id |
| 198 | else: |
| 199 | obj.flow.key.flow_type = \ |
| 200 | bal_model_types_pb2.BAL_FLOW_TYPE_DOWNSTREAM |
| 201 | |
| 202 | obj.flow.data.admin_state = bal_model_types_pb2.BAL_STATE_UP |
| 203 | obj.flow.data.access_int_id = intf_id |
| 204 | #obj.flow.data.network_int_id = intf_id |
| 205 | obj.flow.data.sub_term_id = onu_id |
| 206 | obj.flow.data.svc_port_id = gem_port |
| 207 | obj.flow.data.classifier.presence_mask = 0 |
| 208 | if 'eth_type' in classifier_info: |
| 209 | obj.flow.data.classifier.ether_type = \ |
| 210 | classifier_info['eth_type'] |
| 211 | obj.flow.data.classifier.presence_mask |= \ |
| 212 | bal_model_types_pb2.BAL_CLASSIFIER_ID_ETHER_TYPE |
| 213 | if 'ip_proto' in classifier_info: |
| 214 | obj.flow.data.classifier.ip_proto = \ |
| 215 | classifier_info['ip_proto'] |
| 216 | obj.flow.data.classifier.presence_mask |= \ |
| 217 | bal_model_types_pb2.BAL_CLASSIFIER_ID_IP_PROTO |
| 218 | if 'vlan_vid' in classifier_info: |
| 219 | obj.flow.data.classifier.o_vid = \ |
| 220 | classifier_info['vlan_vid'] |
| 221 | obj.flow.data.classifier.presence_mask |= \ |
| 222 | bal_model_types_pb2.BAL_CLASSIFIER_ID_O_VID |
| 223 | if 'vlan_pcp' in classifier_info: |
| 224 | obj.flow.data.classifier.o_pbits = \ |
| 225 | classifier_info['vlan_pcp'] |
| 226 | obj.flow.data.classifier.presence_mask |= \ |
| 227 | bal_model_types_pb2.BAL_CLASSIFIER_ID_O_PBITS |
| 228 | if 'udp_src' in classifier_info: |
| 229 | obj.flow.data.classifier.src_port = \ |
| 230 | classifier_info['udp_src'] |
| 231 | obj.flow.data.classifier.presence_mask |= \ |
| 232 | bal_model_types_pb2.BAL_CLASSIFIER_ID_SRC_PORT |
| 233 | if 'udp_dst' in classifier_info: |
| 234 | obj.flow.data.classifier.dst_port = \ |
| 235 | classifier_info['udp_dst'] |
| 236 | obj.flow.data.classifier.presence_mask |= \ |
| 237 | bal_model_types_pb2.BAL_CLASSIFIER_ID_DST_PORT |
| 238 | if 'ipv4_dst' in classifier_info: |
| 239 | obj.flow.data.classifier.dst_ip = \ |
| 240 | classifier_info['ipv4_dst'] |
| 241 | obj.flow.data.classifier.presence_mask |= \ |
| 242 | bal_model_types_pb2.BAL_CLASSIFIER_ID_DST_IP |
| 243 | if 'ipv4_src' in classifier_info: |
| 244 | obj.flow.data.classifier.src_ip = \ |
| 245 | classifier_info['ipv4_src'] |
| 246 | obj.flow.data.classifier.presence_mask |= \ |
| 247 | bal_model_types_pb2.BAL_CLASSIFIER_ID_SRC_IP |
| 248 | if 'metadata' in classifier_info: |
| 249 | obj.flow.data.classifier.i_vid = \ |
| 250 | classifier_info['metadata'] |
| 251 | obj.flow.data.classifier.presence_mask |= \ |
| 252 | bal_model_types_pb2.BAL_CLASSIFIER_ID_I_VID |
| 253 | if 'pkt_tag_type' in classifier_info: |
| 254 | if classifier_info['pkt_tag_type'] == 'single_tag': |
| 255 | obj.flow.data.classifier.pkt_tag_type = \ |
| 256 | bal_model_types_pb2.BAL_PKT_TAG_TYPE_SINGLE_TAG |
| 257 | elif classifier_info['pkt_tag_type'] == 'double_tag': |
| 258 | obj.flow.data.classifier.pkt_tag_type = \ |
| 259 | bal_model_types_pb2.BAL_PKT_TAG_TYPE_DOUBLE_TAG |
| 260 | elif classifier_info['pkt_tag_type'] == 'untagged': |
| 261 | obj.flow.data.classifier.pkt_tag_type = \ |
| 262 | bal_model_types_pb2.BAL_PKT_TAG_TYPE_UNTAGGED |
| 263 | else: |
| 264 | obj.flow.data.classifier.pkt_tag_type = \ |
| 265 | bal_model_types_pb2.BAL_PKT_TAG_TYPE_NONE |
| 266 | obj.flow.data.classifier.presence_mask |= \ |
| 267 | bal_model_types_pb2.BAL_CLASSIFIER_ID_PKT_TAG_TYPE |
| 268 | |
| 269 | if action_info is not None: |
| 270 | obj.flow.data.action.presence_mask = 0 |
| 271 | obj.flow.data.action.cmds_bitmask = 0 |
| 272 | if 'pop_vlan' in action_info: |
| 273 | obj.flow.data.action.o_vid = action_info['vlan_vid'] |
| 274 | obj.flow.data.action.cmds_bitmask |= \ |
| 275 | bal_model_types_pb2.BAL_ACTION_CMD_ID_REMOVE_OUTER_TAG |
| 276 | obj.flow.data.action.presence_mask |= \ |
| 277 | bal_model_types_pb2.BAL_ACTION_ID_CMDS_BITMASK |
| 278 | obj.flow.data.action.presence_mask |= \ |
| 279 | bal_model_types_pb2.BAL_ACTION_ID_O_VID |
| 280 | elif 'push_vlan' in action_info: |
| 281 | obj.flow.data.action.o_vid = action_info['vlan_vid'] |
| 282 | obj.flow.data.action.cmds_bitmask |= \ |
| 283 | bal_model_types_pb2.BAL_ACTION_CMD_ID_ADD_OUTER_TAG |
| 284 | obj.flow.data.action.presence_mask |= \ |
| 285 | bal_model_types_pb2.BAL_ACTION_ID_CMDS_BITMASK |
| 286 | obj.flow.data.action.presence_mask |= \ |
| 287 | bal_model_types_pb2.BAL_ACTION_ID_O_VID |
| 288 | elif 'trap_to_host' in action_info: |
| 289 | obj.flow.data.action.cmds_bitmask |= \ |
| 290 | bal_model_types_pb2.BAL_ACTION_CMD_ID_TRAP_TO_HOST |
| 291 | obj.flow.data.action.presence_mask |= \ |
| 292 | bal_model_types_pb2.BAL_ACTION_ID_CMDS_BITMASK |
| 293 | else: |
| 294 | self.log.info('Invalid-action-field') |
| 295 | return |
| 296 | self.log.info('adding-flow-to-OLT-Device', |
| 297 | flow_details=obj) |
| 298 | yield self.stub.BalCfgSet(obj) |
| 299 | except Exception as e: |
| 300 | self.log.info('add_flow-exception', |
| 301 | flow_id, onu_id, exc=str(e)) |
| 302 | return |
| 303 | |
| 304 | @inlineCallbacks |
rshetty | f4bf19e | 2017-09-19 01:28:27 +0530 | [diff] [blame] | 305 | def delete_flow(self, onu_id, intf_id, flow_id, is_downstream): |
| 306 | try: |
| 307 | obj = bal_pb2.BalCfg() |
| 308 | # Fill Header details |
| 309 | obj.device_id = self.device_id.encode('ascii', 'ignore') |
| 310 | obj.hdr.obj_type = bal_model_ids_pb2.BAL_OBJ_ID_FLOW |
| 311 | # Fill Access Terminal Details |
| 312 | # To-DO flow ID need to be retrieved from flow details |
| 313 | obj.flow.key.flow_id = flow_id |
| 314 | if is_downstream is False: |
| 315 | obj.flow.key.flow_type = \ |
| 316 | bal_model_types_pb2.BAL_FLOW_TYPE_UPSTREAM |
| 317 | else: |
| 318 | obj.flow.key.flow_type = \ |
| 319 | bal_model_types_pb2.BAL_FLOW_TYPE_DOWNSTREAM |
| 320 | |
| 321 | obj.flow.data.admin_state = bal_model_types_pb2.BAL_STATE_DOWN |
| 322 | obj.flow.data.access_int_id = intf_id |
| 323 | #obj.flow.data.network_int_id = intf_id |
| 324 | obj.flow.data.sub_term_id = onu_id |
| 325 | self.log.info('deleting-flows-from-OLT-Device', |
| 326 | flow_details=obj) |
| 327 | yield self.stub.BalCfgSet(obj) |
| 328 | except Exception as e: |
| 329 | self.log.info('delete_flow-exception', |
| 330 | flow_id, onu_id, exc=str(e)) |
| 331 | return |
| 332 | |
| 333 | |
| 334 | @inlineCallbacks |
rshetty | 1cc7398 | 2017-09-02 03:31:12 +0530 | [diff] [blame] | 335 | def create_scheduler(self, id, direction, owner_info, num_priority): |
| 336 | try: |
| 337 | obj = bal_pb2.BalCfg() |
| 338 | # Fill Header details |
| 339 | obj.device_id = self.device_id.encode('ascii', 'ignore') |
| 340 | obj.hdr.obj_type = bal_model_ids_pb2.BAL_OBJ_ID_TM_SCHED |
| 341 | # Fill Access Terminal Details |
| 342 | if direction == 'downstream': |
| 343 | obj.tm_sched_cfg.key.dir =\ |
| 344 | bal_model_types_pb2.BAL_TM_SCHED_DIR_DS |
| 345 | else: |
| 346 | obj.tm_sched_cfg.key.dir = \ |
| 347 | bal_model_types_pb2.BAL_TM_SCHED_DIR_US |
| 348 | obj.tm_sched_cfg.key.id = id |
| 349 | |
| 350 | if owner_info['type'] == 'agg_port': |
| 351 | obj.tm_sched_cfg.data.owner.type = \ |
| 352 | bal_model_types_pb2.BAL_TM_SCHED_OWNER_TYPE_AGG_PORT |
| 353 | obj.tm_sched_cfg.data.owner.agg_port.presence_mask = 0 |
| 354 | obj.tm_sched_cfg.data.owner.agg_port.intf_id =\ |
| 355 | owner_info['intf_id'] |
| 356 | obj.tm_sched_cfg.data.owner.agg_port.presence_mask |= \ |
| 357 | bal_model_types_pb2.BAL_TM_SCHED_OWNER_AGG_PORT_ID_INTF_ID |
| 358 | obj.tm_sched_cfg.data.owner.agg_port.sub_term_id = \ |
| 359 | owner_info['onu_id'] |
| 360 | obj.tm_sched_cfg.data.owner.agg_port.presence_mask |= \ |
| 361 | bal_model_types_pb2.BAL_TM_SCHED_OWNER_AGG_PORT_ID_SUB_TERM_ID |
| 362 | obj.tm_sched_cfg.data.owner.agg_port.agg_port_id = \ |
| 363 | owner_info['alloc_id'] |
| 364 | obj.tm_sched_cfg.data.owner.agg_port.presence_mask |= \ |
| 365 | bal_model_types_pb2.BAL_TM_SCHED_OWNER_AGG_PORT_ID_AGG_PORT_ID |
| 366 | else: |
| 367 | self.log.error('Not supported scheduling type', |
| 368 | sched_type=owner_info['type']) |
| 369 | return |
| 370 | obj.tm_sched_cfg.data.sched_type = \ |
| 371 | bal_model_types_pb2.BAL_TM_SCHED_TYPE_SP_WFQ |
| 372 | obj.tm_sched_cfg.data.num_priorities = num_priority |
| 373 | self.log.info('Creating Scheduler', |
| 374 | scheduler_details=obj) |
| 375 | yield self.stub.BalCfgSet(obj) |
| 376 | except Exception as e: |
| 377 | self.log.info('creat-scheduler-exception', |
| 378 | olt=self.olt.olt_id, |
| 379 | sched_id=id, |
| 380 | direction=direction, |
| 381 | owner=owner_info, |
| 382 | exc=str(e)) |
| 383 | return |
Rajeswara Rao | b2b369a | 2017-09-08 11:44:15 +0530 | [diff] [blame] | 384 | |
| 385 | @inlineCallbacks |
Rajeswara Rao | 48a6235 | 2017-10-26 10:27:27 +0530 | [diff] [blame] | 386 | def get_bal_interface_stats(self, intf_id, interface_type): |
Rajeswara Rao | b2b369a | 2017-09-08 11:44:15 +0530 | [diff] [blame] | 387 | self.log.info('Fetching Statistics') |
| 388 | try: |
| 389 | obj = bal_model_types_pb2.BalInterfaceKey() |
Rajeswara Rao | 48a6235 | 2017-10-26 10:27:27 +0530 | [diff] [blame] | 390 | obj.intf_id = intf_id |
| 391 | obj.intf_type = interface_type |
Rajeswara Rao | b2b369a | 2017-09-08 11:44:15 +0530 | [diff] [blame] | 392 | stats = yield self.stub.BalCfgStatGet(obj) |
| 393 | self.log.info('Fetching statistics success', stats_data = stats.data) |
Rajeswara Rao | 48a6235 | 2017-10-26 10:27:27 +0530 | [diff] [blame] | 394 | returnValue(stats) |
Rajeswara Rao | b2b369a | 2017-09-08 11:44:15 +0530 | [diff] [blame] | 395 | except Exception as e: |
| 396 | self.log.info('Fetching statistics failed', exc=str(e)) |
| 397 | |
| 398 | @inlineCallbacks |
| 399 | def set_bal_reboot(self, device_id): |
| 400 | self.log.info('Set Reboot') |
| 401 | try: |
| 402 | obj = bal_pb2.BalReboot() |
| 403 | obj.device_id = device_id |
| 404 | err = yield self.stub.BalApiReboot(obj) |
| 405 | self.log.info('OLT Reboot Success', reboot_err= err) |
| 406 | returnValue(err) |
| 407 | except Exception as e: |
| 408 | self.log.info('OLT Reboot failed', exc=str(e)) |
| 409 | |
| 410 | @inlineCallbacks |
| 411 | def get_bal_heartbeat(self, device_id): |
| 412 | self.log.info('Get HeartBeat') |
| 413 | try: |
| 414 | obj = bal_pb2.BalHeartbeat() |
| 415 | obj.device_id = device_id |
Rajeswara Rao | a78ddcd | 2017-10-10 18:13:27 +0530 | [diff] [blame] | 416 | rebootStatus = yield self.stub.BalApiHeartbeat(obj) |
| 417 | self.log.info('OLT HeartBeat Response Received from', device=device_id, rebootStatus=rebootStatus) |
| 418 | returnValue(rebootStatus) |
Rajeswara Rao | b2b369a | 2017-09-08 11:44:15 +0530 | [diff] [blame] | 419 | except Exception as e: |
| 420 | self.log.info('OLT HeartBeat failed', exc=str(e)) |