blob: 5898612f7deef166e19f7e8aa0767e151bb92326 [file] [log] [blame]
Kieran McPeakebc00cb52019-05-23 13:07:25 +01001/*
2 * Copyright 2019-present Open Networking Foundation
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
17package org.onosproject.drivers.juniper;
18
19
20import static org.hamcrest.Matchers.*;
21import static org.junit.Assert.assertEquals;
22import static org.junit.Assert.assertThat;
23import static org.onosproject.net.Device.Type.ROUTER;
24
25import org.apache.commons.configuration.HierarchicalConfiguration;
26import org.junit.Test;
27import org.onlab.packet.ChassisId;
28import org.onosproject.drivers.utilities.XmlConfigParser;
29import org.onosproject.net.DeviceId;
30import org.onosproject.net.device.DefaultDeviceDescription;
31import org.onosproject.net.device.DeviceDescription;
32
33import java.io.IOException;
34import java.io.InputStreamReader;
35import java.net.URI;
36
37import com.google.common.io.CharStreams;
38
39public class JuniperUtilsTest {
40
41
42 private static final String DEVICE_ID = "netconf:1.2.3.4:830";
43 private final DeviceId deviceId = DeviceId.deviceId(DEVICE_ID);
44
45 @Test
46 public void testDeviceDescriptionParsedFromJunos15() throws IOException {
47
48 HierarchicalConfiguration getSystemInfoResp = XmlConfigParser.loadXml(
49 getClass().getResourceAsStream("/Junos_get-system-information_response_15.1.xml"));
50 String chassisText = CharStreams.toString(
51 new InputStreamReader(
52 getClass().getResourceAsStream("/Junos_get-chassis-mac-addresses_response_15.1.xml")));
53
54 DeviceDescription actual = JuniperUtils.parseJuniperDescription(deviceId, getSystemInfoResp, chassisText);
55 DeviceDescription expected =
56 new DefaultDeviceDescription(URI.create(DEVICE_ID), ROUTER, "JUNIPER", "mx240",
57 "junos 15.1R5.5", "JN11AC665AFC", new ChassisId("8418889983c0"));
58
59 assertEquals(expected, actual);
60
61 }
62
63
64 @Test
65 public void testDeviceDescriptionParsedFromJunos19() throws IOException {
66
67 HierarchicalConfiguration getSystemInfoResp = XmlConfigParser.loadXml(
68 getClass().getResourceAsStream("/Junos_get-system-information_response_19.2.xml"));
69 String chassisText = CharStreams.toString(
70 new InputStreamReader(
71 getClass().getResourceAsStream("/Junos_get-chassis-mac-addresses_response_19.2.xml")));
72
73 DeviceDescription actual = JuniperUtils.parseJuniperDescription(deviceId, getSystemInfoResp, chassisText);
74 DeviceDescription expected =
75 new DefaultDeviceDescription(URI.create(DEVICE_ID), ROUTER, "JUNIPER", "acx6360-or",
76 "junos 19.2I-20190228_dev_common.0.2316", "DX004", new ChassisId("f4b52f1f81c0"));
77
78 assertEquals(expected, actual);
79
80 }
81
82
83 @Test
84 public void testLinkAbstractionToString() throws IOException {
85 final JuniperUtils.LinkAbstraction x = new JuniperUtils.LinkAbstraction("foo", 1, 2, null, null);
86 assertThat("Null attributes excluded", x.toString(), allOf(
87 containsString("LinkAbstraction"),
88 containsString("localPortName=foo"),
89 not(containsString("remotePortDescription"))));
90
91
92 }
93
94
95
96}