Fix for yangtools mandatory node check update 50/62250/6
authorMichal Cmarada <mcmarada@cisco.com>
Thu, 7 Sep 2017 13:26:18 +0000 (15:26 +0200)
committerMichal Cmarada <mcmarada@cisco.com>
Thu, 7 Sep 2017 13:26:18 +0000 (15:26 +0200)
when yangtools will force mandatory node check on Operational DS,
some mandatory fields needs to be added in code otherwise this leads
to build failures. Renderer yang model needs to be adjusted too
to preserve functionality as before.
link to yangtool dev mailing list:
https://lists.opendaylight.org/pipermail/yangtools-dev/2017-August/001959.html

Change-Id: I286d446c63685f1dc5a8fb401344ee828a985e54
Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
Signed-off-by: Tomas Cechvala <tcechval@cisco.com>
groupbasedpolicy/src/main/yang/model/renderer.yang
groupbasedpolicy/src/test/java/org/opendaylight/groupbasedpolicy/base_endpoint/BaseEndpointServiceImplTest.java
location-providers/ne-location-provider/src/test/java/org/opendaylight/groupbasedpolicy/ne/location/provider/NeLocationProviderTest.java
renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/commands/StaticArpCommand.java
renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/lisp/LispStateCommandExecutor.java
renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/lisp/LispStateManager.java
renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/lisp/flat/overlay/StaticRoutingHelper.java
renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/iface/InterfaceManagerTest.java
renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/iface/VppEndpointLocationProviderTest.java
renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/listener/VppEndpointListenerTest.java
renderers/vpp/src/test/java/org/opendaylight/groupbasedpolicy/renderer/vpp/policy/VppRendererPolicyManagerTest.java

index 0954917661ce3799bab11dd058f5125d31c9bf00..4cf6d86b948a32c2c925ec63f467e2ed79eb8f4e 100755 (executable)
@@ -166,6 +166,7 @@ module renderer {
             }
 
             container renderer-policy {
+                presence "Enforce mandatory node only if renderer-policy container is present";
                 description "Policy is named by version and describes desired vs real state.
                     Desired state of policy described by /renderers/renderer/renderer-policy/configuration and version are stored in CONF.
                     The real state of policy described by /renderers/renderer/renderer-policy/status and version are stored in OPER.";
@@ -225,6 +226,7 @@ module renderer {
                     }
 
                     container endpoints {
+                        presence "Enforce mandatory node only if endpoints container is present";
                         list address-endpoint-with-location {
                             min-elements 1;
                             key "context-type context-id address-type address";
index d28e9e625b9c3e7e4dc4f12efff6e2cf2c31dcac..1fcc60b4114bb85fdd4e1ed10fb778560acc7323 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.groupbasedpolicy.base_endpoint;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 import org.junit.Assert;
@@ -53,6 +54,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpo
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.unregister.endpoint.input.ContainmentEndpointUnreg;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.unregister.endpoint.input.ContainmentEndpointUnregBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.AddressType;
@@ -358,6 +360,7 @@ public class BaseEndpointServiceImplTest extends CustomDataBrokerTest {
                 .setTimestamp(addrEp.getTimestamp())
                 .setParentEndpointChoice(addrEp.getParentEndpointChoice())
                 .setChildEndpoint(addrEp.getChildEndpoint())
+                .setEndpointGroup(addrEp.getEndpointGroup())
                 .build());
         }
         builder.setAddressEndpointReg(addrEpRegs);
@@ -372,6 +375,7 @@ public class BaseEndpointServiceImplTest extends CustomDataBrokerTest {
                 .setTenant(contEp.getTenant())
                 .setNetworkContainment(contEp.getNetworkContainment())
                 .setChildEndpoint(contEp.getChildEndpoint())
+                .setEndpointGroup(contEp.getEndpointGroup())
                 .build());
         }
         builder.setContainmentEndpointReg(contEpRegs);
@@ -407,7 +411,8 @@ public class BaseEndpointServiceImplTest extends CustomDataBrokerTest {
             .setAddress(MAC_ADDRESS)
             .setAddressType(AddressType.class)
             .setNetworkContainment(new NetworkContainmentBuilder().setContainment(networkDomainContainment).build())
-            .setTimestamp(timestamp);
+            .setTimestamp(timestamp)
+            .setEndpointGroup(Collections.singletonList(new EndpointGroupId("testEPGID")));
     }
 
     private AddressEndpointBuilder createBaseL3EpBuilder() {
@@ -418,7 +423,8 @@ public class BaseEndpointServiceImplTest extends CustomDataBrokerTest {
             .setAddress(IP_ADDRESS)
             .setAddressType(AddressType.class)
             .setNetworkContainment(new NetworkContainmentBuilder().setContainment(networkDomainContainment).build())
-            .setTimestamp(timestamp);
+            .setTimestamp(timestamp)
+            .setEndpointGroup(Collections.singletonList(new EndpointGroupId("testEPGID")));
     }
 
     private ContainmentEndpointBuilder createBaseContEpBuilder() {
@@ -426,6 +432,7 @@ public class BaseEndpointServiceImplTest extends CustomDataBrokerTest {
             .setContextId(new ContextId(CONTEXT_ID))
             .setContextType(ContextType.class)
             .setTenant(new TenantId(TENANT))
-            .setNetworkContainment(new NetworkContainmentBuilder().setContainment(networkDomainContainment).build());
+            .setNetworkContainment(new NetworkContainmentBuilder().setContainment(networkDomainContainment).build())
+            .setEndpointGroup(Collections.singletonList(new EndpointGroupId("testEPGID")));
     }
 }
index 4efa5717935852ac68983a1aebb72bf9c802ca80..aa64733942553fb07db2e5ebfd9a8038cefa3d20 100644 (file)
@@ -46,7 +46,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpo
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.ExternalLocationCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.network.elements.rev160407.NetworkElements;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.network.elements.rev160407.NetworkElementsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.network.elements.rev160407.network.elements.NetworkElement;
@@ -83,6 +85,9 @@ import com.google.common.util.concurrent.CheckedFuture;
 
 public class NeLocationProviderTest extends CustomDataBrokerTest {
 
+    private static final TenantId TENANT = new TenantId("Tenant");
+    private static final List<EndpointGroupId> DEFAULT_EPG =
+        Collections.singletonList(new EndpointGroupId("defaultEPG"));
     private DataBroker dataBroker;
     private NeLocationProvider neProvider;
     private String L3_CONTEXT_ID = "l3Context";
@@ -97,7 +102,8 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     @Override
     public Collection<Class<?>> getClassesFromModules() {
-        return ImmutableList.<Class<?>>of(NetworkElements.class, LocationProviders.class, Endpoints.class, L3Context.class, Nodes.class);
+        return ImmutableList.<Class<?>>of(NetworkElements.class, LocationProviders.class, Endpoints.class,
+            L3Context.class, Nodes.class);
     }
 
     @Before
@@ -151,13 +157,12 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
     @Test
     public void test_AddressEndpointWrite_NoNE_Overwrite() throws Exception {
         writeBaseAddrEndpoint();
-        NetworkContainment nc = new NetworkContainmentBuilder()
-                .setContainment(new NetworkDomainContainmentBuilder().setNetworkDomainId(new NetworkDomainId(L3_CONTEXT_ID)).build())
-                        .build();
+        NetworkContainment nc = new NetworkContainmentBuilder().setContainment(
+            new NetworkDomainContainmentBuilder().setNetworkDomainId(new NetworkDomainId(L3_CONTEXT_ID)).build())
+            .build();
         AddressEndpoint endpoint = new AddressEndpointBuilder().setKey(
-                new AddressEndpointKey(IPv4_HOST_ADDRESS_1, IpPrefixType.class, new ContextId(L3_CONTEXT_ID), L3Context.class))
-                .setNetworkContainment(nc)
-                .build();
+                new AddressEndpointKey(IPv4_HOST_ADDRESS_1, IpPrefixType.class, new ContextId(L3_CONTEXT_ID),
+                    L3Context.class)).setNetworkContainment(nc).setTenant(TENANT).setEndpointGroup(DEFAULT_EPG).build();
         InstanceIdentifier<AddressEndpoint> iid = IidFactory.addressEndpointIid(endpoint.getKey());
         WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
         wtx.put(LogicalDatastoreType.OPERATIONAL, iid, endpoint, true);
@@ -171,8 +176,9 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
     @Test
     public void test_AddressEndpointModified_NoNE() throws Exception {
         writeBaseAddrEndpoint();
-        NetworkContainment nc = new NetworkContainmentBuilder()
-        .setContainment(new NetworkDomainContainmentBuilder().setNetworkDomainId(new NetworkDomainId(L3_CONTEXT_ID)).build())
+        NetworkContainment nc =
+            new NetworkContainmentBuilder().setContainment(
+                new NetworkDomainContainmentBuilder().setNetworkDomainId(new NetworkDomainId(L3_CONTEXT_ID)).build())
                 .build();
         InstanceIdentifier<NetworkContainment> iid = InstanceIdentifier
                 .builder(Endpoints.class)
@@ -502,8 +508,12 @@ public class NeLocationProviderTest extends CustomDataBrokerTest {
 
     private AddressEndpoint createAddressEndpoint(String ipAddr, Class<? extends AddressType> addrType,
             String context, Class<? extends ContextType> cType) {
-        return new AddressEndpointBuilder().setAddress(ipAddr).setAddressType(addrType)
-                .setContextId(new ContextId(context)).setContextType(cType).build();
+        return new AddressEndpointBuilder()
+            .setAddress(ipAddr)
+            .setAddressType(addrType)
+            .setContextId(new ContextId(context))
+            .setContextType(cType).setTenant(TENANT)
+            .setEndpointGroup(DEFAULT_EPG).build();
     }
 
     private NetworkElements createNetworkElements(String node, String iface, String l3c, String prefix) {
index e90bd2c7cbb3e351ae671f8fd2af4ddeeafb0309..93aba64d52676609d28c8763dfe78fd57da146e3 100644 (file)
@@ -13,7 +13,10 @@ import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Ip;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Neighbor;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.NeighborBuilder;
@@ -52,12 +55,16 @@ public class StaticArpCommand extends AbstractConfigCommand{
     @Override
     void put(ReadWriteTransaction rwTx) {
         InstanceIdentifier<Neighbor> iid = VppIidFactory.getNeighborIid(interfaceKey, new NeighborKey(ip));
+        InstanceIdentifier<Interface> intfIid = VppIidFactory.getInterfaceIID(interfaceKey);
+        rwTx.merge(LogicalDatastoreType.CONFIGURATION, intfIid, new InterfaceBuilder().setKey(interfaceKey).setType(Ip.class).build());
         rwTx.put(LogicalDatastoreType.CONFIGURATION, iid, getNeighborBuilder().build());
     }
 
     @Override
     void merge(ReadWriteTransaction rwTx) {
         InstanceIdentifier<Neighbor> iid = VppIidFactory.getNeighborIid(interfaceKey, new NeighborKey(ip));
+        InstanceIdentifier<Interface> intfIid = VppIidFactory.getInterfaceIID(interfaceKey);
+        rwTx.merge(LogicalDatastoreType.CONFIGURATION, intfIid, new InterfaceBuilder().setKey(interfaceKey).setType(Ip.class).build());
         rwTx.merge(LogicalDatastoreType.CONFIGURATION, iid, getNeighborBuilder().build());
     }
 
index 115e42f82b909cb63256895a730e469ba713e0b2..691596651a09ec70e94f968508da50cf204cbf5f 100644 (file)
@@ -51,8 +51,22 @@ public class LispStateCommandExecutor {
 
     public static <T extends DataObject> boolean executeCommand(InstanceIdentifier<Node> nodeIid,
             AbstractLispCommand<T> lispStateCommand) {
-        final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(nodeIid, lispStateCommand.getIid(),
-                lispStateCommand.getData(), GbpNetconfTransaction.RETRY_COUNT);
+        final boolean transactionState;
+        switch (lispStateCommand.getOperation()) {
+            case MERGE:
+            case PUT: {
+                transactionState = GbpNetconfTransaction.netconfSyncedWrite(nodeIid, lispStateCommand.getIid(),
+                        lispStateCommand.getData(), GbpNetconfTransaction.RETRY_COUNT);
+                break;
+            }
+            case DELETE: {
+                transactionState = GbpNetconfTransaction.netconfSyncedDelete(nodeIid, lispStateCommand.getIid(),
+                        GbpNetconfTransaction.RETRY_COUNT);
+            }
+                break;
+            default:
+                throw new IllegalStateException("No supported operation specified.");
+        }
         if (transactionState) {
             LOG.trace("Successfully executed command: {}", lispStateCommand);
         } else {
index e5a5b56283effe70d8c8e20070711bb366de3b38..f23cb332dcc156beeffa400880c71e9e5c599279 100644 (file)
@@ -146,6 +146,7 @@ public class LispStateManager {
 
     private void enableLispOnHost(EndpointHost endpointHost, LispState lispState)
             throws LispConfigCommandFailedException {
+        LOG.debug("Enabling LISP on host {}", endpointHost.getHostName());
         AbstractLispCommand<Lisp> lispEnableCommand = LispCommandWrapper.enableLisp();
         if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostName(), lispEnableCommand)) {
             lispState.setLispEnabled(true);
index 59266a5df339f8c2323df9bfa111d80b1da594fe..5465b66e3c2ccd988b2b925e87cba75a9bca3b4c 100644 (file)
@@ -117,7 +117,12 @@ public class StaticRoutingHelper {
                 .augmentation(StaticRoutes1.class)
                 .child(Ipv4.class);
 
-        if (GbpNetconfTransaction.netconfSyncedMerge(VppIidFactory.getNetconfNodeIid(new NodeId(hostName)), iid,
+        RoutingProtocolKey routingProtocolKey = new RoutingProtocolKey(hostVrfStateForPortVrf.getProtocolName());
+        boolean routingProtocol = GbpNetconfTransaction.netconfSyncedMerge(VppIidFactory.getNetconfNodeIid(new NodeId(hostName)), VppIidFactory
+                .getRoutingInstanceIid(routingProtocolKey),
+                new RoutingProtocolBuilder().setKey(routingProtocolKey).setType(Static.class).build(), GbpNetconfTransaction.RETRY_COUNT);
+
+        if (routingProtocol && GbpNetconfTransaction.netconfSyncedMerge(VppIidFactory.getNetconfNodeIid(new NodeId(hostName)), iid,
                 ipv4Route, GbpNetconfTransaction.RETRY_COUNT)) {
             hostVrfStateForPortVrf.addNewPortIpInVrf(portSubnetUuid, nextHopAddress);
             hostPortInterfaces.addRouteToPortInterface(outgoingInterface, portSubnetUuid, nextHopAddress, routeId);
index 6ab066dcf297a3b7dc3d2aec216142bdca011b0e..f7130536fea74831b2f246fa511ec129aa833cd8 100644 (file)
@@ -36,6 +36,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpo
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpointBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpointKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.LocationProviders;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.LocationProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocation;
@@ -69,6 +70,7 @@ public class InterfaceManagerTest extends CustomDataBrokerTest {
             InstanceIdentifier.builder(Config.class).child(VppEndpoint.class, BASIC_VPP_EP_KEY).build();
     private final static NodeKey NODE_KEY = new NodeKey(new NodeId("node1"));
     private final static String SOCKET = "socket1";
+    private final static String TENANT = "tenant";
 
     private InterfaceManager manager;
     private FlatOverlayManager flatOverlayManager;
@@ -100,6 +102,7 @@ public class InterfaceManagerTest extends CustomDataBrokerTest {
             .setKey(new AddressEndpointKey(vhostVppEpBuilder().getAddress(), vhostVppEpBuilder().getAddressType(),
                     vhostVppEpBuilder().getContextId(), vhostVppEpBuilder().getContextType()))
             .setEndpointGroup(ImmutableList.of())
+            .setTenant(new TenantId(TENANT))
             .build();
         VppEndpointLocationProvider vppEpLocProvider = new VppEndpointLocationProvider(dataBroker);
         WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
index 6c5f8c1305d97fc991a2acd00896f4377515f0f0..1364e3becf4b8f6877b90f083cef0f180d2709ed 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.groupbasedpolicy.renderer.vpp.iface;
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -42,6 +43,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpo
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.parent.child.endpoints.parent.endpoint.choice.parent.endpoint._case.ParentEndpointBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.parent.child.endpoints.parent.endpoint.choice.parent.endpoint._case.ParentEndpointKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.LocationProviders;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.LocationProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocation;
@@ -63,10 +66,12 @@ import com.google.common.collect.ImmutableList;
 
 public class VppEndpointLocationProviderTest extends CustomDataBrokerTest {
 
+    private static final EndpointGroupId DEFAULT_EPG = new EndpointGroupId("Default");
     private DataBroker dataBroker;
     private VppEndpointLocationProvider locationProvider;
 
     private final String INTF_NAME = "interface-name";
+    private final static String TENANT = "tenant";
     private final NodeId NODE_1 = new NodeId("vpp-node-1");
     private final NodeId NODE_2 = new NodeId("vpp-node-2");
     private final NodeId NODE_3 = new NodeId("vpp-node-3");
@@ -138,10 +143,10 @@ public class VppEndpointLocationProviderTest extends CustomDataBrokerTest {
     }
 
     private void l2ChildHasTwoIpParents(boolean vppEndpointEvent) {
-        AddressEndpointBuilder child = new AddressEndpointBuilder().setKey(MAC_KEY_23_45);
+        AddressEndpointBuilder child = getAddressEndpointBuilder().setKey(MAC_KEY_23_45);
         setParentEndpoints(child, IP_KEY_1_22, IP_KEY_2_22);
-        AddressEndpointBuilder firstParent = new AddressEndpointBuilder().setKey(IP_KEY_1_22);
-        AddressEndpointBuilder secondParent = new AddressEndpointBuilder().setKey(IP_KEY_2_22);
+        AddressEndpointBuilder firstParent = getAddressEndpointBuilder().setKey(IP_KEY_1_22);
+        AddressEndpointBuilder secondParent = getAddressEndpointBuilder().setKey(IP_KEY_2_22);
         setChildEndpoints(firstParent, MAC_KEY_23_45);
         setChildEndpoints(secondParent, MAC_KEY_23_45);
         submitEndpointsToDatastore(child.build(), firstParent.build(), secondParent.build());
@@ -178,9 +183,9 @@ public class VppEndpointLocationProviderTest extends CustomDataBrokerTest {
     }
 
     private void l2ChildHasOneIpParent(boolean vppEndpointEvent) {
-        AddressEndpointBuilder child = new AddressEndpointBuilder().setKey(MAC_KEY_23_45);
+        AddressEndpointBuilder child = getAddressEndpointBuilder().setKey(MAC_KEY_23_45);
         setParentEndpoints(child, IP_KEY_1_22);
-        AddressEndpointBuilder firstParent = new AddressEndpointBuilder().setKey(IP_KEY_1_22);
+        AddressEndpointBuilder firstParent = getAddressEndpointBuilder().setKey(IP_KEY_1_22);
         setChildEndpoints(firstParent, MAC_KEY_23_45);
         submitEndpointsToDatastore(child.build(), firstParent.build());
         assertEndpointsInDatastore(child.getKey(), firstParent.getKey());
@@ -203,9 +208,9 @@ public class VppEndpointLocationProviderTest extends CustomDataBrokerTest {
      */
     @Test
     public void lifecycleTest() {
-        AddressEndpointBuilder child = new AddressEndpointBuilder().setKey(MAC_KEY_23_45);
+        AddressEndpointBuilder child = getAddressEndpointBuilder().setKey(MAC_KEY_23_45);
         setParentEndpoints(child, IP_KEY_1_22);
-        AddressEndpointBuilder firstParent = new AddressEndpointBuilder().setKey(IP_KEY_1_22);
+        AddressEndpointBuilder firstParent = getAddressEndpointBuilder().setKey(IP_KEY_1_22);
         setChildEndpoints(firstParent, MAC_KEY_23_45);
         submitEndpointsToDatastore(child.build(), firstParent.build());
         assertEndpointsInDatastore(child.getKey(), firstParent.getKey());
@@ -216,7 +221,7 @@ public class VppEndpointLocationProviderTest extends CustomDataBrokerTest {
         Assert.assertTrue(location.getKey().equals(getLocationKey(MAC_KEY_23_45)));
         assertNodeConnector(location.getAbsoluteLocation(), INTF_NAME);
         assertMountPoint(location.getAbsoluteLocation(), NODE_1);
-        AddressEndpointBuilder secondParent = new AddressEndpointBuilder().setKey(IP_KEY_2_22);
+        AddressEndpointBuilder secondParent = getAddressEndpointBuilder().setKey(IP_KEY_2_22);
         setChildEndpoints(secondParent, MAC_KEY_23_45);
         setParentEndpoints(child, IP_KEY_1_22, IP_KEY_2_22);
         submitEndpointsToDatastore(child.build(), secondParent.build());
@@ -254,11 +259,11 @@ public class VppEndpointLocationProviderTest extends CustomDataBrokerTest {
      */
     @Test
     public void testRelativeLocation_multihome() {
-        AddressEndpointBuilder mac1 = new AddressEndpointBuilder().setKey(MAC_KEY_23_45);
+        AddressEndpointBuilder mac1 = getAddressEndpointBuilder().setKey(MAC_KEY_23_45);
         setParentEndpoints(mac1, IP_KEY_1_22);
-        AddressEndpointBuilder mac2 = new AddressEndpointBuilder().setKey(MAC_KEY_24_45);
+        AddressEndpointBuilder mac2 = getAddressEndpointBuilder().setKey(MAC_KEY_24_45);
         setParentEndpoints(mac2, IP_KEY_1_22);
-        AddressEndpointBuilder ip1 = new AddressEndpointBuilder().setKey(IP_KEY_1_22);
+        AddressEndpointBuilder ip1 = getAddressEndpointBuilder().setKey(IP_KEY_1_22);
         setChildEndpoints(ip1, MAC_KEY_23_45, MAC_KEY_24_45);
         submitEndpointsToDatastore(mac1.build(), mac2.build(), ip1.build());
         assertEndpointsInDatastore(mac1.getKey(), mac2.getKey(), ip1.getKey());
@@ -295,19 +300,19 @@ public class VppEndpointLocationProviderTest extends CustomDataBrokerTest {
      */
     @Test
     public void testMetadataHaUseCase() {
-        AddressEndpointBuilder mac1 = new AddressEndpointBuilder().setKey(MAC_KEY_23_45);
+        AddressEndpointBuilder mac1 = getAddressEndpointBuilder().setKey(MAC_KEY_23_45);
         setParentEndpoints(mac1, IP_KEY_1_22, IP_KEY_9_99);
-        AddressEndpointBuilder mac2 = new AddressEndpointBuilder().setKey(MAC_KEY_24_45);
+        AddressEndpointBuilder mac2 = getAddressEndpointBuilder().setKey(MAC_KEY_24_45);
         setParentEndpoints(mac2, IP_KEY_2_22, IP_KEY_9_99);
-        AddressEndpointBuilder mac3 = new AddressEndpointBuilder().setKey(MAC_KEY_25_45);
+        AddressEndpointBuilder mac3 = getAddressEndpointBuilder().setKey(MAC_KEY_25_45);
         setParentEndpoints(mac3, IP_KEY_3_22, IP_KEY_9_99);
-        AddressEndpointBuilder ip1 = new AddressEndpointBuilder().setKey(IP_KEY_1_22);
+        AddressEndpointBuilder ip1 = getAddressEndpointBuilder().setKey(IP_KEY_1_22);
         setChildEndpoints(ip1, MAC_KEY_23_45);
-        AddressEndpointBuilder ip2 = new AddressEndpointBuilder().setKey(IP_KEY_2_22);
+        AddressEndpointBuilder ip2 = getAddressEndpointBuilder().setKey(IP_KEY_2_22);
         setChildEndpoints(ip2, MAC_KEY_24_45);
-        AddressEndpointBuilder ip3 = new AddressEndpointBuilder().setKey(IP_KEY_3_22);
+        AddressEndpointBuilder ip3 = getAddressEndpointBuilder().setKey(IP_KEY_3_22);
         setChildEndpoints(ip3, MAC_KEY_25_45);
-        AddressEndpointBuilder ip9 = new AddressEndpointBuilder().setKey(IP_KEY_9_99);
+        AddressEndpointBuilder ip9 = getAddressEndpointBuilder().setKey(IP_KEY_9_99);
         setChildEndpoints(ip9, MAC_KEY_23_45, MAC_KEY_24_45, MAC_KEY_25_45);
         submitEndpointsToDatastore(mac1.build(), mac2.build(), mac3.build(), ip1.build(), ip2.build(), ip3.build(),
                 ip9.build());
@@ -316,7 +321,7 @@ public class VppEndpointLocationProviderTest extends CustomDataBrokerTest {
         locationProvider.createLocationForVppEndpoint(vppEndpointBuilder(MAC_KEY_23_45_VPP, NODE_1, INTF_NAME));
         locationProvider.createLocationForVppEndpoint(vppEndpointBuilder(MAC_KEY_24_45_VPP, NODE_2, INTF_NAME));
         locationProvider.createLocationForVppEndpoint(vppEndpointBuilder(MAC_KEY_25_45_VPP, NODE_3, INTF_NAME));
-        assertL2ChildHasTwoIpParentsAndIpParentHasMultipleChilds();
+        assertL2ChildHasTwoIpParentsAndIpParentHasMultipleChilds(4L);
     }
 
     /**
@@ -324,38 +329,45 @@ public class VppEndpointLocationProviderTest extends CustomDataBrokerTest {
      */
     @Test
     public void metadataHaUseCase_swapped_order() {
-        AddressEndpointBuilder mac1 = new AddressEndpointBuilder().setKey(MAC_KEY_23_45);
+        AddressEndpointBuilder mac1 = getAddressEndpointBuilder().setKey(MAC_KEY_23_45);
         setParentEndpoints(mac1, IP_KEY_1_22, IP_KEY_9_99);
         locationProvider.createLocationForVppEndpoint(vppEndpointBuilder(MAC_KEY_23_45_VPP, NODE_1, INTF_NAME));
-        AddressEndpointBuilder ip1 = new AddressEndpointBuilder().setKey(IP_KEY_1_22);
+        AddressEndpointBuilder ip1 = getAddressEndpointBuilder().setKey(IP_KEY_1_22);
         setChildEndpoints(ip1, MAC_KEY_23_45);
-        AddressEndpointBuilder ip9 = new AddressEndpointBuilder().setKey(IP_KEY_9_99);
+        AddressEndpointBuilder ip9 = getAddressEndpointBuilder().setKey(IP_KEY_9_99);
         setChildEndpoints(ip9, MAC_KEY_23_45);
         submitEndpointsToDatastore(mac1.build(), ip1.build(), ip9.build());
         locationProvider.createLocationForVppEndpoint(vppEndpointBuilder(MAC_KEY_24_45_VPP, NODE_2, INTF_NAME));
-        AddressEndpointBuilder mac2 = new AddressEndpointBuilder().setKey(MAC_KEY_24_45);
+        AddressEndpointBuilder mac2 = getAddressEndpointBuilder().setKey(MAC_KEY_24_45);
         setParentEndpoints(mac2, IP_KEY_2_22, IP_KEY_9_99);
-        AddressEndpointBuilder ip2 = new AddressEndpointBuilder().setKey(IP_KEY_2_22);
+        AddressEndpointBuilder ip2 = getAddressEndpointBuilder().setKey(IP_KEY_2_22);
         setChildEndpoints(ip2, MAC_KEY_24_45);
-        ip9 = new AddressEndpointBuilder().setKey(IP_KEY_9_99);
+        ip9 = getAddressEndpointBuilder().setKey(IP_KEY_9_99);
         setChildEndpoints(ip9, MAC_KEY_23_45, MAC_KEY_24_45);
         submitEndpointsToDatastore(mac2.build(), ip2.build(), ip9.build());
-        AddressEndpointBuilder mac3 = new AddressEndpointBuilder().setKey(MAC_KEY_25_45);
+        AddressEndpointBuilder mac3 = getAddressEndpointBuilder().setKey(MAC_KEY_25_45);
         setParentEndpoints(mac3, IP_KEY_3_22, IP_KEY_9_99);
-        AddressEndpointBuilder ip3 = new AddressEndpointBuilder().setKey(IP_KEY_3_22);
+        AddressEndpointBuilder ip3 = getAddressEndpointBuilder().setKey(IP_KEY_3_22);
         setChildEndpoints(ip3, MAC_KEY_25_45);
-        ip9 = new AddressEndpointBuilder().setKey(IP_KEY_9_99);
+        ip9 = getAddressEndpointBuilder().setKey(IP_KEY_9_99);
         setChildEndpoints(ip9, MAC_KEY_23_45, MAC_KEY_24_45, MAC_KEY_25_45);
         locationProvider.createLocationForVppEndpoint(vppEndpointBuilder(MAC_KEY_25_45_VPP, NODE_3, INTF_NAME));
         submitEndpointsToDatastore(mac3.build(), ip3.build(), ip9.build());
         assertEndpointsInDatastore(mac1.getKey(), mac2.getKey(), mac3.getKey(), ip1.getKey(), ip2.getKey(),
                 ip3.getKey(), ip9.getKey());
-        assertL2ChildHasTwoIpParentsAndIpParentHasMultipleChilds();
+        assertL2ChildHasTwoIpParentsAndIpParentHasMultipleChilds(4L);
     }
 
-    private void assertL2ChildHasTwoIpParentsAndIpParentHasMultipleChilds() {
+    private AddressEndpointBuilder getAddressEndpointBuilder() {
+        return new AddressEndpointBuilder()
+            .setTenant(new TenantId(TENANT))
+            .setEndpointGroup(Collections.singletonList(DEFAULT_EPG))
+            ;
+    }
+
+    private void assertL2ChildHasTwoIpParentsAndIpParentHasMultipleChilds(long expected) {
         List<ProviderAddressEndpointLocation> locations = readLocations();
-        Assert.assertEquals(locations.size(), 4);
+        Assert.assertEquals(expected, locations.size());
         locations.forEach(location -> {
             if (location.getKey().equals(getLocationKey(IP_KEY_1_22))) {
                 assertNodeConnector(location.getAbsoluteLocation(), INTF_NAME);
@@ -478,4 +490,4 @@ public class VppEndpointLocationProviderTest extends CustomDataBrokerTest {
         }
         DataStoreHelper.submitToDs(wTx);
     }
-}
\ No newline at end of file
+}
index 37c68c8a0f4f19373eaad3c3f0b18b3c2ff35280..4b9e1bd5c1c790dc6b63e5fd54798015017ac862 100644 (file)
@@ -27,8 +27,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.ContextType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.Forwarding;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425._interface.attributes._interface.type.choice.VhostUserCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
@@ -40,6 +42,9 @@ public class VppEndpointListenerTest extends CustomDataBrokerTest {
     private final static String ADDRESS = "1.1.1.1/32";
     private final static ContextId CONTEXT_ID = new ContextId("ctx1");
     private final static String IFACE_NAME = "ifaceName";
+    public static final NodeId TEST_NODE = new NodeId("testNode");
+    private static final String DEFAULT_IFACE_NAME = "defaultIfaceName";
+    private static final String TEST_SOCKET = "/tmp/test_socket";
 
     private DataBroker dataBroker;
     private VppEndpointListener listener;
@@ -60,11 +65,7 @@ public class VppEndpointListenerTest extends CustomDataBrokerTest {
     @Test
     public void testOnWrite() throws Exception {
         ArgumentCaptor<VppEndpointConfEvent> argVppEpEvent = ArgumentCaptor.forClass(VppEndpointConfEvent.class);
-        VppEndpoint vppEndpoint = new VppEndpointBuilder().setAddress(ADDRESS)
-            .setAddressType(AddressType.class)
-            .setContextId(CONTEXT_ID)
-            .setContextType(ContextType.class)
-            .build();
+        VppEndpoint vppEndpoint = getBaseVppEndpointBuilder().build();
         InstanceIdentifier<VppEndpoint> vppEpIid =
                 InstanceIdentifier.builder(Config.class).child(VppEndpoint.class, vppEndpoint.getKey()).build();
         WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
@@ -75,16 +76,14 @@ public class VppEndpointListenerTest extends CustomDataBrokerTest {
         VppEndpointConfEvent capturedVppEpEvent = argVppEpEvent.getValue();
         Assert.assertEquals(vppEpIid, capturedVppEpEvent.getIid());
         assertEqualsOptional(null, capturedVppEpEvent.getBefore());
+        Optional<VppEndpoint> after = capturedVppEpEvent.getAfter();
         assertEqualsOptional(vppEndpoint, capturedVppEpEvent.getAfter());
     }
 
     @Test
     public void testOnDelete() throws Exception {
         ArgumentCaptor<VppEndpointConfEvent> argVppEpEvent = ArgumentCaptor.forClass(VppEndpointConfEvent.class);
-        VppEndpoint vppEndpoint = new VppEndpointBuilder().setAddress(ADDRESS)
-            .setAddressType(AddressType.class)
-            .setContextId(CONTEXT_ID)
-            .setContextType(ContextType.class)
+        VppEndpoint vppEndpoint = getBaseVppEndpointBuilder()
             .build();
         InstanceIdentifier<VppEndpoint> vppEpIid =
                 InstanceIdentifier.builder(Config.class).child(VppEndpoint.class, vppEndpoint.getKey()).build();
@@ -105,17 +104,15 @@ public class VppEndpointListenerTest extends CustomDataBrokerTest {
     @Test
     public void testOnSubtreeModified() throws Exception {
         ArgumentCaptor<VppEndpointConfEvent> argVppEpEvent = ArgumentCaptor.forClass(VppEndpointConfEvent.class);
-        VppEndpointBuilder vppEndpointBuilder = new VppEndpointBuilder().setAddress(ADDRESS)
-            .setAddressType(AddressType.class)
-            .setContextId(CONTEXT_ID)
-            .setContextType(ContextType.class);
+        VppEndpointBuilder vppEndpointBuilder = getBaseVppEndpointBuilder();
         VppEndpoint vppEndpoint = vppEndpointBuilder.build();
         InstanceIdentifier<VppEndpoint> vppEpIid =
                 InstanceIdentifier.builder(Config.class).child(VppEndpoint.class, vppEndpoint.getKey()).build();
         WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
         wTx.put(LogicalDatastoreType.CONFIGURATION, vppEpIid, vppEndpoint);
         wTx.submit().get();
-        VppEndpoint modifiedVppEndpoint = vppEndpointBuilder.setVppInterfaceName(IFACE_NAME).build();
+        VppEndpoint modifiedVppEndpoint =
+            vppEndpointBuilder.setVppInterfaceName(IFACE_NAME).build();
         wTx = getDataBroker().newWriteOnlyTransaction();
         wTx.put(LogicalDatastoreType.CONFIGURATION, vppEpIid, modifiedVppEndpoint);
         wTx.submit().get();
@@ -131,6 +128,16 @@ public class VppEndpointListenerTest extends CustomDataBrokerTest {
         assertEqualsOptional(modifiedVppEndpoint, capturedSecondVppEpEvent.getAfter());
     }
 
+    private VppEndpointBuilder getBaseVppEndpointBuilder() {
+        return new VppEndpointBuilder().setAddress(ADDRESS)
+            .setAddressType(AddressType.class)
+            .setContextId(CONTEXT_ID)
+            .setContextType(ContextType.class)
+            .setInterfaceTypeChoice(new VhostUserCaseBuilder().setSocket(TEST_SOCKET).build())
+            .setVppNodeId(TEST_NODE)
+            .setVppInterfaceName(DEFAULT_IFACE_NAME);
+    }
+
     private <T> void assertEqualsOptional(T expected, Optional<T> actual) {
         if (expected == null) {
             Assert.assertFalse(actual.isPresent());
index 27829750738adc35e8fab47c264006e947fd5144..a30516cb3ca5b5da9b3710420c421158271c9a5c 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.groupbasedpolicy.renderer.vpp.policy;
 import java.util.AbstractMap;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.locks.ReentrantLock;
@@ -54,6 +55,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpo
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpointBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpointKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.LocationProviders;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.LocationProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint_location_provider.rev160419.location.providers.location.provider.ProviderAddressEndpointLocation;
@@ -93,6 +96,11 @@ public class VppRendererPolicyManagerTest extends CustomDataBrokerTest {
             IidFactory.rendererIid(VppRenderer.NAME).child(RendererPolicy.class);
     private final static String SOCKET = "socket";
 
+    public static final TenantId TENANT = new TenantId("tenant");
+    public static final List<EndpointGroupId>
+        ENDPOINT_GROUP =
+        Collections.singletonList(new EndpointGroupId("default"));
+
     private MountedDataBrokerProvider mountedDataProviderMock;
     private DataBroker mountPointDataBroker;
     private DataBroker dataBroker;
@@ -401,6 +409,8 @@ public class VppRendererPolicyManagerTest extends CustomDataBrokerTest {
             InstanceIdentifier<VppEndpoint> vppEpIid) {
         AddressEndpoint addrEp = new AddressEndpointBuilder().setKey(new AddressEndpointKey(clientEp.getAddress(),
                 clientEp.getAddressType(), clientEp.getContextId(), clientEp.getContextType()))
+            .setTenant(TENANT)
+            .setEndpointGroup(ENDPOINT_GROUP)
             .build();
         InstanceIdentifier<AddressEndpoint> iid = InstanceIdentifier.create(Endpoints.class)
             .child(AddressEndpoints.class)