Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016 Open Networking Foundation |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 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 | package org.onosproject.drivers.juniper; |
| 18 | |
| 19 | |
| 20 | import com.google.common.annotations.Beta; |
Michele Santuari | f594537 | 2017-01-19 16:39:21 +0100 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableList; |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.device.DeviceDescription; |
| 24 | import org.onosproject.net.device.DeviceDescriptionDiscovery; |
| 25 | import org.onosproject.net.device.PortDescription; |
Yuta HIGUCHI | 234eaf3 | 2017-09-06 13:45:05 -0700 | [diff] [blame] | 26 | import org.onosproject.netconf.NetconfException; |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 27 | import org.onosproject.netconf.NetconfSession; |
Yuta HIGUCHI | 0184a7b | 2017-03-31 13:13:58 -0700 | [diff] [blame] | 28 | import org.slf4j.Logger; |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 29 | |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 30 | import java.util.List; |
| 31 | |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 32 | import static org.onosproject.drivers.juniper.JuniperUtils.REQ_IF_INFO; |
| 33 | import static org.onosproject.drivers.juniper.JuniperUtils.REQ_MAC_ADD_INFO; |
| 34 | import static org.onosproject.drivers.juniper.JuniperUtils.REQ_SYS_INFO; |
| 35 | import static org.onosproject.drivers.juniper.JuniperUtils.requestBuilder; |
Yuta HIGUCHI | 0184a7b | 2017-03-31 13:13:58 -0700 | [diff] [blame] | 36 | import static org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString; |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 37 | import static org.slf4j.LoggerFactory.getLogger; |
| 38 | |
| 39 | /** |
| 40 | * Retrieve the Device information and ports via NETCONF for Juniper Router. |
| 41 | * Tested with MX240 junos 14.2 |
| 42 | */ |
| 43 | @Beta |
Kieran McPeake | 9e64ab5 | 2019-06-07 10:22:29 +0100 | [diff] [blame^] | 44 | public class DeviceDiscoveryJuniperImpl extends JuniperAbstractHandlerBehaviour |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 45 | implements DeviceDescriptionDiscovery { |
| 46 | |
Yuta HIGUCHI | 0184a7b | 2017-03-31 13:13:58 -0700 | [diff] [blame] | 47 | private final Logger log = getLogger(getClass()); |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 48 | |
| 49 | @Override |
| 50 | public DeviceDescription discoverDeviceDetails() { |
Michele Santuari | f594537 | 2017-01-19 16:39:21 +0100 | [diff] [blame] | 51 | DeviceId devId = handler().data().deviceId(); |
Kieran McPeake | 9e64ab5 | 2019-06-07 10:22:29 +0100 | [diff] [blame^] | 52 | NetconfSession session = lookupNetconfSession(devId); |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 53 | String sysInfo; |
Kieran McPeake | e1b418f | 2019-05-23 13:42:13 +0100 | [diff] [blame] | 54 | String chassisMacAddresses; |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 55 | try { |
| 56 | sysInfo = session.get(requestBuilder(REQ_SYS_INFO)); |
Kieran McPeake | e1b418f | 2019-05-23 13:42:13 +0100 | [diff] [blame] | 57 | chassisMacAddresses = session.get(requestBuilder(REQ_MAC_ADD_INFO)); |
Yuta HIGUCHI | 234eaf3 | 2017-09-06 13:45:05 -0700 | [diff] [blame] | 58 | } catch (NetconfException e) { |
Michele Santuari | f594537 | 2017-01-19 16:39:21 +0100 | [diff] [blame] | 59 | log.warn("Failed to retrieve device details for {}", devId); |
| 60 | return null; |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 61 | } |
Yuta HIGUCHI | 0184a7b | 2017-03-31 13:13:58 -0700 | [diff] [blame] | 62 | log.trace("Device {} system-information {}", devId, sysInfo); |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 63 | DeviceDescription description = |
Yuta HIGUCHI | 0184a7b | 2017-03-31 13:13:58 -0700 | [diff] [blame] | 64 | JuniperUtils.parseJuniperDescription(devId, |
Kieran McPeake | e1b418f | 2019-05-23 13:42:13 +0100 | [diff] [blame] | 65 | loadXmlString(sysInfo), |
| 66 | chassisMacAddresses); |
Yuta HIGUCHI | 0184a7b | 2017-03-31 13:13:58 -0700 | [diff] [blame] | 67 | log.debug("Device {} description {}", devId, description); |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 68 | return description; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public List<PortDescription> discoverPortDetails() { |
Michele Santuari | f594537 | 2017-01-19 16:39:21 +0100 | [diff] [blame] | 73 | DeviceId devId = handler().data().deviceId(); |
Kieran McPeake | 9e64ab5 | 2019-06-07 10:22:29 +0100 | [diff] [blame^] | 74 | NetconfSession session = lookupNetconfSession(devId); |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 75 | String reply; |
| 76 | try { |
| 77 | reply = session.get(requestBuilder(REQ_IF_INFO)); |
Yuta HIGUCHI | 234eaf3 | 2017-09-06 13:45:05 -0700 | [diff] [blame] | 78 | } catch (NetconfException e) { |
Kieran McPeake | e1b418f | 2019-05-23 13:42:13 +0100 | [diff] [blame] | 79 | log.warn("Failed to retrieve interface-information for device {}", devId); |
Michele Santuari | f594537 | 2017-01-19 16:39:21 +0100 | [diff] [blame] | 80 | return ImmutableList.of(); |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 81 | } |
Yuta HIGUCHI | 0184a7b | 2017-03-31 13:13:58 -0700 | [diff] [blame] | 82 | log.trace("Device {} interface-information {}", devId, reply); |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 83 | List<PortDescription> descriptions = |
Yuta HIGUCHI | 0184a7b | 2017-03-31 13:13:58 -0700 | [diff] [blame] | 84 | JuniperUtils.parseJuniperPorts(loadXmlString(reply)); |
| 85 | log.debug("Device {} Discovered ports {}", devId, descriptions); |
Michele Santuari | 21c1401 | 2016-11-14 13:31:33 +0100 | [diff] [blame] | 86 | return descriptions; |
| 87 | } |
| 88 | } |