blob: 321704f5a49437d9c63de9e4cb6be9f42f7c2996 [file] [log] [blame]
ivoutsas69b97632016-05-25 13:36:44 +03001/*
2 * Copyright 2016-present Open Networking Laboratory
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.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<>();
121 intfs.add(new DefaultPortDescription(INTF1_PORT, IS_ENABLED, COPPER, CONNECTION_SPEED_ETHERNET,
122 int1Annotations.build()));
123 intfs.add(new DefaultPortDescription(INTF2_PORT, IS_NOT_ENABLED, COPPER, CONNECTION_SPEED_ETHERNET,
124 int2Annotations.build()));
125 intfs.add(new DefaultPortDescription(INTF3_PORT, IS_NOT_ENABLED, COPPER, CONNECTION_SPEED_ETHERNET,
126 int3Annotations.build()));
127 intfs.add(new DefaultPortDescription(INTF4_PORT, IS_ENABLED, COPPER, CONNECTION_SPEED_SERIAL,
128 int4Annotations.build()));
129 intfs.add(new DefaultPortDescription(INTF5_PORT, IS_ENABLED, FIBER, CONNECTION_SPEED_POS,
130 int5Annotations.build()));
131 intfs.add(new DefaultPortDescription(INTF6_PORT, IS_ENABLED, FIBER, CONNECTION_SPEED_FDDI,
132 int6Annotations.build()));
133 return intfs;
134 }
ivoutsase78f9882016-06-28 23:32:14 +0300135
ivoutsas69b97632016-05-25 13:36:44 +0300136}