2 * Copyright © 2017 Ericsson, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.netvirt.sfc.classifier.providers;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertTrue;
15 import java.util.Optional;
16 import org.junit.Before;
17 import org.junit.Ignore;
18 import org.junit.Test;
19 import org.opendaylight.controller.md.sal.binding.test.ConstantSchemaAbstractDataBrokerTest;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.genius.mdsalutil.MDSALUtil;
22 import org.opendaylight.genius.mdsalutil.NwConstants;
23 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.sfc.sff.logical.rev160620.DpnIdType;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 public class GeniusProviderTest extends ConstantSchemaAbstractDataBrokerTest {
29 private GeniusProvider geniusProvider;
32 public void setUp() throws Exception {
33 geniusProvider = new GeniusProvider(getDataBroker(), TestOdlInterfaceRpcService.newInstance(),
34 TestInterfaceManager.newInstance());
38 @Ignore("Broken in Neon (invalid number of elements)")
39 public void bindPortOnIngressClassifier() {
40 // Bind the Ingress service
41 geniusProvider.bindPortOnIngressClassifier(GeniusProviderTestParams.INTERFACE_NAME);
43 // Now make sure its in the data store
44 InstanceIdentifier<BoundServices> id = geniusProvider.getBindServiceId(NwConstants.SFC_CLASSIFIER_INDEX,
45 GeniusProviderTestParams.INTERFACE_NAME, true);
46 Optional<BoundServices> boundServices = getBoundServices(id);
47 assertTrue(boundServices.isPresent());
49 // UnBind the Ingress Service
50 geniusProvider.unbindPortOnIngressClassifier(GeniusProviderTestParams.INTERFACE_NAME);
52 // Now make sure its NOT in the data store
53 assertFalse(getBoundServices(id).isPresent());
57 @Ignore("Broken in Neon (invalid number of elements)")
58 public void bindPortOnEgressClassifier() {
59 // Bind the Egress service
60 geniusProvider.bindPortOnEgressClassifier(
61 GeniusProviderTestParams.INTERFACE_NAME,
62 GeniusProviderTestParams.IPV4_ADDRESS_STR);
64 // Now make sure its in the data store
65 InstanceIdentifier<BoundServices> id = geniusProvider.getBindServiceId(
66 NwConstants.EGRESS_SFC_CLASSIFIER_SERVICE_INDEX,
67 GeniusProviderTestParams.INTERFACE_NAME,
69 Optional<BoundServices> boundServices = getBoundServices(id);
70 assertTrue(boundServices.isPresent());
72 // UnBind the Egress Service
73 geniusProvider.unbindPortOnEgressClassifier(GeniusProviderTestParams.INTERFACE_NAME);
75 // Now make sure its NOT in the data store
76 assertFalse(getBoundServices(id).isPresent());
80 public void getNodeIdFromLogicalInterface() {
81 //Optional<NodeId> getNodeIdFromLogicalInterface(String logicalInterface)
82 // Test that it correctly handles the case when the ifName doesnt exist
83 Optional<NodeId> nodeId = this.geniusProvider.getNodeIdFromLogicalInterface(
84 GeniusProviderTestParams.INTERFACE_NAME_NO_EXIST);
85 assertFalse(nodeId.isPresent());
87 // Test that it correctly handles RPC errors
88 nodeId = this.geniusProvider.getNodeIdFromLogicalInterface(
89 GeniusProviderTestParams.INTERFACE_NAME_INVALID);
90 assertFalse(nodeId.isPresent());
92 // Test that it correctly returns the DpnId when everything is correct
93 nodeId = this.geniusProvider.getNodeIdFromLogicalInterface(
94 GeniusProviderTestParams.INTERFACE_NAME);
95 assertTrue(nodeId.isPresent());
96 assertEquals(nodeId.get().getValue(), GeniusProviderTestParams.NODE_ID);
100 public void getNodeIdFromDpnId() {
101 // Test that it correctly handles null input
102 Optional<NodeId> nodeId = this.geniusProvider.getNodeIdFromDpnId(null);
103 assertFalse(nodeId.isPresent());
105 // Test that it correctly returns the nodeId when everything is correct
106 nodeId = this.geniusProvider.getNodeIdFromDpnId(new DpnIdType(GeniusProviderTestParams.DPN_ID));
107 assertTrue(nodeId.isPresent());
108 assertEquals(nodeId.get().getValue(), GeniusProviderTestParams.NODE_ID);
112 public void getIpFromDpnId() {
113 // Test that it correctly handles the case when the ifName doesnt exist
114 Optional<String> ipStr = this.geniusProvider.getIpFromDpnId(
115 new DpnIdType(GeniusProviderTestParams.DPN_ID_NO_EXIST));
116 assertFalse(ipStr.isPresent());
118 // Test that it correctly handles RPC errors
119 ipStr = this.geniusProvider.getIpFromDpnId(
120 new DpnIdType(GeniusProviderTestParams.DPN_ID_INVALID));
121 assertFalse(ipStr.isPresent());
123 // Test that it correctly returns the ipStr when everything is correct
124 ipStr = this.geniusProvider.getIpFromDpnId(
125 new DpnIdType(GeniusProviderTestParams.DPN_ID));
126 assertTrue(ipStr.isPresent());
127 assertEquals(ipStr.get(), GeniusProviderTestParams.IPV4_ADDRESS_STR);
131 public void getDpnIdFromInterfaceName() {
132 // Test that it correctly handles the case when the ifName doesnt exist
133 Optional<DpnIdType> dpnId = this.geniusProvider.getDpnIdFromInterfaceName(
134 GeniusProviderTestParams.INTERFACE_NAME_NO_EXIST);
135 assertFalse(dpnId.isPresent());
137 // Test that it correctly handles RPC errors
138 dpnId = this.geniusProvider.getDpnIdFromInterfaceName(
139 GeniusProviderTestParams.INTERFACE_NAME_INVALID);
140 assertFalse(dpnId.isPresent());
142 // Test that it correctly returns the DpnId when everything is correct
143 dpnId = this.geniusProvider.getDpnIdFromInterfaceName(
144 GeniusProviderTestParams.INTERFACE_NAME);
145 assertTrue(dpnId.isPresent());
146 assertEquals(dpnId.get().getValue().toJava(), GeniusProviderTestParams.DPN_ID);
150 public void getNodeConnectorIdFromInterfaceName() {
151 // Test that it correctly handles the case when the ifName doesnt exist
152 Optional<String> nodeConnStr = this.geniusProvider.getNodeConnectorIdFromInterfaceName(
153 GeniusProviderTestParams.INTERFACE_NAME_NO_EXIST);
154 assertFalse(nodeConnStr.isPresent());
156 // Test that it correctly handles RPC errors
157 nodeConnStr = this.geniusProvider.getNodeConnectorIdFromInterfaceName(
158 GeniusProviderTestParams.INTERFACE_NAME_INVALID);
159 assertFalse(nodeConnStr.isPresent());
161 // Test that it correctly returns the NodeConnectorId when everything is correct
162 nodeConnStr = this.geniusProvider.getNodeConnectorIdFromInterfaceName(
163 GeniusProviderTestParams.INTERFACE_NAME);
164 assertTrue(nodeConnStr.isPresent());
165 assertEquals(nodeConnStr.get(), GeniusProviderTestParams.NODE_CONNECTOR_ID_PREFIX
166 + GeniusProviderTestParams.INTERFACE_NAME);
170 public void getEgressVxlanPortForNode() {
171 // Test that it correctly handles the case when the dpnId doesnt exist
172 Optional<Long> ofPort = this.geniusProvider.getEgressVxlanPortForNode(
173 GeniusProviderTestParams.DPN_ID_NO_EXIST);
174 assertFalse(ofPort.isPresent());
176 // Test that it correctly handles when there are no tunnel ports on the bridge
177 ofPort = this.geniusProvider.getEgressVxlanPortForNode(GeniusProviderTestParams.DPN_ID_NO_PORTS);
178 assertFalse(ofPort.isPresent());
180 // Test that it correctly handles when there are no VXGPE tunnel ports on the bridge
181 ofPort = this.geniusProvider.getEgressVxlanPortForNode(GeniusProviderTestParams.DPN_ID_NO_VXGPE_PORTS);
182 assertFalse(ofPort.isPresent());
184 // Test that is correctly handles when a terminationPoint has no options
185 ofPort = this.geniusProvider.getEgressVxlanPortForNode(GeniusProviderTestParams.DPN_ID_NO_OPTIONS);
186 assertFalse(ofPort.isPresent());
188 // Test that it correctly returns the OpenFlow port when everything is correct
189 ofPort = this.geniusProvider.getEgressVxlanPortForNode(GeniusProviderTestParams.DPN_ID);
190 assertTrue(ofPort.isPresent());
191 assertEquals(ofPort.get().longValue(), GeniusProviderTestParams.OF_PORT);
194 Optional<BoundServices> getBoundServices(InstanceIdentifier<BoundServices> id) {
195 return Optional.ofNullable(MDSALUtil.read(getDataBroker(), LogicalDatastoreType.CONFIGURATION, id).orNull());