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.Test;
18 import org.opendaylight.controller.md.sal.binding.test.ConstantSchemaAbstractDataBrokerTest;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.genius.mdsalutil.MDSALUtil;
21 import org.opendaylight.genius.mdsalutil.NwConstants;
22 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.sfc.sff.logical.rev160620.DpnIdType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 public class GeniusProviderTest extends ConstantSchemaAbstractDataBrokerTest {
28 private GeniusProvider geniusProvider;
31 public void setUp() throws Exception {
32 geniusProvider = new GeniusProvider(getDataBroker(), TestOdlInterfaceRpcService.newInstance(),
33 TestInterfaceManager.newInstance());
37 public void bindPortOnIngressClassifier() {
38 // Bind the Ingress service
39 geniusProvider.bindPortOnIngressClassifier(GeniusProviderTestParams.INTERFACE_NAME);
41 // Now make sure its in the data store
42 InstanceIdentifier<BoundServices> id = geniusProvider.getBindServiceId(NwConstants.SFC_CLASSIFIER_INDEX,
43 GeniusProviderTestParams.INTERFACE_NAME, true);
44 Optional<BoundServices> boundServices = getBoundServices(id);
45 assertTrue(boundServices.isPresent());
47 // UnBind the Ingress Service
48 geniusProvider.unbindPortOnIngressClassifier(GeniusProviderTestParams.INTERFACE_NAME);
50 // Now make sure its NOT in the data store
51 assertFalse(getBoundServices(id).isPresent());
55 public void bindPortOnEgressClassifier() {
56 // Bind the Egress service
57 geniusProvider.bindPortOnEgressClassifier(
58 GeniusProviderTestParams.INTERFACE_NAME,
59 GeniusProviderTestParams.IPV4_ADDRESS_STR);
61 // Now make sure its in the data store
62 InstanceIdentifier<BoundServices> id = geniusProvider.getBindServiceId(
63 NwConstants.EGRESS_SFC_CLASSIFIER_SERVICE_INDEX,
64 GeniusProviderTestParams.INTERFACE_NAME,
66 Optional<BoundServices> boundServices = getBoundServices(id);
67 assertTrue(boundServices.isPresent());
69 // UnBind the Egress Service
70 geniusProvider.unbindPortOnEgressClassifier(GeniusProviderTestParams.INTERFACE_NAME);
72 // Now make sure its NOT in the data store
73 assertFalse(getBoundServices(id).isPresent());
77 public void getNodeIdFromLogicalInterface() {
78 //Optional<NodeId> getNodeIdFromLogicalInterface(String logicalInterface)
79 // Test that it correctly handles the case when the ifName doesnt exist
80 Optional<NodeId> nodeId = this.geniusProvider.getNodeIdFromLogicalInterface(
81 GeniusProviderTestParams.INTERFACE_NAME_NO_EXIST);
82 assertFalse(nodeId.isPresent());
84 // Test that it correctly handles RPC errors
85 nodeId = this.geniusProvider.getNodeIdFromLogicalInterface(
86 GeniusProviderTestParams.INTERFACE_NAME_INVALID);
87 assertFalse(nodeId.isPresent());
89 // Test that it correctly returns the DpnId when everything is correct
90 nodeId = this.geniusProvider.getNodeIdFromLogicalInterface(
91 GeniusProviderTestParams.INTERFACE_NAME);
92 assertTrue(nodeId.isPresent());
93 assertEquals(nodeId.get().getValue(), GeniusProviderTestParams.NODE_ID);
97 public void getNodeIdFromDpnId() {
98 // Test that it correctly handles null input
99 Optional<NodeId> nodeId = this.geniusProvider.getNodeIdFromDpnId(null);
100 assertFalse(nodeId.isPresent());
102 // Test that it correctly returns the nodeId when everything is correct
103 nodeId = this.geniusProvider.getNodeIdFromDpnId(new DpnIdType(GeniusProviderTestParams.DPN_ID));
104 assertTrue(nodeId.isPresent());
105 assertEquals(nodeId.get().getValue(), GeniusProviderTestParams.NODE_ID);
109 public void getIpFromDpnId() {
110 // Test that it correctly handles the case when the ifName doesnt exist
111 Optional<String> ipStr = this.geniusProvider.getIpFromDpnId(
112 new DpnIdType(GeniusProviderTestParams.DPN_ID_NO_EXIST));
113 assertFalse(ipStr.isPresent());
115 // Test that it correctly handles RPC errors
116 ipStr = this.geniusProvider.getIpFromDpnId(
117 new DpnIdType(GeniusProviderTestParams.DPN_ID_INVALID));
118 assertFalse(ipStr.isPresent());
120 // Test that it correctly returns the ipStr when everything is correct
121 ipStr = this.geniusProvider.getIpFromDpnId(
122 new DpnIdType(GeniusProviderTestParams.DPN_ID));
123 assertTrue(ipStr.isPresent());
124 assertEquals(ipStr.get(), GeniusProviderTestParams.IPV4_ADDRESS_STR);
128 public void getDpnIdFromInterfaceName() {
129 // Test that it correctly handles the case when the ifName doesnt exist
130 Optional<DpnIdType> dpnId = this.geniusProvider.getDpnIdFromInterfaceName(
131 GeniusProviderTestParams.INTERFACE_NAME_NO_EXIST);
132 assertFalse(dpnId.isPresent());
134 // Test that it correctly handles RPC errors
135 dpnId = this.geniusProvider.getDpnIdFromInterfaceName(
136 GeniusProviderTestParams.INTERFACE_NAME_INVALID);
137 assertFalse(dpnId.isPresent());
139 // Test that it correctly returns the DpnId when everything is correct
140 dpnId = this.geniusProvider.getDpnIdFromInterfaceName(
141 GeniusProviderTestParams.INTERFACE_NAME);
142 assertTrue(dpnId.isPresent());
143 assertEquals(dpnId.get().getValue(), GeniusProviderTestParams.DPN_ID);
147 public void getNodeConnectorIdFromInterfaceName() {
148 // Test that it correctly handles the case when the ifName doesnt exist
149 Optional<String> nodeConnStr = this.geniusProvider.getNodeConnectorIdFromInterfaceName(
150 GeniusProviderTestParams.INTERFACE_NAME_NO_EXIST);
151 assertFalse(nodeConnStr.isPresent());
153 // Test that it correctly handles RPC errors
154 nodeConnStr = this.geniusProvider.getNodeConnectorIdFromInterfaceName(
155 GeniusProviderTestParams.INTERFACE_NAME_INVALID);
156 assertFalse(nodeConnStr.isPresent());
158 // Test that it correctly returns the NodeConnectorId when everything is correct
159 nodeConnStr = this.geniusProvider.getNodeConnectorIdFromInterfaceName(
160 GeniusProviderTestParams.INTERFACE_NAME);
161 assertTrue(nodeConnStr.isPresent());
162 assertEquals(nodeConnStr.get(), GeniusProviderTestParams.NODE_CONNECTOR_ID_PREFIX
163 + GeniusProviderTestParams.INTERFACE_NAME);
167 public void getEgressVxlanPortForNode() {
168 // Test that it correctly handles the case when the dpnId doesnt exist
169 Optional<Long> ofPort = this.geniusProvider.getEgressVxlanPortForNode(
170 GeniusProviderTestParams.DPN_ID_NO_EXIST);
171 assertFalse(ofPort.isPresent());
173 // Test that it correctly handles when there are no tunnel ports on the bridge
174 ofPort = this.geniusProvider.getEgressVxlanPortForNode(GeniusProviderTestParams.DPN_ID_NO_PORTS);
175 assertFalse(ofPort.isPresent());
177 // Test that it correctly handles when there are no VXGPE tunnel ports on the bridge
178 ofPort = this.geniusProvider.getEgressVxlanPortForNode(GeniusProviderTestParams.DPN_ID_NO_VXGPE_PORTS);
179 assertFalse(ofPort.isPresent());
181 // Test that is correctly handles when a terminationPoint has no options
182 ofPort = this.geniusProvider.getEgressVxlanPortForNode(GeniusProviderTestParams.DPN_ID_NO_OPTIONS);
183 assertFalse(ofPort.isPresent());
185 // Test that it correctly returns the OpenFlow port when everything is correct
186 ofPort = this.geniusProvider.getEgressVxlanPortForNode(GeniusProviderTestParams.DPN_ID);
187 assertTrue(ofPort.isPresent());
188 assertEquals(ofPort.get().longValue(), GeniusProviderTestParams.OF_PORT);
191 Optional<BoundServices> getBoundServices(InstanceIdentifier<BoundServices> id) {
192 return Optional.ofNullable(MDSALUtil.read(getDataBroker(), LogicalDatastoreType.CONFIGURATION, id).orNull());