blob: 5b9bf92b5008da8ee97718e08cb154c30ea3f655 [file] [log] [blame]
ivoutsas69b97632016-05-25 13:36:44 +03001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
ivoutsas69b97632016-05-25 13:36:44 +03003 *
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.cisco;
18
19
20import org.junit.Test;
ivoutsase78f9882016-06-28 23:32:14 +030021import org.onlab.packet.ChassisId;
ivoutsas69b97632016-05-25 13:36:44 +030022import org.onosproject.net.AnnotationKeys;
23import org.onosproject.net.DefaultAnnotations;
ivoutsase78f9882016-06-28 23:32:14 +030024import org.onosproject.net.DefaultDevice;
25import org.onosproject.net.DeviceId;
ivoutsas69b97632016-05-25 13:36:44 +030026import org.onosproject.net.Port;
27import org.onosproject.net.PortNumber;
28import org.onosproject.net.device.DefaultPortDescription;
29import org.onosproject.net.device.PortDescription;
ivoutsase78f9882016-06-28 23:32:14 +030030import org.onosproject.net.provider.ProviderId;
ivoutsas69b97632016-05-25 13:36:44 +030031import java.io.InputStream;
ivoutsas69b97632016-05-25 13:36:44 +030032import java.util.ArrayList;
33import java.util.List;
ivoutsase78f9882016-06-28 23:32:14 +030034import java.util.Scanner;
ivoutsas69b97632016-05-25 13:36:44 +030035import static org.junit.Assert.assertEquals;
ivoutsase78f9882016-06-28 23:32:14 +030036import static org.onosproject.net.Device.Type.SWITCH;
37import static org.onosproject.net.DeviceId.deviceId;
38
ivoutsas69b97632016-05-25 13:36:44 +030039
40/**
41 * Tests the parser for Netconf TextBlock configurations and replies from Cisco devices.
42 */
43public class TextBlockParserCiscoTest {
44
45 private static final PortNumber INTF1_PORT = PortNumber.portNumber(0);
46 private static final String INTF1_NAME = "FastEthernet0/0";
47 private static final PortNumber INTF2_PORT = PortNumber.portNumber(0);
48 private static final String INTF2_NAME = "Ethernet1/0";
49 private static final PortNumber INTF3_PORT = PortNumber.portNumber(0);
50 private static final String INTF3_NAME = "GigabitEthernet2/0";
51 private static final PortNumber INTF4_PORT = PortNumber.portNumber(0);
52 private static final String INTF4_NAME = "Serial3/0";
53 private static final PortNumber INTF5_PORT = PortNumber.portNumber(0);
54 private static final String INTF5_NAME = "POS4/0";
55 private static final PortNumber INTF6_PORT = PortNumber.portNumber(0);
56 private static final String INTF6_NAME = "Fddi5/0";
57 private static final Port.Type COPPER = Port.Type.COPPER;
58 private static final Port.Type FIBER = Port.Type.FIBER;
59 private static final long CONNECTION_SPEED_ETHERNET = 100000;
60 private static final long CONNECTION_SPEED_SERIAL = 1544;
61 private static final long CONNECTION_SPEED_POS = 9952000;
62 private static final long CONNECTION_SPEED_FDDI = 100000;
63 private static final boolean IS_ENABLED = true;
64 private static final boolean IS_NOT_ENABLED = false;
ivoutsase78f9882016-06-28 23:32:14 +030065 private static final String SHOW_VERSION = "/testShowVersion.xml";
66 private static final String SHOW_INTFS = "/testShowInterfaces.xml";
67 private static final String SW = "IOS C3560E 15.0(2)EJ";
68 private static final String HW = "SM-X-ES3-24-P";
69 private static final String MFR = "Cisco";
70 private static final String SN = "FOC18401Z3R";
71 private static final ProviderId PROVIDERID = new ProviderId("of", "foo");
72 private static final DeviceId DEVICE = deviceId("of:foo");
73 private static final ChassisId CID = new ChassisId();
ivoutsas69b97632016-05-25 13:36:44 +030074
75 @Test
ivoutsase78f9882016-06-28 23:32:14 +030076 public void controllersVersion() {
77 InputStream streamOrig = getClass().getResourceAsStream(SHOW_VERSION);
78 String version = new Scanner(streamOrig, "UTF-8").useDelimiter("\\Z").next();
79 version = version.substring(version.indexOf('\n') + 1);
80 String[] actualDetails = TextBlockParserCisco.parseCiscoIosDeviceDetails(version);
81
82 assertEquals("Information could not be retrieved",
83 getExpectedInfo(), actualInfo(actualDetails));
84 }
85
86 @Test
87 public void controllersIntfs() {
88 InputStream streamOrig = getClass().getResourceAsStream(SHOW_INTFS);
ivoutsas69b97632016-05-25 13:36:44 +030089 String rpcReply = new Scanner(streamOrig, "UTF-8").useDelimiter("\\Z").next();
90 List<PortDescription> actualIntfs = TextBlockParserCisco.parseCiscoIosPorts(rpcReply);
ivoutsase78f9882016-06-28 23:32:14 +030091 assertEquals("Information could not be retrieved",
ivoutsas69b97632016-05-25 13:36:44 +030092 getExpectedIntfs(), actualIntfs);
93 }
94
ivoutsase78f9882016-06-28 23:32:14 +030095 private DefaultDevice getExpectedInfo() {
96 return new DefaultDevice(PROVIDERID, DEVICE, SWITCH, MFR, HW, SW, SN, CID);
97 }
98
99 private DefaultDevice actualInfo(String[] actualDetails) {
100
101 return new DefaultDevice(PROVIDERID, DEVICE, SWITCH, actualDetails[0],
102 actualDetails[1], actualDetails[2],
103 actualDetails[3], CID);
104 }
105
ivoutsas69b97632016-05-25 13:36:44 +0300106 private List<PortDescription> getExpectedIntfs() {
107 DefaultAnnotations.Builder int1Annotations = DefaultAnnotations.builder()
108 .set(AnnotationKeys.PORT_NAME, INTF1_NAME);
109 DefaultAnnotations.Builder int2Annotations = DefaultAnnotations.builder()
110 .set(AnnotationKeys.PORT_NAME, INTF2_NAME);
111 DefaultAnnotations.Builder int3Annotations = DefaultAnnotations.builder()
112 .set(AnnotationKeys.PORT_NAME, INTF3_NAME);
113 DefaultAnnotations.Builder int4Annotations = DefaultAnnotations.builder()
114 .set(AnnotationKeys.PORT_NAME, INTF4_NAME);
115 DefaultAnnotations.Builder int5Annotations = DefaultAnnotations.builder()
116 .set(AnnotationKeys.PORT_NAME, INTF5_NAME);
117 DefaultAnnotations.Builder int6Annotations = DefaultAnnotations.builder()
118 .set(AnnotationKeys.PORT_NAME, INTF6_NAME);
119
120 List<PortDescription> intfs = new ArrayList<>();
Yuta HIGUCHI53e47962018-03-01 23:50:48 -0800121 intfs.add(DefaultPortDescription.builder().withPortNumber(INTF1_PORT).isEnabled(IS_ENABLED)
122 .type(COPPER).portSpeed(CONNECTION_SPEED_ETHERNET)
123 .annotations(int1Annotations.build()).build());
124 intfs.add(DefaultPortDescription.builder().withPortNumber(INTF2_PORT).isEnabled(IS_NOT_ENABLED)
125 .type(COPPER).portSpeed(CONNECTION_SPEED_ETHERNET)
126 .annotations(int2Annotations.build()).build());
127 intfs.add(DefaultPortDescription.builder().withPortNumber(INTF3_PORT).isEnabled(IS_NOT_ENABLED)
128 .type(COPPER).portSpeed(CONNECTION_SPEED_ETHERNET)
129 .annotations(int3Annotations.build()).build());
130 intfs.add(DefaultPortDescription.builder().withPortNumber(INTF4_PORT).isEnabled(IS_ENABLED)
131 .type(COPPER).portSpeed(CONNECTION_SPEED_SERIAL)
132 .annotations(int4Annotations.build()).build());
133 intfs.add(DefaultPortDescription.builder().withPortNumber(INTF5_PORT).isEnabled(IS_ENABLED)
134 .type(FIBER).portSpeed(CONNECTION_SPEED_POS)
135 .annotations(int5Annotations.build()).build());
136 intfs.add(DefaultPortDescription.builder().withPortNumber(INTF6_PORT).isEnabled(IS_ENABLED)
137 .type(FIBER).portSpeed(CONNECTION_SPEED_FDDI)
138 .annotations(int6Annotations.build()).build());
ivoutsas69b97632016-05-25 13:36:44 +0300139 return intfs;
140 }
ivoutsase78f9882016-06-28 23:32:14 +0300141
ivoutsas69b97632016-05-25 13:36:44 +0300142}