Matteo Scandolo | 72f43d0 | 2018-07-16 10:54:01 -0400 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 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 | |
Matteo Scandolo | 72f43d0 | 2018-07-16 10:54:01 -0400 | [diff] [blame] | 15 | from xosapi.orm import ORMWrapper, register_convenience_wrapper |
| 16 | from xosapi.convenience.service import ORMWrapperService |
| 17 | |
| 18 | import logging as log |
| 19 | |
Zack Williams | f19a610 | 2018-11-02 10:52:15 -0700 | [diff] [blame] | 20 | |
Matteo Scandolo | 72f43d0 | 2018-07-16 10:54:01 -0400 | [diff] [blame] | 21 | class ORMWrapperVOLTService(ORMWrapperService): |
| 22 | |
| 23 | def get_onu_sn_from_openflow(self, dp_id, port_no): |
| 24 | """Return the ONU serial number from logical_device informations |
Zack Williams | f19a610 | 2018-11-02 10:52:15 -0700 | [diff] [blame] | 25 | |
Matteo Scandolo | 72f43d0 | 2018-07-16 10:54:01 -0400 | [diff] [blame] | 26 | example usage: |
| 27 | volt = VOLTService.objects.first() |
| 28 | sn = volt.get_onu_from_openflow("of:0000000ce2314000", 2) |
| 29 | # BRCM1234 |
| 30 | |
| 31 | Arguments: |
| 32 | dp_id {string} -- The openflow id of the OLT device |
| 33 | port_no {int} -- The openflow port id (UNI Port) |
Zack Williams | f19a610 | 2018-11-02 10:52:15 -0700 | [diff] [blame] | 34 | |
Matteo Scandolo | 72f43d0 | 2018-07-16 10:54:01 -0400 | [diff] [blame] | 35 | Returns: |
| 36 | string -- ONU Serial Number |
| 37 | """ |
| 38 | |
Zack Williams | f19a610 | 2018-11-02 10:52:15 -0700 | [diff] [blame] | 39 | log.debug("Searching ONUDevice for %s:%s" % (dp_id, port_no)) |
Matteo Scandolo | 72f43d0 | 2018-07-16 10:54:01 -0400 | [diff] [blame] | 40 | try: |
| 41 | olt = self.stub.OLTDevice.objects.get(dp_id=dp_id) |
| 42 | uni_ports = self.stub.UNIPort.objects.filter(port_no=port_no) |
| 43 | onu = [o.onu_device for o in uni_ports if o.onu_device.pon_port.olt_device.id == olt.id][0] |
| 44 | return onu.serial_number |
| 45 | except IndexError: |
Zack Williams | f19a610 | 2018-11-02 10:52:15 -0700 | [diff] [blame] | 46 | log.error("Can't find ONU for %s:%s" % (dp_id, port_no)) |
Matteo Scandolo | 72f43d0 | 2018-07-16 10:54:01 -0400 | [diff] [blame] | 47 | except Exception: |
Zack Williams | f19a610 | 2018-11-02 10:52:15 -0700 | [diff] [blame] | 48 | log.exception("Error while finding ONUDevice for %s:%s" % (dp_id, port_no)) |
Matteo Scandolo | 72f43d0 | 2018-07-16 10:54:01 -0400 | [diff] [blame] | 49 | |
Zack Williams | f19a610 | 2018-11-02 10:52:15 -0700 | [diff] [blame] | 50 | |
| 51 | register_convenience_wrapper("VOLTService", ORMWrapperVOLTService) |