blob: 20e80a12faf473066d2036d2c2e3188f84c248f1 [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
2 * Copyright 2017-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 */
16package org.onosproject.drivers.microsemi;
17
18import static junit.framework.TestCase.fail;
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertFalse;
21import static org.junit.Assert.assertNotNull;
22import static org.junit.Assert.assertTrue;
23
24import org.junit.Before;
25import org.junit.Ignore;
26import org.junit.Test;
27import org.onosproject.drivers.microsemi.yang.utils.MaNameUtil;
28import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMepLbCreate;
29import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority;
30import org.onosproject.incubator.net.l2monitoring.cfm.MepEntry;
31import org.onosproject.incubator.net.l2monitoring.cfm.MepLbCreate;
32import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.InterfaceStatusTlvType;
33import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.PortStatusTlvType;
34import org.onosproject.incubator.net.l2monitoring.cfm.RemoteMepEntry.RemoteMepState;
35import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr;
36import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
37import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
38import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr;
39import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
40import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
41import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.MdNameAndTypeCombo;
42import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.MaNameAndTypeCombo;
43
Sean Condon1dbcd712017-10-19 12:09:21 +010044import java.util.BitSet;
45
Sean Condon0e89bda2017-03-21 14:23:19 +000046/**
47 * Test of the CFM implementation on EA1000 through the incubator/net/l2monitoring interface.
48 */
49public class EA1000CfmMepProgrammableTest {
50 EA1000CfmMepProgrammable cfmProgrammable;
Sean Condon1dbcd712017-10-19 12:09:21 +010051 public static final MdId MD_ID_1 = MdIdCharStr.asMdId("md-1");
52 public static final MaIdShort MA_ID_11 = MaIdCharStr.asMaId("ma-1-1");
53 public static final MepId MEP_111 = MepId.valueOf((short) 1);
54 public static final MepId MEP_112 = MepId.valueOf((short) 2);
Sean Condon0e89bda2017-03-21 14:23:19 +000055
56 @Before
57 public void setUp() throws Exception {
58 cfmProgrammable = new EA1000CfmMepProgrammable();
59 cfmProgrammable.setHandler(new MockEa1000DriverHandler());
60 assertNotNull(cfmProgrammable.handler().data().deviceId());
61 }
62
63
64 @Ignore
65 @Test
66 public void testCreateMep() {
67 fail("Not yet implemented");
68 }
69
70 @Ignore
71 @Test
72 public void testGetAllMeps() {
73 fail("Not yet implemented");
74 }
75
76 @Test
77 public void testGetMep() throws CfmConfigException {
Sean Condon1dbcd712017-10-19 12:09:21 +010078 MepEntry mepEntry = cfmProgrammable.getMep(MD_ID_1, MA_ID_11, MEP_111);
Sean Condon0e89bda2017-03-21 14:23:19 +000079
80 //Result will come from MockNetconfSessionEa1000.SAMPLE_MSEACFM_MD_MA_MEP_FULL_REPLY
81 assertNotNull(mepEntry);
82 assertTrue(mepEntry.administrativeState());
83 assertTrue(mepEntry.cciEnabled());
84 assertEquals(Priority.PRIO5.name(), mepEntry.ccmLtmPriority().name());
85
Sean Condon1dbcd712017-10-19 12:09:21 +010086 assertTrue("Expecting remote-mac-error", mepEntry.activeMacStatusDefect()); //remote-mac-error
87 assertTrue("Expecting remote-rdi", mepEntry.activeRdiCcmDefect()); //remote-rdi
Sean Condon0e89bda2017-03-21 14:23:19 +000088
89 assertNotNull(mepEntry.activeRemoteMepList());
90
Sean Condon1dbcd712017-10-19 12:09:21 +010091//FIXME Waiting on patch https://gerrit.onosproject.org/#/c/15778/
92// assertEquals("Expecting 2 Remote Meps", 2, mepEntry.activeRemoteMepList().size());
93 mepEntry.activeRemoteMepList().forEach(rmep -> {
94 if (rmep.remoteMepId().value() == 1) {
95 assertEquals(RemoteMepState.RMEP_FAILED.name(),
96 rmep.state().toString());
97 assertEquals(54654654L, rmep.failedOrOkTime().toMillis());
98 assertEquals("aa:bb:cc:dd:ee:ff".toUpperCase(), rmep.macAddress().toString());
99 assertFalse(rmep.rdi());
100 assertEquals(PortStatusTlvType.PS_NO_STATUS_TLV.name(),
101 rmep.portStatusTlvType().toString());
102 assertEquals(InterfaceStatusTlvType.IS_DORMANT.name(),
103 rmep.interfaceStatusTlvType().toString());
104 }
105 });
106
107 }
108
109 @Test
110 public void testGetMep2() throws CfmConfigException {
111 MepEntry mepEntry = cfmProgrammable.getMep(MD_ID_1, MA_ID_11, MEP_112);
112
113 //Result will come from MockNetconfSessionEa1000.SAMPLE_MSEACFM_MD_MA_MEP_FULL_REPLY
114 assertNotNull(mepEntry);
115 assertTrue(mepEntry.administrativeState());
116 assertTrue(mepEntry.cciEnabled());
117 assertEquals(Priority.PRIO4.name(), mepEntry.ccmLtmPriority().name());
118
119 assertNotNull(mepEntry.activeRemoteMepList());
120 BitSet bs1 = new BitSet();
121 bs1.clear();
122//FIXME Waiting on patch https://gerrit.onosproject.org/#/c/15778/
Sean Condon0e89bda2017-03-21 14:23:19 +0000123// assertEquals("Expecting 2 Remote Meps", 2, mepEntry.activeRemoteMepList().size());
124 mepEntry.activeRemoteMepList().forEach(rmep -> {
125 if (rmep.remoteMepId().value() == 1) {
126 assertEquals(RemoteMepState.RMEP_FAILED.name(),
127 rmep.state().toString());
128 assertEquals(54654654L, rmep.failedOrOkTime().toMillis());
129 assertEquals("aa:bb:cc:dd:ee:ff".toUpperCase(), rmep.macAddress().toString());
130 assertFalse(rmep.rdi());
131 assertEquals(PortStatusTlvType.PS_NO_STATUS_TLV.name(),
132 rmep.portStatusTlvType().toString());
133 assertEquals(InterfaceStatusTlvType.IS_DORMANT.name(),
134 rmep.interfaceStatusTlvType().toString());
135 }
136 });
137
138 }
139
140 /**
141 * For sampleXmlRegexDeleteMseaCfmMep.
142 * @throws CfmConfigException If an error occurs
143 */
144 @Test
145 public void testDeleteMep() throws CfmConfigException {
Sean Condon1dbcd712017-10-19 12:09:21 +0100146 assertTrue(cfmProgrammable.deleteMep(MD_ID_1, MA_ID_11, MEP_111));
Sean Condon0e89bda2017-03-21 14:23:19 +0000147 }
148
149 /**
150 * For sampleXmlRegexTransmitLoopback.
151 * @throws CfmConfigException If an error occurs
152 */
153 @Test
154 public void testTransmitLoopback() throws CfmConfigException {
155 MepLbCreate.MepLbCreateBuilder lbCreate =
156 DefaultMepLbCreate.builder(MepId.valueOf((short) 12));
157 lbCreate.numberMessages(5);
158// lbCreate.dataTlvHex("AA:BB:CC:DD:EE");
159 lbCreate.vlanPriority(Priority.PRIO3);
160 lbCreate.vlanDropEligible(true);
161
Sean Condon1dbcd712017-10-19 12:09:21 +0100162 cfmProgrammable.transmitLoopback(MD_ID_1, MA_ID_11, MEP_111, lbCreate.build());
Sean Condon0e89bda2017-03-21 14:23:19 +0000163 }
164
165 @Test
166 public void testAbortLoopback() throws CfmConfigException {
Sean Condon1dbcd712017-10-19 12:09:21 +0100167 cfmProgrammable.abortLoopback(MD_ID_1, MA_ID_11, MEP_111);
Sean Condon0e89bda2017-03-21 14:23:19 +0000168 }
169
170// @Test
171// public void testTransmitLinktrace() {
172// fail("Not yet implemented");
173// }
174
175 @Test
176 public void testGetYangMdNameFromApiMdId() throws CfmConfigException {
177 MdNameAndTypeCombo name = EA1000CfmMepProgrammable
178 .getYangMdNameFromApiMdId(MdIdCharStr.asMdId("md-1"));
179
180 assertEquals(org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm
181 .maintenancedomain.mdnameandtypecombo
182 .DefaultNameCharacterString.class, name.getClass());
183
184//There's a problem with checkstyle for typecast on really long paths
185// assertEquals("md-1", ((org.onosproject.yang.gen.v1.http.www.microsemi.com
186// .microsemi.edge.assure.msea.cfm.rev20160229.mseacfm.mefcfm
187// .maintenancedomain.mdnameandtypecombo
188// .DefaultNameCharacterString) name).name().string());
189 }
190
191 @Test
192 public void testGetYangMaNameFromApiMaId() throws CfmConfigException {
193 MaNameAndTypeCombo name = MaNameUtil
194 .getYangMaNameFromApiMaId(MaIdCharStr.asMaId("ma-1-1"));
195 assertEquals(org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm
196 .maintenancedomain.maintenanceassociation.manameandtypecombo
197 .DefaultNameCharacterString.class, name.getClass());
198
199//There's a problem with checkstyle for typecast on really long paths
200// assertEquals("ma-1-1", ((org.onosproject.yang.gen.v1.http.www.microsemi.com
201// .microsemi.edge.assure.msea.cfm.rev20160229.mseacfm.mefcfm
202// .maintenancedomain.maintenanceassociation.manameandtypecombo
203// .DefaultNameCharacterString) name).name().string());
204 }
205
206}