Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 1 | # Copyright 2017 the original author or authors. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | # |
| 15 | |
| 16 | import structlog |
| 17 | import sys |
| 18 | import functools |
| 19 | |
| 20 | from voltha.registry import registry |
| 21 | from voltha.core.config.config_proxy import CallbackType |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 22 | from voltha.protos.bbf_fiber_base_pb2 import ChannelgroupConfig, \ |
| 23 | ChannelpartitionConfig, ChannelpairConfig, ChannelterminationConfig, \ |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 24 | OntaniConfig, VOntaniConfig, VEnetConfig, \ |
| 25 | AllTrafficDescriptorProfileData, AllTcontsConfigData, AllGemportsConfigData |
| 26 | from voltha.protos.bbf_fiber_traffic_descriptor_profile_body_pb2 import \ |
| 27 | TrafficDescriptorProfileData |
| 28 | from voltha.protos.bbf_fiber_tcont_body_pb2 import TcontsConfigData |
| 29 | from voltha.protos.bbf_fiber_gemport_body_pb2 import GemportsConfigData |
| 30 | |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 31 | from voltha.protos.device_pb2 import Device |
| 32 | from voltha.protos.common_pb2 import AdminState |
| 33 | |
| 34 | log = structlog.get_logger() |
| 35 | |
| 36 | class XponAgent(object): |
| 37 | |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 38 | interface_stack = { |
| 39 | ChannelgroupConfig: { |
| 40 | 'path': '/channel_groups/{}', 'path_keys': ['name'], |
| 41 | 'parent': None, 'parent_path': None, 'parent_path_keys': [None], |
| 42 | 'child': { |
| 43 | 1: {'config': ChannelpartitionConfig, |
| 44 | 'child_path': ['/channel_partitions']}}, |
| 45 | 'olt_link': None, 'olt_link_path': None, |
| 46 | 'olt_link_path_keys': [None], 'olt_device_id': 'from_child', |
| 47 | 'onu_link': None, 'onu_link_path': None, |
| 48 | 'onu_link_path_keys': [None], 'onu_device_id': 'na'}, |
| 49 | ChannelpartitionConfig: { |
| 50 | 'path': '/channel_partitions/{}', 'path_keys': ['name'], |
| 51 | 'parent': ChannelgroupConfig, 'parent_path': '/channel_groups/{}', |
| 52 | 'parent_path_keys': ['data.channelgroup_ref'], |
| 53 | 'child': { |
| 54 | 1: {'config': ChannelpairConfig, |
| 55 | 'child_path': ['/channel_pairs']}}, |
| 56 | 'olt_link': None, 'olt_link_path': None, |
| 57 | 'olt_link_path_keys': [None], 'olt_device_id': 'from_child', |
| 58 | 'onu_link': None, 'onu_link_path': None, |
| 59 | 'onu_link_path_keys': [None], 'onu_device_id': 'na'}, |
| 60 | ChannelpairConfig: { |
| 61 | 'path': '/channel_pairs/{}', 'path_keys': ['name'], |
| 62 | 'parent': ChannelpartitionConfig, |
| 63 | 'parent_path': '/channel_partitions/{}', |
| 64 | 'parent_path_keys': ['data.channelpartition_ref'], |
| 65 | 'child': { |
| 66 | 1: {'config': ChannelterminationConfig, |
| 67 | 'child_path': ['/devices', 'channel_terminations']}}, |
| 68 | 'olt_link': None, 'olt_link_path': None, |
| 69 | 'olt_link_path_keys': [None], 'olt_device_id': 'from_child', |
| 70 | 'onu_link': None, 'onu_link_path': None, |
| 71 | 'onu_link_path_keys': [None], 'onu_device_id': 'na'}, |
| 72 | ChannelterminationConfig: { |
| 73 | 'path': '/devices/{}/channel_terminations/{}', |
| 74 | 'path_keys': ['id', 'name'], |
| 75 | 'parent': ChannelpairConfig, 'parent_path': '/channel_pairs/{}', |
| 76 | 'parent_path_keys': ['data.channelpair_ref'], |
| 77 | 'child': None, 'child_path': [None], |
| 78 | 'olt_link': None, 'olt_link_path': None, |
| 79 | 'olt_link_path_keys': [None], 'olt_device_id': 'self', |
| 80 | 'onu_link': None, 'onu_link_path': None, |
| 81 | 'onu_link_path_keys': [None], 'onu_device_id': 'na'}, |
| 82 | VOntaniConfig: { |
| 83 | 'path': '/v_ont_anis/{}', 'path_keys': ['name'], |
| 84 | 'parent': ChannelpartitionConfig, |
| 85 | 'parent_path': '/channel_partitions/{}', |
| 86 | 'parent_path_keys': ['data.parent_ref'], |
| 87 | 'child': { |
| 88 | 1: {'config': VEnetConfig, 'child_path': ['/v_enets']}, |
| 89 | 2: {'config': TcontsConfigData, 'child_path': ['/tconts']}}, |
| 90 | 'olt_link': ChannelpairConfig, |
| 91 | 'olt_link_path': '/channel_pairs/{}', |
| 92 | 'olt_link_path_keys': ['data.preferred_chanpair'], |
| 93 | 'olt_device_id': 'from_link', |
| 94 | 'onu_link': None, 'onu_link_path': None, |
| 95 | 'onu_link_path_keys': [None], 'onu_device_id': 'self'}, |
| 96 | OntaniConfig: { |
| 97 | 'path': '/ont_anis/{}', 'path_keys': ['name'], |
| 98 | 'parent': None, 'parent_path': None, 'parent_path_keys': [None], |
| 99 | 'child': None, 'child_path': [None], |
| 100 | 'olt_link': VOntaniConfig, 'olt_link_path': '/v_ont_anis/{}', |
| 101 | 'olt_link_path_keys': ['name'], 'olt_device_id' : 'from_link', |
| 102 | 'onu_link': VOntaniConfig, 'onu_link_path': '/v_ont_anis/{}', |
| 103 | 'onu_link_path_keys': ['name'], 'onu_device_id': 'from_link'}, |
| 104 | VEnetConfig: { |
| 105 | 'path': '/v_enets/{}', 'path_keys': ['name'], |
| 106 | 'parent': VOntaniConfig, 'parent_path': '/v_ont_anis/{}', |
| 107 | 'parent_path_keys': ['data.v_ontani_ref'], |
| 108 | 'child': { |
| 109 | 1: {'config': GemportsConfigData, |
| 110 | 'child_path': ['/gemports']}}, |
| 111 | 'olt_link': None, 'olt_link_path': None, |
| 112 | 'olt_link_path_keys': [None], 'olt_device_id': 'from_parent', |
| 113 | 'onu_link': None, 'onu_link_path': None, |
| 114 | 'onu_link_path_keys': [None], 'onu_device_id': 'from_parent'}, |
| 115 | TcontsConfigData: { |
| 116 | 'path': '/tconts/{}', 'path_keys': ['name'], |
| 117 | 'parent': VOntaniConfig, 'parent_path': '/v_ont_anis/{}', |
| 118 | 'parent_path_keys': ['interface_reference'], |
| 119 | 'child': None, 'child_path': [None], |
| 120 | 'olt_link': None, 'olt_link_path': None, |
| 121 | 'olt_link_path_keys': [None], 'olt_device_id': 'from_parent', |
| 122 | 'onu_link': None, 'onu_link_path': None, |
| 123 | 'onu_link_path_keys': [None], 'onu_device_id': 'from_parent'}, |
| 124 | GemportsConfigData: { |
| 125 | 'path': '/gemports/{}', 'path_keys': ['name'], |
| 126 | 'parent': VEnetConfig, 'parent_path': '/v_enets/{}', |
| 127 | 'parent_path_keys': ['itf_ref'], |
| 128 | 'child': None, 'child_path': [None], |
| 129 | 'olt_link': None, 'olt_link_path': None, |
| 130 | 'olt_link_path_keys': [None], 'olt_device_id': 'from_parent', |
| 131 | 'onu_link': None, 'onu_link_path': None, |
| 132 | 'onu_link_path_keys': [None], 'onu_device_id': 'from_parent'} |
| 133 | } |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 134 | |
| 135 | def __init__(self, core): |
| 136 | self.core = core |
| 137 | self.preData = None |
| 138 | self.inReplay = False |
| 139 | return |
| 140 | |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 141 | def get_device_adapter_agent(self, device): |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 142 | assert device.adapter != '' |
| 143 | adapter_agent = registry('adapter_loader').get_agent(device.adapter) |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 144 | log.debug('get-device-adapter-agent', device=device, |
| 145 | adapter_agent=adapter_agent) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 146 | return adapter_agent |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 147 | |
| 148 | def get_interface_path(self, data): |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 149 | interface = self.interface_stack[type(data)] |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 150 | id_val = {} |
| 151 | count = 0 |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 152 | for key in interface['path_keys']: |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 153 | id_val[count] = getattr(data, key) |
| 154 | count+=1 |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 155 | path = interface['path'].format(*id_val.values()) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 156 | return path |
| 157 | |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 158 | def _child_predicate(self, data, child): |
| 159 | return self.get_parent_data(child).name == data.name |
| 160 | |
| 161 | def _get_child_data_by_path (self, data, path): |
| 162 | children = self.core.get_proxy('/').get(path) |
| 163 | return next((child for child in children |
| 164 | if self._child_predicate(data, child)), None) |
| 165 | |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 166 | def get_device(self, data, device_type): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 167 | if data is None: |
| 168 | return None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 169 | interface_node = self.interface_stack[type(data)] |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 170 | device = None |
| 171 | if interface_node['{}_device_id'.format(device_type)] == 'self': |
| 172 | if device_type == 'olt': |
| 173 | device = self.core.get_proxy('/').get('/devices/{}'. |
| 174 | format(data.id)) |
| 175 | return device |
| 176 | elif device_type == 'onu': |
| 177 | devs = self.core.get_proxy('/').get('/devices') |
| 178 | for dev in devs: |
| 179 | if dev.serial_number == data.data.expected_serial_number: |
| 180 | return dev |
| 181 | if device is None: |
| 182 | if interface_node['{}_device_id'. |
| 183 | format(device_type)] == 'from_parent': |
| 184 | device = self.get_device(self.get_parent_data(data), |
| 185 | device_type) |
| 186 | elif interface_node['{}_device_id'. |
| 187 | format(device_type)] == 'from_child': |
| 188 | device = self.get_device(self.get_child_data(data), |
| 189 | device_type) |
| 190 | elif interface_node['{}_device_id'. |
| 191 | format(device_type)] == 'from_link': |
| 192 | device = self.get_device(self.get_link_data(data, device_type), |
| 193 | device_type) |
| 194 | return device |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 195 | |
| 196 | def get_parent_data(self, data): |
| 197 | if data is None: |
| 198 | return None |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 199 | interface_node = self.interface_stack[type(data)] |
| 200 | if interface_node['parent'] is None: |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 201 | return None |
| 202 | id_val = {} |
| 203 | count = 0 |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 204 | for key in interface_node['parent_path_keys']: |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 205 | id_val[count] = self.rgetattr(data, key) |
| 206 | count+=1 |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 207 | parent_path = interface_node['parent_path'].format(*id_val.values()) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 208 | try: |
| 209 | parent_data = self.core.get_proxy('/').get(parent_path) |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 210 | if not parent_data: |
| 211 | return None |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 212 | return parent_data |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 213 | except KeyError: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 214 | log.info('xpon-agent-warning-interface-cannot-get-parent', |
| 215 | data=data) |
| 216 | return None |
| 217 | |
| 218 | def get_child_data(self, data): |
| 219 | interface_node = self.interface_stack[type(data)] |
Nikolay Titov | 4e1c370 | 2017-08-23 12:41:57 -0400 | [diff] [blame] | 220 | child = None |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 221 | if len(interface_node['child'][1]['child_path']) > 1: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 222 | top_children = self.core.get_proxy('/').get('{}'.format( |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 223 | interface_node['child'][1]['child_path'][0])) |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 224 | for top_child in top_children: |
| 225 | child = self._get_child_data_by_path(data, '{}/{}/{}'.format( |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 226 | interface_node['child'][1]['child_path'][0], top_child.id, |
| 227 | interface_node['child'][1]['child_path'][1])) |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 228 | if child is not None: |
| 229 | return child |
| 230 | else: |
| 231 | child = self._get_child_data_by_path(data, '{}'.format( |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 232 | interface_node['child'][1]['child_path'][0])) |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 233 | if child is None: |
| 234 | log.info('xpon-agent-warning-interface-cannot-get-child', |
| 235 | data=data) |
| 236 | return child |
| 237 | |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 238 | def get_link_data(self, data, device_type): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 239 | interface_node = self.interface_stack[type(data)] |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 240 | if interface_node['{}_link'.format(device_type)] is None: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 241 | return None |
| 242 | id_val = {} |
| 243 | count = 0 |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 244 | for key in interface_node['{}_link_path_keys'.format(device_type)]: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 245 | id_val[count] = self.rgetattr(data, key) |
| 246 | count+=1 |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 247 | link_path = interface_node['{}_link_path'.format(device_type)].format( |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 248 | *id_val.values()) |
| 249 | try: |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 250 | link_data = self.core.get_proxy('/').get(link_path) |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 251 | return link_data |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 252 | except KeyError: |
| 253 | log.info('xpon-agent-warning-interface-cannot-get-{}-link-data'. |
| 254 | format(device_type), data=data) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 255 | return None |
| 256 | |
| 257 | def rgetattr(self, obj, attr): |
| 258 | def _getattr(obj, name): |
| 259 | return getattr(obj, name) |
| 260 | return functools.reduce(_getattr, [obj]+attr.split('.')) |
| 261 | |
| 262 | def is_valid_interface(self, data): |
| 263 | valid = False |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 264 | for key in self.interface_stack.keys(): |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 265 | valid |= isinstance(data, key) |
| 266 | return valid |
| 267 | |
| 268 | def register_interface(self, device_id, path, update=True): |
| 269 | log.info('register-interface:', device_id=device_id, path=path) |
| 270 | try: |
| 271 | interface_proxy = self.core.get_proxy(path) |
| 272 | if update: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 273 | interface_proxy.register_callback(CallbackType.POST_UPDATE, |
| 274 | self.update_interface, |
| 275 | device_id) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 276 | else: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 277 | interface_proxy.register_callback(CallbackType.POST_ADD, |
| 278 | self.create_interface, |
| 279 | device_id) |
| 280 | interface_proxy.register_callback(CallbackType.POST_REMOVE, |
| 281 | self.remove_interface, |
| 282 | device_id) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 283 | except: |
| 284 | print "Unexpected error:", sys.exc_info()[0] |
| 285 | |
| 286 | def unregister_interface(self, device_id, path, update=True): |
| 287 | log.info('unregister-interface:', device_id=device_id, path=path) |
| 288 | try: |
| 289 | interface_proxy = self.core.get_proxy(path) |
| 290 | if update: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 291 | interface_proxy.unregister_callback(CallbackType.POST_UPDATE, |
| 292 | self.update_interface, |
| 293 | device_id) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 294 | else: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 295 | interface_proxy.unregister_callback(CallbackType.POST_ADD, |
| 296 | self.create_interface, |
| 297 | device_id) |
| 298 | interface_proxy.unregister_callback(CallbackType.POST_REMOVE, |
| 299 | self.remove_interface, |
| 300 | device_id) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 301 | except: |
| 302 | print "Unexpected error:", sys.exc_info()[0] |
| 303 | |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 304 | def create_interface_in_device(self, device, data): |
Niren R Chidrawar | 11e4d7c | 2017-08-17 23:21:31 -0400 | [diff] [blame] | 305 | if device is None: |
| 306 | return |
| 307 | log.info('xpon-agent-create-interface-in-device', |
| 308 | device_id=device.id, type=type(data).__name__, data=data) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 309 | adapter_agent = self.get_device_adapter_agent(device) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 310 | if (isinstance(data, TcontsConfigData)): |
| 311 | # Adapter interfaces for TCONT always need traffic-descriptor |
| 312 | traffic_descriptor_data = self.core.get_proxy('/').get( |
| 313 | '/traffic_descriptor_profiles/{}'. |
| 314 | format(data.traffic_descriptor_profile_ref)) |
| 315 | adapter_agent.create_tcont( |
| 316 | device=device, tcont_data=data, |
| 317 | traffic_descriptor_data=traffic_descriptor_data) |
| 318 | elif (isinstance(data, TrafficDescriptorProfileData)): |
| 319 | # Do nothing for now |
| 320 | log.info( |
| 321 | 'create-interface-in-device-traffic-descriptor-do-nothing', |
| 322 | device=device, data=data) |
| 323 | elif (isinstance(data, GemportsConfigData)): |
| 324 | adapter_agent.create_gemport(device=device, data=data) |
| 325 | elif (isinstance(data, (ChannelgroupConfig, ChannelpartitionConfig, |
| 326 | ChannelpairConfig, ChannelterminationConfig, |
| 327 | OntaniConfig, VOntaniConfig, VEnetConfig))): |
| 328 | adapter_agent.create_interface(device=device, data=data) |
| 329 | else: |
| 330 | # Not handled yet |
| 331 | log.info('create-interface-in-device: Not handling', |
| 332 | device=device, data=data) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 333 | |
Nikolay Titov | e44c3d2 | 2017-08-03 15:27:37 -0400 | [diff] [blame] | 334 | def update_interface_in_device(self, device, data): |
Niren R Chidrawar | 11e4d7c | 2017-08-17 23:21:31 -0400 | [diff] [blame] | 335 | if device is None: |
| 336 | return |
| 337 | log.info('xpon-agent-update-interface-in-device', |
| 338 | device_id=device.id, type=type(data).__name__, data=data) |
Nikolay Titov | e44c3d2 | 2017-08-03 15:27:37 -0400 | [diff] [blame] | 339 | adapter_agent = self.get_device_adapter_agent(device) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 340 | if (isinstance(data, TcontsConfigData)): |
| 341 | # Adapter interfaces for TCONT always need traffic-descriptor |
| 342 | traffic_descriptor_data = self.core.get_proxy('/').get( |
| 343 | '/traffic_descriptor_profiles/{}'. |
| 344 | format(data.traffic_descriptor_profile_ref)) |
| 345 | adapter_agent.update_tcont( |
| 346 | device=device, tcont_data=data, |
| 347 | traffic_descriptor_data=traffic_descriptor_data) |
| 348 | elif (isinstance(data, TrafficDescriptorProfileData)): |
| 349 | # Do nothing for now |
| 350 | log.info( |
| 351 | 'update-interface-in-device-traffic-descriptor-do-nothing', |
| 352 | device=device, data=data) |
| 353 | elif (isinstance(data, GemportsConfigData)): |
| 354 | adapter_agent.update_gemport(device=device, data=data) |
| 355 | elif (isinstance(data, (ChannelgroupConfig, ChannelpartitionConfig, |
| 356 | ChannelpairConfig, ChannelterminationConfig, |
| 357 | OntaniConfig, VOntaniConfig, VEnetConfig))): |
| 358 | adapter_agent.update_interface(device=device, data=data) |
| 359 | else: |
| 360 | # Not handled yet |
| 361 | log.info('create-interface-in-device: Not handling', |
| 362 | device=device, data=data) |
Nikolay Titov | e44c3d2 | 2017-08-03 15:27:37 -0400 | [diff] [blame] | 363 | |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 364 | def remove_interface_in_device(self, device, data): |
Niren R Chidrawar | 11e4d7c | 2017-08-17 23:21:31 -0400 | [diff] [blame] | 365 | if device is None: |
| 366 | return |
| 367 | log.info('xpon-agent-remove-interface-in-device', |
| 368 | device_id=device.id, type=type(data).__name__, data=data) |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 369 | adapter_agent = self.get_device_adapter_agent(device) |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 370 | if (isinstance(data, TcontsConfigData)): |
| 371 | # Adapter interfaces for TCONT always need traffic-descriptor |
| 372 | traffic_descriptor_data = self.core.get_proxy('/').get( |
| 373 | '/traffic_descriptor_profiles/{}'. |
| 374 | format(data.traffic_descriptor_profile_ref)) |
| 375 | adapter_agent.remove_tcont( |
| 376 | device=device, tcont_data=data, |
| 377 | traffic_descriptor_data=traffic_descriptor_data) |
| 378 | elif (isinstance(data, TrafficDescriptorProfileData)): |
| 379 | # Do nothing for now |
| 380 | log.info( |
| 381 | 'remove-interface-in-device-traffic-descriptor-do-nothing', |
| 382 | device=device, data=data) |
| 383 | elif (isinstance(data, GemportsConfigData)): |
| 384 | adapter_agent.remove_gemport(device=device, data=data) |
| 385 | elif (isinstance(data, (ChannelgroupConfig, ChannelpartitionConfig, |
| 386 | ChannelpairConfig, ChannelterminationConfig, |
| 387 | OntaniConfig, VOntaniConfig, VEnetConfig))): |
| 388 | adapter_agent.remove_interface(device=device, data=data) |
| 389 | else: |
| 390 | # Not handled yet |
| 391 | log.info('remove-interface-in-device: Not handling', |
| 392 | device=device, data=data) |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 393 | |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 394 | def create_interface(self, data, device_id=None): |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 395 | if not self.is_valid_interface(data): |
| 396 | log.info('xpon-agent-create-interface-invalid-interface-type', |
| 397 | type=type(data).__name__) |
| 398 | return |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 399 | if device_id is None: |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 400 | olt_device = self.get_device(data, 'olt') |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 401 | else: |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 402 | olt_device = self.core.get_proxy('/').get('/devices/{}'. |
| 403 | format(device_id)) |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 404 | device_id = None if olt_device is None else olt_device.id |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 405 | self.register_interface(device_id=device_id, |
| 406 | path=self.get_interface_path(data)) |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 407 | if olt_device is not None: |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 408 | if(isinstance(data, ChannelterminationConfig)): |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 409 | self.create_channel_termination(olt_device, data) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 410 | elif(isinstance(data, VOntaniConfig)): |
Niren R Chidrawar | 11e4d7c | 2017-08-17 23:21:31 -0400 | [diff] [blame] | 411 | self.create_onu_interfaces(data=data, olt_device=olt_device) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 412 | else: |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 413 | log.info( |
| 414 | 'xpon-agent-creating-interface-at-olt-device:', |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 415 | olt_device_id=olt_device.id, data=data) |
| 416 | self.create_interface_in_device(olt_device, data) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 417 | interface_node = self.interface_stack[type(data)] |
| 418 | if interface_node['onu_device_id'] != 'na': |
| 419 | onu_device = self.get_device(data, 'onu') |
| 420 | log.info( |
| 421 | 'xpon-agent-creating-interface-at-onu-device:', |
| 422 | onu_device_id=onu_device.id, data=data) |
| 423 | self.create_interface_in_device(onu_device, data) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 424 | |
| 425 | def update_interface(self, data, device_id): |
| 426 | if not self.is_valid_interface(data): |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 427 | log.info('xpon-agent-update-interface-invalid-interface-type', |
| 428 | type=type(data).__name__) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 429 | return |
| 430 | if device_id is None: |
Nikolay Titov | e44c3d2 | 2017-08-03 15:27:37 -0400 | [diff] [blame] | 431 | olt_device = self.get_device(data, 'olt') |
| 432 | else: |
| 433 | olt_device = self.core.get_proxy('/').get('/devices/{}'. |
| 434 | format(device_id)) |
| 435 | if olt_device is not None: |
| 436 | log.info('xpon-agent-updating-interface-at-olt-device', |
| 437 | olt_device_id=olt_device.id, data=data) |
| 438 | self.update_interface_in_device(olt_device, data) |
| 439 | interface_node = self.interface_stack[type(data)] |
| 440 | if interface_node['onu_device_id'] != 'na': |
| 441 | onu_device = self.get_device(data, 'onu') |
| 442 | log.info('xpon-agent-updating-interface-at-onu-device:', |
| 443 | onu_device_id=onu_device.id, data=data) |
| 444 | self.update_interface_in_device(onu_device, data) |
Nikolay Titov | d82b2fc | 2017-10-06 00:24:37 -0400 | [diff] [blame] | 445 | if isinstance(data, VOntaniConfig): |
| 446 | self.update_onu_device(olt_device, onu_device, data) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 447 | |
| 448 | def remove_interface(self, data, device_id=None): |
Nikolay Titov | 176f1db | 2017-08-10 12:38:43 -0400 | [diff] [blame] | 449 | if not self.is_valid_interface(data): |
| 450 | log.info('xpon-agent-remove-interface-invalid-interface-type', |
| 451 | type=type(data).__name__) |
| 452 | return |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 453 | if device_id is None: |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 454 | olt_device = self.get_device(data, 'olt') |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 455 | else: |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 456 | olt_device = self.core.get_proxy('/').get('/devices/{}'. |
| 457 | format(device_id)) |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 458 | if olt_device is not None: |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 459 | log.info('xpon-agent-remove-interface:', |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 460 | olt_device_id=olt_device.id, data=data) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 461 | if(isinstance(data, ChannelterminationConfig)): |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 462 | self.remove_channel_termination(olt_device, data) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 463 | else: |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 464 | interface_node = self.interface_stack[type(data)] |
| 465 | if interface_node['onu_device_id'] != 'na': |
| 466 | onu_device = self.get_device(data, 'onu') |
| 467 | log.info( |
| 468 | 'xpon-agent-removing-interface-at-onu-device:', |
| 469 | onu_device_id=onu_device.id, data=data) |
| 470 | self.remove_interface_in_device(onu_device, data) |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 471 | log.info( |
| 472 | 'xpon-agent-removing-interface-at-olt-device:', |
| 473 | olt_device_id=olt_device.id, data=data) |
| 474 | self.remove_interface_in_device(olt_device, data) |
Girish | d582367 | 2017-11-23 12:15:14 +0530 | [diff] [blame] | 475 | if isinstance(data, VOntaniConfig): |
| 476 | self.delete_onu_device(olt_device, onu_device) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 477 | |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 478 | def create_channel_termination(self, olt_device, data): |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 479 | channel_pair = self.get_parent_data(data) |
| 480 | channel_part = self.get_parent_data(channel_pair) |
| 481 | channel_group = self.get_parent_data(channel_part) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 482 | if channel_group is not None: |
| 483 | log.info('xpon-agent-creating-channel-group', |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 484 | olt_device_id=olt_device.id, channel_group=channel_group) |
| 485 | self.create_interface_in_device(olt_device, channel_group) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 486 | if channel_part is not None: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 487 | log.info('xpon-agent-creating-channel-partition:', |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 488 | olt_device_id=olt_device.id, channel_part=channel_part) |
| 489 | self.create_interface_in_device(olt_device, channel_part) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 490 | if channel_pair is not None: |
| 491 | log.info('xpon-agent-creating-channel-pair:', |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 492 | olt_device_id=olt_device.id, channel_pair=channel_pair) |
| 493 | self.create_interface_in_device(olt_device, channel_pair) |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 494 | log.info('xpon-agent-creating-channel-termination:', |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 495 | olt_device_id=olt_device.id, data=data) |
| 496 | self.create_interface_in_device(olt_device, data) |
| 497 | if channel_pair is None: |
| 498 | return |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 499 | v_ont_anis = self.core.get_proxy('/').get('/v_ont_anis') |
| 500 | for v_ont_ani in v_ont_anis: |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 501 | if self.get_link_data(v_ont_ani, 'olt').name == channel_pair.name: |
Niren R Chidrawar | 11e4d7c | 2017-08-17 23:21:31 -0400 | [diff] [blame] | 502 | self.create_onu_interfaces(data=v_ont_ani, olt_device=olt_device) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 503 | |
Niren R Chidrawar | 11e4d7c | 2017-08-17 23:21:31 -0400 | [diff] [blame] | 504 | def create_onu_interfaces(self, data, olt_device=None, onu_device=None): |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 505 | if not self.inReplay: |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 506 | self.create_onu_device(device=olt_device, v_ont_ani=data) |
Niren R Chidrawar | 11e4d7c | 2017-08-17 23:21:31 -0400 | [diff] [blame] | 507 | onu_device = self.get_device(data, 'onu') |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 508 | self.create_interface_in_device(olt_device, data) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 509 | self.create_interface_in_device(onu_device, data) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 510 | try: |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 511 | ont_ani = self.core.get_proxy('/').get('/ont_anis/{}'. |
| 512 | format(data.name)) |
| 513 | if ont_ani is not None: |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 514 | self.create_interface_in_device(olt_device, ont_ani) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 515 | self.create_interface_in_device(onu_device, ont_ani) |
Nikolay Titov | 1ab3d4b | 2017-08-11 13:30:40 -0400 | [diff] [blame] | 516 | tconts = self.core.get_proxy('/').get('/tconts') |
| 517 | for tcont in tconts: |
| 518 | if self.get_parent_data(tcont).name == data.name: |
Nikolay Titov | 1ab3d4b | 2017-08-11 13:30:40 -0400 | [diff] [blame] | 519 | self.create_interface_in_device(olt_device, tcont) |
Nikolay Titov | 1ab3d4b | 2017-08-11 13:30:40 -0400 | [diff] [blame] | 520 | self.create_interface_in_device(onu_device, tcont) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 521 | v_enets = self.core.get_proxy('/').get('/v_enets') |
| 522 | for v_enet in v_enets: |
| 523 | if self.get_parent_data(v_enet).name == data.name: |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 524 | self.create_interface_in_device(olt_device, v_enet) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 525 | self.create_interface_in_device(onu_device, v_enet) |
Nikolay Titov | 1ab3d4b | 2017-08-11 13:30:40 -0400 | [diff] [blame] | 526 | gemports = self.core.get_proxy('/').get('/gemports') |
| 527 | for gemport in gemports: |
| 528 | if self.get_parent_data(gemport).name == v_enet.name: |
Nikolay Titov | 1ab3d4b | 2017-08-11 13:30:40 -0400 | [diff] [blame] | 529 | self.create_interface_in_device(olt_device, |
| 530 | gemport) |
Nikolay Titov | 1ab3d4b | 2017-08-11 13:30:40 -0400 | [diff] [blame] | 531 | self.create_interface_in_device(onu_device, |
| 532 | gemport) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 533 | except KeyError: |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 534 | log.info( |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 535 | 'xpon-agent-create-onu-interfaces-no-ont-ani-link-exists') |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 536 | |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 537 | def remove_channel_termination(self, olt_device, data): |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 538 | channel_pair = self.get_parent_data(data) |
| 539 | if channel_pair is None: |
| 540 | log.info( |
| 541 | 'xpon-agent-removing-channel-termination:', |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 542 | olt_device_id=olt_device.id, data=data) |
| 543 | self.remove_interface_in_device(olt_device, data) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 544 | return |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 545 | self.remove_onu_interfaces(olt_device, channel_pair) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 546 | log.info( |
| 547 | 'xpon-agent-removing-channel-termination:', |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 548 | olt_device_id=olt_device.id, data=data) |
| 549 | self.remove_interface_in_device(olt_device, data) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 550 | log.info( |
| 551 | 'xpon-agent-removing-channel-pair:', |
Nikolay Titov | 1ab3d4b | 2017-08-11 13:30:40 -0400 | [diff] [blame] | 552 | olt_device_id=olt_device.id, channel_pair=channel_pair) |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 553 | self.remove_interface_in_device(olt_device, channel_pair) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 554 | channel_partition = self.get_parent_data(channel_pair) |
| 555 | if channel_partition is not None: |
| 556 | log.info( |
| 557 | 'xpon-agent-removing-channel-partition:', |
Nikolay Titov | 1ab3d4b | 2017-08-11 13:30:40 -0400 | [diff] [blame] | 558 | olt_device_id=olt_device.id, |
| 559 | channel_partition=channel_partition) |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 560 | self.remove_interface_in_device(olt_device, channel_partition) |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 561 | channel_group = self.get_parent_data(channel_partition) |
| 562 | if channel_group is not None: |
| 563 | log.info( |
| 564 | 'xpon-agent-removing-channel-group:', |
Nikolay Titov | 1ab3d4b | 2017-08-11 13:30:40 -0400 | [diff] [blame] | 565 | olt_device_id=olt_device.id, channel_group=channel_group) |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 566 | self.remove_interface_in_device(olt_device, channel_group) |
| 567 | |
| 568 | def remove_onu_interfaces(self, olt_device, data): |
| 569 | v_ont_anis = self.core.get_proxy('/').get('/v_ont_anis') |
| 570 | for v_ont_ani in v_ont_anis: |
| 571 | if self.get_link_data(v_ont_ani, 'olt').name == data.name: |
| 572 | onu_device = self.get_device(v_ont_ani, 'onu') |
| 573 | v_enets = self.core.get_proxy('/').get('/v_enets') |
| 574 | for v_enet in v_enets: |
| 575 | if self.get_parent_data(v_enet).name == v_ont_ani.name: |
Nikolay Titov | 1ab3d4b | 2017-08-11 13:30:40 -0400 | [diff] [blame] | 576 | gemports = self.core.get_proxy('/').get('/gemports') |
| 577 | for gemport in gemports: |
| 578 | if self.get_parent_data(gemport).name == \ |
| 579 | v_enet.name: |
| 580 | log.info( |
| 581 | 'xpon-agent-remove-gemport-at-onu-device:', |
| 582 | onu_device_id=onu_device.id, |
| 583 | gemport=gemport) |
| 584 | self.remove_interface_in_device(onu_device, |
| 585 | gemport) |
| 586 | log.info( |
| 587 | 'xpon-agent-remove-gemport-at-olt-device:', |
| 588 | olt_device_id=olt_device.id, |
| 589 | gemport=gemport) |
| 590 | self.remove_interface_in_device(olt_device, |
| 591 | gemport) |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 592 | log.info( |
| 593 | 'xpon-agent-removing-v-enet-at-onu-device:', |
| 594 | onu_device_id=onu_device.id, data=v_enet) |
| 595 | self.remove_interface_in_device(onu_device, v_enet) |
| 596 | log.info( |
| 597 | 'xpon-agent-removing-v-enet-at-olt-device:', |
| 598 | olt_device_id=olt_device.id, data=v_enet) |
| 599 | self.remove_interface_in_device(olt_device, v_enet) |
Nikolay Titov | 1ab3d4b | 2017-08-11 13:30:40 -0400 | [diff] [blame] | 600 | tconts = self.core.get_proxy('/').get('/tconts') |
| 601 | for tcont in tconts: |
| 602 | if self.get_parent_data(tcont).name == v_ont_ani.name: |
| 603 | log.info( |
| 604 | 'xpon-agent-removing-tcont-at-onu-device:', |
| 605 | onu_device_id=onu_device.id, tcont=tcont) |
| 606 | self.remove_interface_in_device(onu_device, tcont) |
| 607 | log.info( |
| 608 | 'xpon-agent-removing-tcont-at-olt-device:', |
| 609 | olt_device_id=olt_device.id, tcont=tcont) |
| 610 | self.remove_interface_in_device(olt_device, tcont) |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 611 | try: |
| 612 | ont_ani = self.core.get_proxy('/').get( |
| 613 | '/ont_anis/{}'.format(v_ont_ani.name)) |
| 614 | log.info( |
| 615 | 'xpon-agent-removing-ont-ani-at-onu-device:', |
| 616 | onu_device_id=onu_device.id, data=ont_ani) |
| 617 | self.remove_interface_in_device(onu_device, ont_ani) |
| 618 | log.info( |
| 619 | 'xpon-agent-removing-ont-ani-at-olt-device:', |
| 620 | olt_device_id=olt_device.id, data=ont_ani) |
| 621 | self.remove_interface_in_device(olt_device, ont_ani) |
| 622 | except KeyError: |
| 623 | log.info( |
| 624 | 'xpon-agent-remove-channel-termination-ont-ani-not-found') |
| 625 | log.info( |
| 626 | 'xpon-agent-removing-v-ont-ani-at-onu-device:', |
| 627 | onu_device_id=onu_device.id, data=v_ont_ani) |
| 628 | self.remove_interface_in_device(onu_device, v_ont_ani) |
| 629 | log.info( |
| 630 | 'xpon-agent-removing-v-ont-ani-at-olt-device:', |
| 631 | olt_device_id=olt_device.id, data=v_ont_ani) |
| 632 | self.remove_interface_in_device(olt_device, v_ont_ani) |
| 633 | self.delete_onu_device(olt_device, onu_device) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 634 | |
| 635 | def replay_interface(self, device_id): |
| 636 | self.inReplay = True |
Niren R Chidrawar | 11e4d7c | 2017-08-17 23:21:31 -0400 | [diff] [blame] | 637 | if not self.is_onu_device_id(device_id): |
| 638 | ct_items = self.core.get_proxy('/').get( |
| 639 | '/devices/{}/channel_terminations'.format(device_id)) |
| 640 | for ct in ct_items: |
| 641 | self.create_interface(data=ct, device_id=device_id) |
| 642 | else: |
| 643 | onu_device = self.core.get_proxy('/').get('/devices/{}'. |
| 644 | format(device_id)) |
| 645 | v_ont_anis = self.core.get_proxy('/').get('/v_ont_anis') |
| 646 | for v_ont_ani in v_ont_anis: |
| 647 | if v_ont_ani.data.expected_serial_number == \ |
| 648 | onu_device.serial_number: |
| 649 | #self._create_onu_interfaces(onu_device, v_ont_ani) |
| 650 | self.create_onu_interfaces(data=v_ont_ani, onu_device=onu_device) |
| 651 | break |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 652 | self.inReplay = False |
| 653 | |
Niren R Chidrawar | 11e4d7c | 2017-08-17 23:21:31 -0400 | [diff] [blame] | 654 | def is_onu_device_id(self, device_id): |
| 655 | device = self.core.get_proxy('/').get('/devices/{}'.format(device_id)) |
| 656 | return True if device.type.endswith("_onu") else False |
| 657 | |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 658 | def get_port_num(self, device_id, label): |
| 659 | log.info('get-port-num:', label=label, device_id=device_id) |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 660 | ports = self.core.get_proxy('/').get('/devices/{}/ports'. |
| 661 | format(device_id)) |
| 662 | log.info('get-port-num:', label=label, device_id=device_id, |
| 663 | ports=ports) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 664 | for port in ports: |
| 665 | if port.label == label: |
| 666 | return port.port_no |
| 667 | return 0 |
| 668 | |
Sireesha Kora | 3f3788f | 2017-08-18 01:18:53 -0400 | [diff] [blame] | 669 | def get_channel_group_for_vont_ani(self, v_ont_ani): |
| 670 | _cp = self.core.get_proxy('/').get('/channel_partitions/{}'.format( |
| 671 | v_ont_ani.data.parent_ref)) |
| 672 | assert _cp is not None |
| 673 | _cg = self.core.get_proxy('/').get('/channel_groups/{}'.format( |
| 674 | _cp.data.channelgroup_ref)) |
| 675 | assert _cg is not None |
| 676 | return _cg.cg_index |
| 677 | |
Nikolay Titov | 0da216c | 2017-07-27 00:47:44 -0400 | [diff] [blame] | 678 | def create_onu_device(self, device, v_ont_ani): |
| 679 | log.info('create-onu-device', device_id=device.id, v_ont_ani=v_ont_ani) |
| 680 | adapter_agent = self.get_device_adapter_agent(device) |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 681 | parent_chnl_pair_id = self.get_port_num( |
| 682 | device.id, v_ont_ani.data.preferred_chanpair) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 683 | log.info('create-onu-device:', parent_chnl_pair_id=parent_chnl_pair_id) |
Niren R Chidrawar | efcebcd | 2017-07-19 20:03:39 -0400 | [diff] [blame] | 684 | vendor_id = v_ont_ani.data.expected_serial_number[:4] |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 685 | proxy_address = Device.ProxyAddress( |
Niren R Chidrawar | 11e4d7c | 2017-08-17 23:21:31 -0400 | [diff] [blame] | 686 | device_id=device.id, |
Sireesha Kora | 3f3788f | 2017-08-18 01:18:53 -0400 | [diff] [blame] | 687 | channel_group_id=self.get_channel_group_for_vont_ani(v_ont_ani), |
Niren R Chidrawar | 11e4d7c | 2017-08-17 23:21:31 -0400 | [diff] [blame] | 688 | channel_id=parent_chnl_pair_id, |
Sireesha Kora | 3f3788f | 2017-08-18 01:18:53 -0400 | [diff] [blame] | 689 | channel_termination=v_ont_ani.data.preferred_chanpair, |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 690 | onu_id=v_ont_ani.data.onu_id, onu_session_id=v_ont_ani.data.onu_id) |
Niren R Chidrawar | efcebcd | 2017-07-19 20:03:39 -0400 | [diff] [blame] | 691 | adapter_agent.add_onu_device( |
Nikolay Titov | 3f0c9dd | 2017-07-17 17:37:25 -0400 | [diff] [blame] | 692 | parent_device_id=device.id, parent_port_no=parent_chnl_pair_id, |
Niren R Chidrawar | efcebcd | 2017-07-19 20:03:39 -0400 | [diff] [blame] | 693 | vendor_id=vendor_id, proxy_address=proxy_address, |
| 694 | root=True, serial_number=v_ont_ani.data.expected_serial_number, |
| 695 | admin_state=AdminState.ENABLED if v_ont_ani.interface.enabled |
rshetty | c26a3c3 | 2017-07-27 11:06:38 +0530 | [diff] [blame] | 696 | else AdminState.PREPROVISIONED) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 697 | return |
| 698 | |
Nikolay Titov | d82b2fc | 2017-10-06 00:24:37 -0400 | [diff] [blame] | 699 | def update_onu_device(self, olt_device, onu_device, v_ont_ani): |
| 700 | log.info('update-onu-device', olt_device_id=olt_device.id, |
| 701 | onu_device_id=onu_device.id, v_ont_ani=v_ont_ani) |
| 702 | adapter_agent = self.get_device_adapter_agent(olt_device) |
| 703 | new_admin_state = AdminState.ENABLED if v_ont_ani.interface.enabled \ |
| 704 | else AdminState.DISABLED |
| 705 | if onu_device.admin_state != new_admin_state: |
| 706 | log.info('update-onu-device-admin-state', |
| 707 | onu_device_id=onu_device.id, |
| 708 | new_admin_state=new_admin_state) |
| 709 | onu_device.admin_state = new_admin_state |
| 710 | self.core.get_proxy('/').update('/devices/{}'.format(onu_device.id), |
| 711 | onu_device) |
| 712 | |
Nikolay Titov | fae5c91 | 2017-08-01 15:09:59 -0400 | [diff] [blame] | 713 | def delete_onu_device(self, olt_device, onu_device): |
| 714 | log.info('delete-onu-device', olt_device_id=olt_device.id, |
| 715 | onu_device_id=onu_device.id) |
| 716 | adapter_agent = self.get_device_adapter_agent(olt_device) |
| 717 | adapter_agent.delete_child_device(olt_device.id, onu_device.id) |
Nikolay Titov | 89004ec | 2017-06-19 18:22:42 -0400 | [diff] [blame] | 718 | return |