blob: bd87be8d6ab883eb2fdeafc42c89357adbff4468 [file] [log] [blame]
Michele Santuari21c14012016-11-14 13:31:33 +01001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016 Open Networking Foundation
Michele Santuari21c14012016-11-14 13:31:33 +01003 *
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
17package org.onosproject.drivers.juniper;
18
19
20import com.google.common.annotations.Beta;
Michele Santuarif5945372017-01-19 16:39:21 +010021import com.google.common.collect.ImmutableList;
Michele Santuari21c14012016-11-14 13:31:33 +010022import org.onosproject.net.DeviceId;
23import org.onosproject.net.device.DeviceDescription;
24import org.onosproject.net.device.DeviceDescriptionDiscovery;
25import org.onosproject.net.device.PortDescription;
Yuta HIGUCHI234eaf32017-09-06 13:45:05 -070026import org.onosproject.netconf.NetconfException;
Michele Santuari21c14012016-11-14 13:31:33 +010027import org.onosproject.netconf.NetconfSession;
Yuta HIGUCHI0184a7b2017-03-31 13:13:58 -070028import org.slf4j.Logger;
Michele Santuari21c14012016-11-14 13:31:33 +010029
Michele Santuari21c14012016-11-14 13:31:33 +010030import java.util.List;
31
Michele Santuari21c14012016-11-14 13:31:33 +010032import static org.onosproject.drivers.juniper.JuniperUtils.REQ_IF_INFO;
33import static org.onosproject.drivers.juniper.JuniperUtils.REQ_MAC_ADD_INFO;
34import static org.onosproject.drivers.juniper.JuniperUtils.REQ_SYS_INFO;
35import static org.onosproject.drivers.juniper.JuniperUtils.requestBuilder;
Yuta HIGUCHI0184a7b2017-03-31 13:13:58 -070036import static org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString;
Michele Santuari21c14012016-11-14 13:31:33 +010037import 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 McPeake9e64ab52019-06-07 10:22:29 +010044public class DeviceDiscoveryJuniperImpl extends JuniperAbstractHandlerBehaviour
Michele Santuari21c14012016-11-14 13:31:33 +010045 implements DeviceDescriptionDiscovery {
46
Yuta HIGUCHI0184a7b2017-03-31 13:13:58 -070047 private final Logger log = getLogger(getClass());
Michele Santuari21c14012016-11-14 13:31:33 +010048
49 @Override
50 public DeviceDescription discoverDeviceDetails() {
Michele Santuarif5945372017-01-19 16:39:21 +010051 DeviceId devId = handler().data().deviceId();
Kieran McPeake9e64ab52019-06-07 10:22:29 +010052 NetconfSession session = lookupNetconfSession(devId);
Michele Santuari21c14012016-11-14 13:31:33 +010053 String sysInfo;
Kieran McPeakee1b418f2019-05-23 13:42:13 +010054 String chassisMacAddresses;
Michele Santuari21c14012016-11-14 13:31:33 +010055 try {
56 sysInfo = session.get(requestBuilder(REQ_SYS_INFO));
Kieran McPeakee1b418f2019-05-23 13:42:13 +010057 chassisMacAddresses = session.get(requestBuilder(REQ_MAC_ADD_INFO));
Yuta HIGUCHI234eaf32017-09-06 13:45:05 -070058 } catch (NetconfException e) {
Michele Santuarif5945372017-01-19 16:39:21 +010059 log.warn("Failed to retrieve device details for {}", devId);
60 return null;
Michele Santuari21c14012016-11-14 13:31:33 +010061 }
Yuta HIGUCHI0184a7b2017-03-31 13:13:58 -070062 log.trace("Device {} system-information {}", devId, sysInfo);
Michele Santuari21c14012016-11-14 13:31:33 +010063 DeviceDescription description =
Yuta HIGUCHI0184a7b2017-03-31 13:13:58 -070064 JuniperUtils.parseJuniperDescription(devId,
Kieran McPeakee1b418f2019-05-23 13:42:13 +010065 loadXmlString(sysInfo),
66 chassisMacAddresses);
Yuta HIGUCHI0184a7b2017-03-31 13:13:58 -070067 log.debug("Device {} description {}", devId, description);
Michele Santuari21c14012016-11-14 13:31:33 +010068 return description;
69 }
70
71 @Override
72 public List<PortDescription> discoverPortDetails() {
Michele Santuarif5945372017-01-19 16:39:21 +010073 DeviceId devId = handler().data().deviceId();
Kieran McPeake9e64ab52019-06-07 10:22:29 +010074 NetconfSession session = lookupNetconfSession(devId);
Michele Santuari21c14012016-11-14 13:31:33 +010075 String reply;
76 try {
77 reply = session.get(requestBuilder(REQ_IF_INFO));
Yuta HIGUCHI234eaf32017-09-06 13:45:05 -070078 } catch (NetconfException e) {
Kieran McPeakee1b418f2019-05-23 13:42:13 +010079 log.warn("Failed to retrieve interface-information for device {}", devId);
Michele Santuarif5945372017-01-19 16:39:21 +010080 return ImmutableList.of();
Michele Santuari21c14012016-11-14 13:31:33 +010081 }
Yuta HIGUCHI0184a7b2017-03-31 13:13:58 -070082 log.trace("Device {} interface-information {}", devId, reply);
Michele Santuari21c14012016-11-14 13:31:33 +010083 List<PortDescription> descriptions =
Yuta HIGUCHI0184a7b2017-03-31 13:13:58 -070084 JuniperUtils.parseJuniperPorts(loadXmlString(reply));
85 log.debug("Device {} Discovered ports {}", devId, descriptions);
Michele Santuari21c14012016-11-14 13:31:33 +010086 return descriptions;
87 }
88}