<name>binding-rpc-broker</name>
</rpc-registry>
</module>
+ <module>
+ <type xmlns:groupbasedpolicy="urn:opendaylight:params:xml:ns:yang:controller:config:groupbasedpolicy">
+ groupbasedpolicy:base-endpoint-renderer-augmentation-registry-impl
+ </type>
+ <name>base-endpoint-renderer-augmentation-registry</name>
+
+ <data-broker>
+ <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-async-data-broker</type>
+ <name>binding-data-broker</name>
+ </data-broker>
+
+ <rpc-registry>
+ <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-rpc-registry</type>
+ <name>binding-rpc-broker</name>
+ </rpc-registry>
+ </module>
<module>
<type xmlns:groupbasedpolicy="urn:opendaylight:params:xml:ns:yang:controller:config:groupbasedpolicy">
groupbasedpolicy:statistics-manager-impl
<provider>/modules/module[type='ep-renderer-augmentation-registry-impl'][name='ep-renderer-augmentation-registry']</provider>
</instance>
</service>
+ <service>
+ <type xmlns:groupbasedpolicy="urn:opendaylight:params:xml:ns:yang:controller:config:groupbasedpolicy">
+ groupbasedpolicy:base-endpoint-renderer-augmentation-registry
+ </type>
+
+ <instance>
+ <name>base-endpoint-renderer-augmentation-registry</name>
+ <provider>/modules/module[type='base-endpoint-renderer-augmentation-registry-impl'][name='base-endpoint-renderer-augmentation-registry']</provider>
+ </instance>
+ </service>
<service>
<type xmlns:groupbasedpolicy="urn:opendaylight:params:xml:ns:yang:controller:config:groupbasedpolicy">
groupbasedpolicy:statistics-manager
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.config.yang.config.groupbasedpolicy;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.groupbasedpolicy.base_endpoint.BaseEndpointRpcRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BaseEndpointRendererAugmentationRegistryImplModule extends org.opendaylight.controller.config.yang.config.groupbasedpolicy.AbstractBaseEndpointRendererAugmentationRegistryImplModule {
+
+ private static final Logger LOG = LoggerFactory.getLogger(BaseEndpointRendererAugmentationRegistryImplModule.class);
+
+ public BaseEndpointRendererAugmentationRegistryImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ super(identifier, dependencyResolver);
+ }
+
+ public BaseEndpointRendererAugmentationRegistryImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.groupbasedpolicy.BaseEndpointRendererAugmentationRegistryImplModule oldModule, java.lang.AutoCloseable oldInstance) {
+ super(identifier, dependencyResolver, oldModule, oldInstance);
+ }
+
+ @Override
+ public void customValidation() {
+ // add custom validation form module attributes here.
+ }
+
+ @Override
+ public java.lang.AutoCloseable createInstance() {
+ final DataBroker dataProvider = getDataBrokerDependency();
+ final RpcProviderRegistry rpcRegistry = getRpcRegistryDependency();
+
+ BaseEndpointRpcRegistry baseEndpointRpcRegistry = new BaseEndpointRpcRegistry(dataProvider, rpcRegistry);
+ LOG.info("{} successfully started.", BaseEndpointRendererAugmentationRegistryImplModule.class.getCanonicalName());
+ return baseEndpointRpcRegistry;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+/*
+* Generated file
+*
+* Generated from: yang module name: groupbasedpolicy-cfg yang module local name: base-endpoint-renderer-augmentation-registry-impl
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Mon May 09 16:19:05 CEST 2016
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.controller.config.yang.config.groupbasedpolicy;
+public class BaseEndpointRendererAugmentationRegistryImplModuleFactory extends org.opendaylight.controller.config.yang.config.groupbasedpolicy.AbstractBaseEndpointRendererAugmentationRegistryImplModuleFactory {
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.api;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.containment.endpoints.ContainmentEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.register.endpoint.input.AddressEndpointReg;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.register.endpoint.input.ContainmentEndpointReg;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+
+public interface BaseEndpointRendererAugmentation {
+
+ /**
+ * Creates pair of AddressEndpoint augmentation, specific for renderer and augmentation type
+ * (class
+ * name).
+ *
+ * @param input input data for AddressEndpoint creation
+ * @return pair of augmentation type and augmentation
+ */
+ @Nullable
+ Map.Entry<Class<? extends Augmentation<AddressEndpoint>>, Augmentation<AddressEndpoint>> buildAddressEndpointAugmentation(
+ AddressEndpointReg input);
+
+ /**
+ * Creates pair of AddressEndpoint augmentation, specific for renderer and augmentation type
+ * (class
+ * name).
+ *
+ * @param input input data for AddressEndpoint creation
+ * @return pair of augmentation type and augmentation
+ */
+ @Nullable
+ Map.Entry<Class<? extends Augmentation<ContainmentEndpoint>>, Augmentation<ContainmentEndpoint>> buildContainmentEndpointAugmentation(
+ ContainmentEndpointReg input);
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.api;
+
+public interface BaseEndpointRendererAugmentationRegistry {
+
+ /**
+ * Registers renderer's endpoints augmentation.
+ *
+ * @param baseEndpointRendererAugmentation cannot be {@code null}
+ * @throws NullPointerException
+ */
+ void register(BaseEndpointRendererAugmentation baseEndpointRendererAugmentation);
+
+ /**
+ * Unregisters renderer's endpoints augmentation.
+ *
+ * @param baseEndpointRendererAugmentation cannot be {@code null}
+ * @throws NullPointerException
+ */
+ void unregister(BaseEndpointRendererAugmentation baseEndpointRendererAugmentation);
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.base_endpoint;
+
+import com.google.common.base.Function;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.groupbasedpolicy.api.BaseEndpointRendererAugmentation;
+import org.opendaylight.groupbasedpolicy.api.BaseEndpointRendererAugmentationRegistry;
+import org.opendaylight.groupbasedpolicy.util.IidFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpoint;
+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.endpoints.containment.endpoints.ContainmentEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.containment.endpoints.ContainmentEndpointBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.containment.endpoints.ContainmentEndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.register.endpoint.input.AddressEndpointReg;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.register.endpoint.input.ContainmentEndpointReg;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.unregister.endpoint.input.AddressEndpointUnreg;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.unregister.endpoint.input.ContainmentEndpointUnreg;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.Future;
+
+public class BaseEndpointRpcRegistry
+ implements BaseEndpointService, BaseEndpointRendererAugmentationRegistry, AutoCloseable {
+
+ static final ConcurrentMap<String, BaseEndpointRendererAugmentation> registeredRenderers = new ConcurrentHashMap<>();
+ private static final Logger LOG = LoggerFactory.getLogger(BaseEndpointRpcRegistry.class);
+ private final DataBroker dataProvider;
+ private final BindingAwareBroker.RpcRegistration<BaseEndpointService> rpcRegistration;
+
+ private Function<Void, RpcResult<Void>> futureTrans = new Function<Void, RpcResult<Void>>() {
+
+ @Override
+ public RpcResult<Void> apply(Void input) {
+ return RpcResultBuilder.<Void>success().build();
+ }
+ };
+
+ public BaseEndpointRpcRegistry(DataBroker dataProvider, RpcProviderRegistry rpcRegistry) {
+ this.dataProvider = dataProvider;
+
+ if (rpcRegistry != null) {
+ rpcRegistration = rpcRegistry.addRpcImplementation(BaseEndpointService.class, this);
+ LOG.debug("Added Endpoints RPC Implementation Correctly");
+ } else {
+ rpcRegistration = null;
+ }
+
+ if (dataProvider != null) {
+ InstanceIdentifier<Endpoints> iid = InstanceIdentifier.builder(Endpoints.class).build();
+ WriteTransaction t = this.dataProvider.newWriteOnlyTransaction();
+ t.put(LogicalDatastoreType.OPERATIONAL, iid, new EndpointsBuilder().build());
+ CheckedFuture<Void, TransactionCommitFailedException> f = t.submit();
+ Futures.addCallback(f, new FutureCallback<Void>() {
+
+ @Override
+ public void onFailure(Throwable t) {
+ LOG.error("Could not write Endpoints base container", t);
+ }
+
+ @Override
+ public void onSuccess(Void result) {
+ LOG.info("Endpoints container write successful");
+ }
+ });
+ }
+ }
+
+ /**
+ * Registers renderer's endpoints augmentation.
+ *
+ * @param baseEndpointRendererAugmentation cannot be {@code null}
+ * @throws NullPointerException
+ */
+ @Override
+ public void register(BaseEndpointRendererAugmentation baseEndpointRendererAugmentation) {
+ if (baseEndpointRendererAugmentation != null) {
+ registeredRenderers.putIfAbsent(baseEndpointRendererAugmentation.getClass().getName(),
+ baseEndpointRendererAugmentation);
+ LOG.info("Registered {}", baseEndpointRendererAugmentation.getClass().getName());
+ }
+ }
+
+ /**
+ * Unregisters renderer's endpoints augmentation.
+ *
+ * @param baseEndpointRendererAugmentation cannot be {@code null}
+ * @throws NullPointerException
+ */
+ @Override
+ public void unregister(BaseEndpointRendererAugmentation baseEndpointRendererAugmentation) {
+ if (baseEndpointRendererAugmentation == null
+ || !registeredRenderers.containsKey(baseEndpointRendererAugmentation.getClass().getName())) {
+ return;
+ }
+ registeredRenderers.remove(baseEndpointRendererAugmentation.getClass().getName());
+ LOG.info("Unregistered {}", baseEndpointRendererAugmentation.getClass().getName());
+ }
+
+ /**
+ * Register a new endpoint into the registry. If there is already an existing
+ * endpoint with the same keys, they will be overwritten with the new information.
+ *
+ * @param input Endpoint to register
+ */
+ @Override
+ public Future<RpcResult<Void>> registerEndpoint(RegisterEndpointInput input) {
+ long timestamp = System.currentTimeMillis();
+
+ WriteTransaction t = dataProvider.newWriteOnlyTransaction();
+
+ List<ContainmentEndpointReg> endpoints = input.getContainmentEndpointReg();
+ for (ContainmentEndpointReg ce : nullToEmpty(endpoints)) {
+ long stamp = (ce.getTimestamp() == null || ce.getTimestamp() == 0) ? timestamp : ce.getTimestamp();
+ ContainmentEndpoint endpoint = buildContainmentEndpoint(ce).setTimestamp(stamp).build();
+ t.put(LogicalDatastoreType.OPERATIONAL, IidFactory.containmentEndpointIid(endpoint.getKey()), endpoint,
+ true);
+ }
+
+ List<AddressEndpointReg> addressEndpoints = input.getAddressEndpointReg();
+ for (AddressEndpointReg ae : nullToEmpty(addressEndpoints)) {
+ long stamp = (ae.getTimestamp() == null || ae.getTimestamp() == 0) ? timestamp : ae.getTimestamp();
+ AddressEndpoint endpoint = buildAddressEndpoint(ae).setTimestamp(stamp).build();
+ t.put(LogicalDatastoreType.OPERATIONAL, IidFactory.addressEndpointIid(endpoint.getKey()), endpoint, true);
+ }
+
+ ListenableFuture<Void> r = t.submit();
+ return Futures.transform(r, futureTrans);
+ }
+
+ private ContainmentEndpointBuilder buildContainmentEndpoint(ContainmentEndpointReg input) {
+ ContainmentEndpointBuilder eb = new ContainmentEndpointBuilder().setChildEndpoint(input.getChildEndpoint())
+ .setCondition(input.getCondition())
+ .setContextType(input.getContextType())
+ .setContextId(input.getContextId())
+ .setEndpointGroup(input.getEndpointGroup())
+ .setKey(new ContainmentEndpointKey(input.getContextId(), input.getContextType()))
+ .setNetworkContainment(input.getNetworkContainment())
+ .setTenant(input.getTenant())
+ .setTimestamp(input.getTimestamp());
+
+ for (Map.Entry<String, BaseEndpointRendererAugmentation> entry : registeredRenderers.entrySet()) {
+ try {
+ Map.Entry<Class<? extends Augmentation<ContainmentEndpoint>>, Augmentation<ContainmentEndpoint>> augmentationEntry =
+ entry.getValue().buildContainmentEndpointAugmentation(input);
+ if (augmentationEntry != null) {
+ eb.addAugmentation(augmentationEntry.getKey(), augmentationEntry.getValue());
+ }
+ } catch (Exception e) {
+ LOG.warn("AddressEndpoint Augmentation error while processing " + entry.getKey() + ". Reason: ", e);
+ }
+ }
+ return eb;
+ }
+
+ private AddressEndpointBuilder buildAddressEndpoint(AddressEndpointReg ae) {
+ AddressEndpointBuilder builder = new AddressEndpointBuilder().setTenant(ae.getTenant())
+ .setNetworkContainment(ae.getNetworkContainment())
+ .setEndpointGroup(ae.getEndpointGroup())
+ .setAddress(ae.getAddress())
+ .setAddressType(ae.getAddressType())
+ .setChildEndpoint(ae.getChildEndpoint())
+ .setCondition(ae.getCondition())
+ .setKey(new AddressEndpointKey(ae.getAddress(), ae.getAddressType(), ae.getContextId(),
+ ae.getContextType()))
+ .setParentEndpointChoice(ae.getParentEndpointChoice())
+ .setTimestamp(ae.getTimestamp())
+ .setContextId(ae.getContextId())
+ .setContextType(ae.getContextType())
+ .setTenant(ae.getTenant());
+
+ for (Map.Entry<String, BaseEndpointRendererAugmentation> entry : registeredRenderers.entrySet()) {
+ try {
+ Map.Entry<Class<? extends Augmentation<AddressEndpoint>>, Augmentation<AddressEndpoint>> augmentationEntry =
+ entry.getValue().buildAddressEndpointAugmentation(ae);
+ if (augmentationEntry != null) {
+ builder.addAugmentation(augmentationEntry.getKey(), augmentationEntry.getValue());
+ }
+ } catch (Exception e) {
+ LOG.warn("AddressEndpoint Augmentation error while processing " + entry.getKey() + ". Reason: ", e);
+ }
+ }
+ return builder;
+ }
+
+ /**
+ * Unregister an endpoint or endpoints from the registry.
+ *
+ * @param input Endpoint/endpoints to unregister
+ */
+ @Override
+ public Future<RpcResult<Void>> unregisterEndpoint(UnregisterEndpointInput input) {
+ WriteTransaction t = dataProvider.newWriteOnlyTransaction();
+
+ List<AddressEndpointUnreg> addressEndpoints = input.getAddressEndpointUnreg();
+ for (AddressEndpointUnreg ae : nullToEmpty(addressEndpoints)) {
+ AddressEndpointKey key = new AddressEndpointKey(ae.getAddress(), ae.getAddressType(), ae.getContextId(),
+ ae.getContextType());
+ t.delete(LogicalDatastoreType.OPERATIONAL, IidFactory.addressEndpointIid(key));
+ }
+
+ List<ContainmentEndpointUnreg> endpoints = input.getContainmentEndpointUnreg();
+ for (ContainmentEndpointUnreg ce : nullToEmpty(endpoints)) {
+ ContainmentEndpointKey key = new ContainmentEndpointKey(ce.getContextId(), ce.getContextType());
+ t.delete(LogicalDatastoreType.OPERATIONAL, IidFactory.containmentEndpointIid(key));
+ }
+
+ ListenableFuture<Void> r = t.submit();
+ return Futures.transform(r, futureTrans);
+ }
+
+ @Override
+ public void close() throws Exception {
+ if (rpcRegistration != null) {
+ rpcRegistration.close();
+ }
+ }
+
+ private <T> List<T> nullToEmpty(@Nullable List<T> list) {
+ return list == null ? Collections.emptyList() : list;
+ }
+
+}
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.AddressEndpoints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.ContainmentEndpoints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.containment.endpoints.ContainmentEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.containment.endpoints.ContainmentEndpointKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionDefinitionId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ActionName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Key;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3PrefixKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpoint;
+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.policy.rev140421.SubjectFeatureDefinitions;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.Tenants;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.has.classifier.refs.ClassifierRef;
.build();
}
+ public static InstanceIdentifier<ContainmentEndpoint> containmentEndpointIid(ContainmentEndpointKey key) {
+ return InstanceIdentifier
+ .builder(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.Endpoints.class)
+ .child(ContainmentEndpoints.class)
+ .child(ContainmentEndpoint.class, key)
+ .build();
+ }
+
+ public static InstanceIdentifier<AddressEndpoint> addressEndpointIid(AddressEndpointKey addressEndpointKey) {
+ return InstanceIdentifier
+ .builder(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.Endpoints.class)
+ .child(AddressEndpoints.class)
+ .child(AddressEndpoint.class, addressEndpointKey)
+ .build();
+ }
+
}
config:java-class "org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry";
}
+ identity base-endpoint-renderer-augmentation-registry {
+ description
+ "base-endpoint-renderer-augmentation-registry service definition";
+
+ base "config:service-type";
+ config:java-class "org.opendaylight.groupbasedpolicy.api.BaseEndpointRendererAugmentationRegistry";
+ }
+
identity policy-validator-registry {
description
"policy-validator-registry service definition";
config:java-name-prefix EpRendererAugmentationRegistryImpl;
}
+ identity base-endpoint-renderer-augmentation-registry-impl {
+ base "config:module-type";
+
+ config:provided-service base-endpoint-renderer-augmentation-registry;
+ config:java-name-prefix BaseEndpointRendererAugmentationRegistryImpl;
+ }
+
identity statistics-manager-impl {
base "config:module-type";
}
}
}
+ case base-endpoint-renderer-augmentation-registry-impl {
+ when "/config:modules/config:module/config:type = 'base-endpoint-renderer-augmentation-registry-impl'";
+
+ //wires in the data-broker service
+ container data-broker {
+ uses config:service-ref {
+ refine type {
+ mandatory true;
+ config:required-identity mdsal:binding-async-data-broker;
+ }
+ }
+ }
+ //RPC Registry
+ container rpc-registry {
+ uses config:service-ref {
+ refine type {
+ mandatory true;
+ config:required-identity mdsal:binding-rpc-registry;
+ }
+ }
+ }
+ }
case statistics-manager-impl {
when "/config:modules/config:module/config:type = 'statistics-manager-impl'";
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.base_endpoint;
+
+import com.google.common.util.concurrent.CheckedFuture;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.groupbasedpolicy.api.BaseEndpointRendererAugmentation;
+import org.opendaylight.groupbasedpolicy.base_endpoint.BaseEndpointRpcRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.register.endpoint.input.AddressEndpointRegKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.register.endpoint.input.ContainmentEndpointRegKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.RegisterEndpointInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.RegisterEndpointInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.UnregisterEndpointInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.UnregisterEndpointInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.common.endpoint.fields.NetworkContainmentBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.register.endpoint.input.AddressEndpointRegBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.register.endpoint.input.ContainmentEndpointRegBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.unregister.endpoint.input.AddressEndpointUnregBuilder;
+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.forwarding.l2_l3.rev160427.L2FloodDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.MacAddressType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev160427.Subnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.AddressType;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import java.util.ArrayList;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.*;
+import static org.mockito.internal.verification.VerificationModeFactory.times;
+
+public class BaseEndpointRpcRegistryTest {
+
+ private static final String MAC_ADDRESS = "01:23:45:67:89:AB";
+ private static final String TENANT = "admin";
+ private static final String DOMAIN = "test.domain";
+ private static final String CONTEXT_ID = "testContext";
+ private static final String FLOOD_DOMAIN = "testFloodDomain";
+
+ private DataBroker dataProvider;
+ private BaseEndpointRendererAugmentation baseEndpointRendererAugmentation;
+ private BaseEndpointRpcRegistry baseEndpointRpcRegistry;
+
+ @Before
+ public void init() {
+ dataProvider = mock(DataBroker.class);
+ baseEndpointRendererAugmentation = mock(BaseEndpointRendererAugmentation.class);
+ WriteTransaction wt = newWriteTransactionMock();
+ RpcProviderRegistry rpcRegistry = mock(RpcProviderRegistry.class);
+
+ baseEndpointRpcRegistry = new BaseEndpointRpcRegistry(dataProvider, rpcRegistry);
+ }
+
+ @Test
+ public void testConstructor() throws Exception {
+ RpcProviderRegistry rpcRegistry = mock(RpcProviderRegistry.class);
+ BaseEndpointRpcRegistry registry = new BaseEndpointRpcRegistry(dataProvider, rpcRegistry);
+ registry.close();
+ }
+
+ @Test
+ public void testRegister() throws Exception {
+ baseEndpointRpcRegistry.register(baseEndpointRendererAugmentation);
+ Assert.assertEquals(1, BaseEndpointRpcRegistry.registeredRenderers.size());
+
+ baseEndpointRpcRegistry.unregister(baseEndpointRendererAugmentation);
+ Assert.assertEquals(0, BaseEndpointRpcRegistry.registeredRenderers.size());
+ }
+
+ @Test
+ public void testRegisterEndpoint() throws Exception {
+ WriteTransaction wt = newWriteTransactionMock();
+
+ baseEndpointRpcRegistry.registerEndpoint(createRegisterEndpointInputVariablesForTest());
+
+ verify(wt, times(2)).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+ any(DataObject.class), eq(true));
+ }
+
+ private RegisterEndpointInput createRegisterEndpointInputVariablesForTest() throws Exception {
+ RegisterEndpointInputBuilder registerEndpointInputBuilder = new RegisterEndpointInputBuilder();
+ long timestamp = System.currentTimeMillis();
+
+ registerEndpointInputBuilder.setAddressEndpointReg(new ArrayList<>());
+ registerEndpointInputBuilder.setContainmentEndpointReg(new ArrayList<>());
+
+ registerEndpointInputBuilder.getAddressEndpointReg().add(
+ new AddressEndpointRegBuilder().setTimestamp(timestamp)
+ .setContextId(new ContextId(CONTEXT_ID))
+ .setContextType(L2FloodDomain.class)
+ .setTenant(new TenantId(TENANT))
+ .setAddress(MAC_ADDRESS)
+ .setAddressType(MacAddressType.class)
+ .setAddressType(AddressType.class)
+ .setNetworkContainment(new NetworkContainmentBuilder()
+ .setNetworkDomainId(new NetworkDomainId(DOMAIN)).setNetworkDomainType(Subnet.class).build())
+ .setKey(new AddressEndpointRegKey(MAC_ADDRESS,MacAddressType.class, new ContextId(CONTEXT_ID), L2FloodDomain.class))
+ .setTimestamp(timestamp).build());
+
+ registerEndpointInputBuilder.getContainmentEndpointReg().add(
+ new ContainmentEndpointRegBuilder()
+ .setTimestamp(timestamp)
+ .setContextId(new L2FloodDomainId(FLOOD_DOMAIN))
+ .setContextType(L2FloodDomain.class)
+ .setTenant(new TenantId(TENANT))
+ .setNetworkContainment(new NetworkContainmentBuilder()
+ .setNetworkDomainId(new NetworkDomainId(DOMAIN)).setNetworkDomainType(Subnet.class).build())
+ .setKey(new ContainmentEndpointRegKey(new L2FloodDomainId(FLOOD_DOMAIN),L2FloodDomain.class))
+ .build());
+
+ return registerEndpointInputBuilder.build();
+ }
+
+ @Test
+ public void testUnregisterEndpoint() throws Exception {
+ WriteTransaction wt = newWriteTransactionMock();
+
+ UnregisterEndpointInput unregisterEndpointInput = unregisterEndpointInput();
+
+ baseEndpointRpcRegistry.unregisterEndpoint(unregisterEndpointInput);
+
+ verify(wt, times(2)).delete(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
+ }
+
+ private UnregisterEndpointInput unregisterEndpointInput() {
+ UnregisterEndpointInputBuilder builder = new UnregisterEndpointInputBuilder();
+
+ builder.setAddressEndpointUnreg(new ArrayList<>());
+ builder.setContainmentEndpointUnreg(new ArrayList<>());
+
+ builder.getAddressEndpointUnreg().add(new AddressEndpointUnregBuilder().setContextId(new ContextId(CONTEXT_ID))
+ .setContextType(L2FloodDomain.class)
+ .setAddress(MAC_ADDRESS)
+ .setAddressType(MacAddressType.class)
+ .build());
+
+ builder.getContainmentEndpointUnreg().add(new ContainmentEndpointUnregBuilder()
+ .setContextId(new ContextId(CONTEXT_ID)).setContextType(L2FloodDomain.class).build());
+
+ return builder.build();
+ }
+
+ private WriteTransaction newWriteTransactionMock() {
+ WriteTransaction wt = mock(WriteTransaction.class);
+ CheckedFuture<Void, TransactionCommitFailedException> f = mock(CheckedFuture.class);
+
+ when(dataProvider.newWriteOnlyTransaction()).thenReturn(wt);
+ when(wt.submit()).thenReturn(f);
+ return wt;
+ }
+
+}