public void initialize() {
LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
- singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
+ try {
+ singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
+ }
+ catch (Exception e) {
+ LOG.warn("Exception while registering candidate ... ", e);
+ }
}
@Override
public void initialize() {
LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
- singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
+ try {
+ singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
+ }
+ catch (Exception e) {
+ LOG.warn("Exception while registering candidate ... ", e);
+ }
}
@Override
public void initialize() {
LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
- singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
+ try {
+ singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
+ }
+ catch (Exception e) {
+ LOG.warn("Exception while registering candidate ... ", e);
+ }
}
@Override
public void initialize() {
LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
- singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
+ try {
+ singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
+ }
+ catch (Exception e) {
+ LOG.warn("Exception while registering candidate ... ", e);
+ }
}
@Override
public void initialize() {
LOG.info("Clustering session initiated for {}", this.getClass().getSimpleName());
- singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
+ try {
+ singletonServiceRegistration = clusterSingletonService.registerClusterSingletonService(this);
+ }
+ catch (Exception e) {
+ LOG.warn("Exception while registering candidate ... ", e);
+ }
}
@Override
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortKey;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.portsecurity.rev150712.PortSecurityExtension;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;\r
@VisibleForTesting\r
VppEndpoint buildVppEndpoint(Port port, BaseEndpointByPort bebp) {\r
PortBindingExtension portBinding = port.getAugmentation(PortBindingExtension.class);\r
+ ExcludeFromPolicy excludeFromPolicy = new ExcludeFromPolicyBuilder().setExcludeFromPolicy(true).build();\r
VppEndpointBuilder vppEpBuilder = new VppEndpointBuilder().setDescription("neutron port")\r
.setContextId(bebp.getContextId())\r
.setContextType(bebp.getContextType())\r
.setAddressType(bebp.getAddressType())\r
.setVppInterfaceName(VPP_INTERFACE_NAME_PREFIX + bebp.getPortId().getValue())\r
.setVppNodeId(new NodeId(portBinding.getHostId()));\r
+\r
if (port.getDeviceOwner().contains(COMPUTE_OWNER)) {\r
vppEpBuilder.setInterfaceTypeChoice(\r
- new VhostUserCaseBuilder().setSocket(getSocketFromPortBinding(portBinding)).build());\r
+ new VhostUserCaseBuilder().setSocket(getSocketFromPortBinding(portBinding)).build());\r
+ Optional<PortSecurityExtension> portSecurity =\r
+ Optional.fromNullable(port.getAugmentation(PortSecurityExtension.class));\r
+ if (portSecurity.isPresent() && !portSecurity.get().isPortSecurityEnabled()) {\r
+ vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy);\r
+ }\r
+\r
} else if (port.getDeviceOwner().contains(DHCP_OWNER) && port.getMacAddress() != null) {\r
IpAddress dhcpServerIpAddress = port.getFixedIps().stream().findFirst().isPresent() ?\r
port.getFixedIps().stream().findFirst().get().getIpAddress() : null;\r
.setDhcpServerAddress(dhcpServerIpAddress)\r
.build();\r
vppEpBuilder.setInterfaceTypeChoice(tapCase);\r
+\r
} else if (isValidQRouterPort(port)) {\r
TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue()))\r
.setName(createQRouterPortName(port.getUuid()))\r
.build();\r
vppEpBuilder.setInterfaceTypeChoice(tapCase);\r
- vppEpBuilder.addAugmentation(ExcludeFromPolicy.class,\r
- new ExcludeFromPolicyBuilder().setExcludeFromPolicy(true).build());\r
+ vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy);\r
+\r
} else if (isValidVppRouterPort(port)) {\r
if (!DEFAULT_NODE.equals(routingNode.getValue())) {\r
LOG.warn(\r
}\r
}\r
}\r
- vppEpBuilder.addAugmentation(ExcludeFromPolicy.class,\r
- new ExcludeFromPolicyBuilder().setExcludeFromPolicy(true).build());\r
+ vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy);\r
vppEpBuilder.setInterfaceTypeChoice(getLoopbackCase(port));\r
}\r
return vppEpBuilder.build();\r
package org.opendaylight.controller.config.yang.config.vpp_provider.impl;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.eventbus.EventBus;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.MountPointService;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.groupbasedpolicy.renderer.vpp.dhcp.DhcpRelayHandler;
import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.InterfaceManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.LispStateManager;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.loopback.LoopbackManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.event.manager.GbpSubnetEventManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.flat.overlay.FlatOverlayManager;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.loopback.LoopbackManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.listener.GbpSubnetListener;
import org.opendaylight.groupbasedpolicy.renderer.vpp.listener.RendererPolicyListener;
import org.opendaylight.groupbasedpolicy.renderer.vpp.listener.VppEndpointListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import java.util.ArrayList;
-import java.util.List;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.eventbus.EventBus;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
public class VppRenderer implements AutoCloseable, BindingAwareProvider {
LoopbackManager loopbackManager = new LoopbackManager(mountDataProvider);
interfaceManager = new InterfaceManager(mountDataProvider, dataBroker, flatOverlayManager);
- AclManager aclManager = new AclManager(mountDataProvider);
+ AclManager aclManager = new AclManager(mountDataProvider, interfaceManager);
NatManager natManager = new NatManager(dataBroker, mountDataProvider);
subnetEventManager = new GbpSubnetEventManager(loopbackManager);
dtoEventBus.register(interfaceManager);
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
public class VppRpcServiceImpl implements VppAdapterService, AutoCloseable {
ifaceCommand = tapBuilder.build();
}
InstanceIdentifier<Node> vppNodeIid = VppIidFactory.getNetconfNodeIid(input.getVppNodeId());
- Optional<DataBroker> optDataBroker = mountDataProvider.getDataBrokerForMountPoint(vppNodeIid);
- if (!optDataBroker.isPresent()) {
- return Futures.immediateFuture(RpcResultBuilder.<Void>failed()
- .withError(ErrorType.RPC, "Cannot find data broker for mount point " + vppNodeIid)
- .build());
- }
- return Futures.transformAsync(interfaceManager.createInterfaceOnVpp(ifaceCommand, optDataBroker.get()),
- voidToRpcResult());
+ return Futures.transformAsync(interfaceManager.createInterfaceOnVpp(ifaceCommand, vppNodeIid),
+ voidToRpcResult(), MoreExecutors.directExecutor());
}
public ListenableFuture<RpcResult<Void>> deleteInterfaceFromNode(DeleteInterfaceFromNodeInput input) {
+ ". Not found or already deleted.")
.build());
}
- Optional<DataBroker> dataBroker = mountDataProvider.getDataBrokerForMountPoint(vppNodeIid);
+ Optional<DataBroker> dataBroker = mountDataProvider.resolveDataBrokerForMountPoint(vppNodeIid);
WriteTransaction wTx = dataBroker.get().newWriteOnlyTransaction();
wTx.delete(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(iKey));
- return Futures.transformAsync(wTx.submit(), voidToRpcResult());
+ return Futures.transformAsync(wTx.submit(), voidToRpcResult(), MoreExecutors.directExecutor());
}
- });
+ }, MoreExecutors.directExecutor());
}
public ListenableFuture<RpcResult<Void>> addInterfaceToBridgeDomain(AddInterfaceToBridgeDomainInput input) {
+ vppNodeIid + ". Not found or deleted.")
.build());
}
- Optional<DataBroker> dataBroker = mountDataProvider.getDataBrokerForMountPoint(vppNodeIid);
- return Futures.transformAsync(interfaceManager.configureInterface(dataBroker.get(), iKey,
- input.getBridgeDomainId(), null), voidToRpcResult());
+ return Futures.transformAsync(interfaceManager.configureInterface(vppNodeIid, iKey,
+ input.getBridgeDomainId(), null), voidToRpcResult(), MoreExecutors.directExecutor());
}
- });
+ }, MoreExecutors.directExecutor());
}
public ListenableFuture<RpcResult<Void>> delInterfaceFromBridgeDomain(DelInterfaceFromBridgeDomainInput input) {
+ ". Not found or deleted.")
.build());
}
- Optional<DataBroker> dataBroker = mountDataProvider.getDataBrokerForMountPoint(vppNodeIid);
- return Futures.transformAsync(interfaceManager.removeInterfaceFromBridgeDomain(dataBroker.get(),
- optIface.get().getKey()), voidToRpcResult());
+ return Futures.transformAsync(interfaceManager.removeInterfaceFromBridgeDomain(vppNodeIid,
+ optIface.get().getKey()), voidToRpcResult(), MoreExecutors.directExecutor());
}
- });
+ }, MoreExecutors.directExecutor());
}
- private CheckedFuture<Optional<Interface>, ReadFailedException> readInterface(InstanceIdentifier<?> nodeIid,
+ private CheckedFuture<Optional<Interface>, ReadFailedException> readInterface(InstanceIdentifier<Node> nodeIid,
String interfaceName) {
- Optional<DataBroker> optDataBroker = mountDataProvider.getDataBrokerForMountPoint(nodeIid);
+ Optional<DataBroker> optDataBroker = mountDataProvider.resolveDataBrokerForMountPoint(nodeIid);
if (!optDataBroker.isPresent()) {
LOG.error("Cannot find data broker for node {}", nodeIid);
return Futures.immediateCheckedFuture(Optional.absent());
package org.opendaylight.groupbasedpolicy.renderer.vpp.commands;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
+import java.util.Collections;
+
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General.Operations;
import org.opendaylight.groupbasedpolicy.util.NetUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.RoutingBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.interconnection.BridgeBasedBuilder;
-import java.util.Collections;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
public class LoopbackCommand extends AbstractInterfaceCommand {
vppAugmentationBuilder.setL2(new L2Builder().setInterconnection(
new BridgeBasedBuilder().setBridgeDomain(bridgeDomain).setBridgedVirtualInterface(bvi).build())
.build());
+
}
Interface1Builder
interface1Builder =
package org.opendaylight.groupbasedpolicy.renderer.vpp.commands;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General.Operations;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.TapBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.interconnection.BridgeBasedBuilder;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+
public class TapPortCommand extends AbstractInterfaceCommand {
private String tapName;
return new VhostUserCommand(this);
}
}
-}
+}
\ No newline at end of file
package org.opendaylight.groupbasedpolicy.renderer.vpp.dhcp;
-import com.google.common.base.Optional;
-import com.google.common.collect.SetMultimap;
+import static org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory.getVppRendererConfig;
+
+import java.util.Collections;
+import java.util.Set;
+import java.util.stream.Stream;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.DhcpRelayCommand;
import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
import org.opendaylight.groupbasedpolicy.util.NetUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.has.subnet.Subnet;
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.TapCase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Collections;
-import java.util.Set;
-import java.util.stream.Stream;
-
-import static org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory.getVppRendererConfig;
+import com.google.common.base.Optional;
+import com.google.common.collect.SetMultimap;
public class DhcpRelayHandler {
private static final Logger LOG = LoggerFactory.getLogger(DhcpRelayHandler.class);
- private final MountedDataBrokerProvider mountDataProvider;
private final DataBroker dataBroker;
+ // TODO remove argument
public DhcpRelayHandler(DataBroker dataBroker, MountedDataBrokerProvider mountDataProvider) {
- this.mountDataProvider = mountDataProvider;
this.dataBroker = dataBroker;
}
private boolean submitDhcpRelay(DhcpRelayCommand dhcpRelayCommand, NodeId nodeIid) {
LOG.trace("Submitting DhcpRelay command: {}, nodeId: {}", dhcpRelayCommand, nodeIid);
-
- Optional<DataBroker> mountPointDataBroker =
- mountDataProvider.getDataBrokerForMountPoint(VppIidFactory.getNetconfNodeIid(nodeIid));
- if (!mountPointDataBroker.isPresent()) {
- throw new IllegalStateException("Cannot find data broker for mount point " + nodeIid);
- }
if (dhcpRelayCommand.getOperation() == General.Operations.PUT) {
- return GbpNetconfTransaction.netconfSyncedWrite(mountPointDataBroker.get(), dhcpRelayCommand,
+ return GbpNetconfTransaction.netconfSyncedWrite(VppIidFactory.getNetconfNodeIid(nodeIid), dhcpRelayCommand,
GbpNetconfTransaction.RETRY_COUNT);
} else if (dhcpRelayCommand.getOperation() == General.Operations.DELETE) {
- return GbpNetconfTransaction.netconfSyncedDelete(mountPointDataBroker.get(), dhcpRelayCommand,
+ return GbpNetconfTransaction.netconfSyncedDelete(VppIidFactory.getNetconfNodeIid(nodeIid), dhcpRelayCommand,
GbpNetconfTransaction.RETRY_COUNT);
}
return false;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.ExecutionException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import com.google.common.eventbus.Subscribe;
-import com.google.common.util.concurrent.AsyncFunction;
-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.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.AbstractInterfaceCommand;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.interfaces.ConfigCommand;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.LoopbackCommand;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.TapPortCommand;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.VhostUserCommand;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.VhostUserCommand.VhostUserCommandBuilder;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.interfaces.ConfigCommand;
import org.opendaylight.groupbasedpolicy.renderer.vpp.config.ConfigUtil;
import org.opendaylight.groupbasedpolicy.renderer.vpp.event.NodeOperEvent;
import org.opendaylight.groupbasedpolicy.renderer.vpp.event.VppEndpointConfEvent;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppRendererProcessingException;
import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.vbd.impl.transaction.VbdNetconfTransaction;
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 com.google.common.base.Strings;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.SetMultimap;
+import com.google.common.eventbus.Subscribe;
+import com.google.common.util.concurrent.AsyncFunction;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
public class InterfaceManager implements AutoCloseable {
@Subscribe
@SuppressWarnings("OptionalGetWithoutIsPresent")
public synchronized void vppEndpointChanged(VppEndpointConfEvent event) {
- ListenableFuture<Void> modificationFuture;
- ListenableFuture<Boolean> policyExcludedFuture;
String message;
final VppEndpoint oldVppEndpoint = event.getBefore().orNull();
final VppEndpoint newVppEndpoint = event.getAfter().orNull();
+ try {
switch (event.getDtoModificationType()) {
case CREATED: {
Preconditions.checkNotNull(newVppEndpoint);
- modificationFuture = vppEndpointCreated(newVppEndpoint);
+ vppEndpointCreated(newVppEndpoint).get();
message = String.format("Vpp endpoint %s on node %s and interface %s created",
newVppEndpoint.getAddress(), newVppEndpoint.getVppNodeId().getValue(),
newVppEndpoint.getVppInterfaceName());
- policyExcludedFuture = updatePolicyExcludedEndpoints(newVppEndpoint, true);
+ updatePolicyExcludedEndpoints(newVppEndpoint, true).get();
}
break;
case UPDATED: {
Preconditions.checkNotNull(oldVppEndpoint);
Preconditions.checkNotNull(newVppEndpoint);
- modificationFuture = vppEndpointUpdated(oldVppEndpoint, newVppEndpoint);
+ vppEndpointUpdated(oldVppEndpoint, newVppEndpoint).get();
message = String.format("Vpp endpoint %s on node %s and interface %s updated",
newVppEndpoint.getAddress(), newVppEndpoint.getVppNodeId().getValue(),
newVppEndpoint.getVppInterfaceName());
- final ListenableFuture<Boolean> partialOldPolicyExcludedFuture =
- updatePolicyExcludedEndpoints(oldVppEndpoint, false);
- policyExcludedFuture =
- Futures.transformAsync(partialOldPolicyExcludedFuture, (AsyncFunction<Boolean, Boolean>) input ->
- updatePolicyExcludedEndpoints(newVppEndpoint, true));
+ updatePolicyExcludedEndpoints(oldVppEndpoint, true).get();
}
break;
case DELETED: {
Preconditions.checkNotNull(oldVppEndpoint);
- modificationFuture = vppEndpointDeleted(oldVppEndpoint);
+ vppEndpointDeleted(oldVppEndpoint).get();
message = String.format("Vpp endpoint %s on node %s and interface %s removed",
oldVppEndpoint.getAddress(), oldVppEndpoint.getVppNodeId().getValue(),
oldVppEndpoint.getVppInterfaceName());
- policyExcludedFuture = updatePolicyExcludedEndpoints(event.getBefore().get(), false);
+ updatePolicyExcludedEndpoints(event.getBefore().get(), false).get();
}
break;
- default: {
- message = "Unknown event modification type: " + event.getDtoModificationType();
- modificationFuture = Futures.immediateFailedFuture(new VppRendererProcessingException(message));
- policyExcludedFuture = Futures.immediateFailedFuture(new VppRendererProcessingException(message));
- }
+ default: {
+ message = "Unknown event modification type: " + event.getDtoModificationType();
+ LOG.error("Failed to process VPP endpoint {}. {}",
+ (oldVppEndpoint != null) ? oldVppEndpoint.getKey() : newVppEndpoint.getKey(),
+ event.getAfter(), new VppRendererProcessingException(message));
+ }
+ }
+ LOG.info(message);
+ } catch (InterruptedException | ExecutionException e) {
+ // TODO Auto-generated catch block
+ LOG.error("Failed to process changed vpp endpoint - before: {}, after {}: ", event.getBefore(),
+ event.getBefore());
}
- // Modification
- Futures.addCallback(modificationFuture, new FutureCallback<Void>() {
- @Override
- public void onSuccess(@Nullable Void result) {
- LOG.info(message);
- }
-
- @Override
- public void onFailure(@Nonnull Throwable t) {
- LOG.warn("Vpp endpoint change event failed. Old ep: {}, new ep: {}", oldVppEndpoint, newVppEndpoint);
- }
- });
-
- // Excluded policy
- Futures.addCallback(policyExcludedFuture, new FutureCallback<Boolean>() {
- @Override
- public void onSuccess(@Nullable Boolean input) {
- // NO-OP
- }
-
- @Override
- public void onFailure(@Nonnull Throwable throwable) {
- LOG.warn("Vpp endpoint exclusion failed. Odl ep: {}, new ep: {}", oldVppEndpoint, newVppEndpoint);
- }
- });
}
private ListenableFuture<Boolean> updatePolicyExcludedEndpoints(VppEndpoint vppEndpoint, boolean created) {
}
ConfigCommand ifaceWithoutBdCommand = potentialIfaceCommand.get();
InstanceIdentifier<Node> vppNodeIid = VppIidFactory.getNetconfNodeIid(vppEndpoint.getVppNodeId());
- Optional<DataBroker> potentialVppDataProvider = mountDataProvider.getDataBrokerForMountPoint(vppNodeIid);
+ Optional<DataBroker> potentialVppDataProvider = mountDataProvider.resolveDataBrokerForMountPoint(vppNodeIid);
if (!potentialVppDataProvider.isPresent()) {
final String message = "Cannot get data broker for mount point " + vppNodeIid;
LOG.warn(message);
return Futures.immediateFailedFuture(new VppRendererProcessingException(message));
}
- DataBroker vppDataBroker = potentialVppDataProvider.get();
- return createInterfaceWithEndpointLocation(ifaceWithoutBdCommand, vppDataBroker, vppEndpoint, vppNodeIid);
+ return createInterfaceWithEndpointLocation(ifaceWithoutBdCommand, vppNodeIid, vppEndpoint);
}
public ListenableFuture<Void> createInterfaceOnVpp(final ConfigCommand createIfaceWithoutBdCommand,
- final DataBroker vppDataBroker) {
- final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(vppDataBroker, createIfaceWithoutBdCommand,
+ final InstanceIdentifier<Node> vppIid) {
+ final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(vppIid, createIfaceWithoutBdCommand,
GbpNetconfTransaction.RETRY_COUNT);
if (transactionState) {
LOG.trace("Creating Interface on VPP: {}", createIfaceWithoutBdCommand);
}
private ListenableFuture<Void> createInterfaceWithEndpointLocation(final ConfigCommand createIfaceWithoutBdCommand,
- final DataBroker vppDataBroker,
- final VppEndpoint vppEndpoint,
- final InstanceIdentifier<?> vppNodeIid) {
- final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(vppDataBroker, createIfaceWithoutBdCommand,
+ final InstanceIdentifier<Node> vppIid,
+ final VppEndpoint vppEndpoint) {
+ final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(vppIid, createIfaceWithoutBdCommand,
GbpNetconfTransaction.RETRY_COUNT);
if (transactionState) {
- LOG.debug("Create interface on VPP command was successful. VPP: {} Command: {}", vppNodeIid,
+ LOG.debug("Create interface on VPP command was successful. VPP: {} Command: {}", vppIid,
createIfaceWithoutBdCommand);
return vppEndpointLocationProvider.createLocationForVppEndpoint(vppEndpoint);
} else {
- final String message = "Create interface on VPP command was not successful. VPP: " + vppNodeIid
+ final String message = "Create interface on VPP command was not successful. VPP: " + vppIid
+ " Command: " + createIfaceWithoutBdCommand;
LOG.warn(message);
return Futures.immediateFailedFuture(new VppRendererProcessingException(message));
}
AbstractInterfaceCommand ifaceWithoutBdCommand = potentialIfaceCommand.get();
InstanceIdentifier<Node> vppNodeIid = VppIidFactory.getNetconfNodeIid(vppEndpoint.getVppNodeId());
- Optional<DataBroker> potentialVppDataProvider = mountDataProvider.getDataBrokerForMountPoint(vppNodeIid);
+ Optional<DataBroker> potentialVppDataProvider = mountDataProvider.resolveDataBrokerForMountPoint(vppNodeIid);
if (!potentialVppDataProvider.isPresent()) {
final String message = "Cannot get data broker for mount point " + vppNodeIid;
LOG.warn(message);
if (ConfigUtil.getInstance().isL3FlatEnabled()) {
flatOverlayManager.handleInterfaceDeleteForFlatOverlay(vppDataBroker, vppEndpoint);
}
-
- return deleteIfaceOnVpp(ifaceWithoutBdCommand, vppDataBroker, vppEndpoint, vppNodeIid);
+ return deleteIfaceOnVpp(ifaceWithoutBdCommand, vppNodeIid, vppEndpoint);
}
- private ListenableFuture<Void> deleteIfaceOnVpp(AbstractInterfaceCommand deleteIfaceWithoutBdCommand,
- DataBroker vppDataBroker, VppEndpoint vppEndpoint, InstanceIdentifier<?> vppNodeIid) {
+ private ListenableFuture<Void> deleteIfaceOnVpp(AbstractInterfaceCommand deleteIfaceWithoutBdCommand, InstanceIdentifier<Node> vppIid,
+ VppEndpoint vppEndpoint) {
InterfaceBuilder intfBuilder = deleteIfaceWithoutBdCommand.getInterfaceBuilder();
- final boolean transactionState = GbpNetconfTransaction.netconfSyncedDelete(vppDataBroker,
+ final boolean transactionState = GbpNetconfTransaction.netconfSyncedDelete(vppIid,
deleteIfaceWithoutBdCommand, GbpNetconfTransaction.RETRY_COUNT);
if (transactionState) {
- LOG.debug("Delete interface on VPP command was successful: VPP: {} Command: {}", vppNodeIid,
+ LOG.debug("Delete interface on VPP command was successful: VPP: {} Command: {}", vppIid,
deleteIfaceWithoutBdCommand);
- AccessListWrapper.removeAclsForInterface(vppDataBroker, new InterfaceKey(intfBuilder.getName()));
+ AccessListWrapper.removeAclsForInterface(vppIid, new InterfaceKey(intfBuilder.getName()));
return vppEndpointLocationProvider.deleteLocationForVppEndpoint(vppEndpoint);
} else {
- final String message = "Delete interface on VPP command was not successful: VPP: " + vppNodeIid
+ final String message = "Delete interface on VPP command was not successful: VPP: " + vppIid
+ " Command: " + deleteIfaceWithoutBdCommand;
LOG.warn(message);
return Futures.immediateFailedFuture(new VppRendererProcessingException(message));
* {@link ExternalLocationCase} where
* {@link ExternalLocationCase#getExternalNodeMountPoint()} MUST NOT be {@code null}
* and {@link ExternalLocationCase#getExternalNodeConnector()} MUST NOT be {@code null}
+ * @param aclWrappers wrappers for ACLs
+ * @param enableBvi BVI enabled/disabled
* @return {@link ListenableFuture}
*/
public synchronized ListenableFuture<Void> addBridgeDomainToInterface(@Nonnull String bridgeDomainName,
@Nonnull List<AccessListWrapper> aclWrappers,
boolean enableBvi) {
ExternalLocationCase epLoc = resolveAndValidateLocation(addrEpWithLoc);
- InstanceIdentifier<?> vppNodeIid = epLoc.getExternalNodeMountPoint();
+ InstanceIdentifier<Node> vppNodeIid = (InstanceIdentifier<Node>) epLoc.getExternalNodeMountPoint();
String interfacePath = epLoc.getExternalNodeConnector();
Optional<InstanceIdentifier<Interface>> optInterfaceIid =
new Exception("Cannot resolve interface instance-identifier for interface path" + interfacePath));
}
InstanceIdentifier<Interface> interfaceIid = optInterfaceIid.get();
- Optional<DataBroker> potentialVppDataProvider = mountDataProvider.getDataBrokerForMountPoint(vppNodeIid);
+ Optional<DataBroker> potentialVppDataProvider = mountDataProvider.resolveDataBrokerForMountPoint(vppNodeIid);
if (!potentialVppDataProvider.isPresent()) {
return Futures.immediateFailedFuture(new Exception("Cannot get data broker for mount point " + vppNodeIid));
}
- final DataBroker mountpoint = potentialVppDataProvider.get();
- Optional<Interface> optInterface = GbpNetconfTransaction.read(mountpoint, LogicalDatastoreType.CONFIGURATION,
+ Optional<Interface> optInterface = GbpNetconfTransaction.read(vppNodeIid, LogicalDatastoreType.CONFIGURATION,
interfaceIid, GbpNetconfTransaction.RETRY_COUNT);
if (!optInterface.isPresent()) {
}
InstanceIdentifier<L2> l2Iid =
interfaceIid.builder().augmentation(VppInterfaceAugmentation.class).child(L2.class).build();
- Optional<L2> optL2 = GbpNetconfTransaction.read(mountpoint, LogicalDatastoreType.CONFIGURATION,
+ Optional<L2> optL2 = GbpNetconfTransaction.read(vppNodeIid, LogicalDatastoreType.CONFIGURATION,
l2Iid, GbpNetconfTransaction.RETRY_COUNT);
L2Builder l2Builder = (optL2.isPresent()) ? new L2Builder(optL2.get()) : new L2Builder();
L2 l2 = l2Builder.setInterconnection(new BridgeBasedBuilder()
.setBridgedVirtualInterface(enableBvi)
.build()).build();
LOG.debug("Adding bridge domain {} to interface {}", bridgeDomainName, interfacePath);
- final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(mountpoint, l2Iid, l2,
+ LOG.info("Debugging L2: iid={}, data={}", l2Iid, l2);
+ final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(vppNodeIid, l2Iid, l2,
GbpNetconfTransaction.RETRY_COUNT);
if (transactionState) {
LOG.debug("Adding bridge domain {} to interface {} successful", bridgeDomainName, interfacePath);
Set<String> excludedIfaces = excludedFromPolicy.get(vppNodeIid.firstKeyOf(Node.class).getNodeId());
- if(excludedIfaces == null || !excludedIfaces.contains(interfaceIid.firstKeyOf(Interface.class).getName())) {
+ if (!isExcludedFromPolicy(vppNodeIid.firstKeyOf(Node.class).getNodeId(),
+ interfaceIid.firstKeyOf(Interface.class).getName())) {
// can apply ACLs on interfaces in bridge domains
aclWrappers.forEach(aclWrapper -> {
- LOG.debug("Writing access list for interface {} on a node {}.", interfaceIid,
- vppNodeIid);
- aclWrapper.writeAcl(mountpoint, interfaceIid.firstKeyOf(Interface.class));
- aclWrapper.writeAclRefOnIface(mountpoint, interfaceIid);
+ LOG.debug("Writing access list for interface {} on a node {}.", interfaceIid, vppNodeIid);
+ aclWrapper.writeAcl(vppNodeIid, interfaceIid.firstKeyOf(Interface.class));
+ aclWrapper.writeAclRefOnIface(vppNodeIid, interfaceIid);
});
}
String bridgeDomainPath = VppPathMapper.bridgeDomainToRestPath(bridgeDomainName);
}
}
- public ListenableFuture<Void> configureInterface(DataBroker mountPoint, InterfaceKey ifaceKey, @Nullable String bridgeDomainName,
+ public boolean isExcludedFromPolicy(@Nonnull NodeId nodeId,@Nonnull String interfaceName) {
+ Set<String> excludedIfaces = excludedFromPolicy.get(nodeId);
+ if(excludedIfaces != null && excludedIfaces.contains(interfaceName)) {
+ return true;
+ }
+ return false;
+ }
+
+ public ListenableFuture<Void> configureInterface(InstanceIdentifier<Node> vppIid, InterfaceKey ifaceKey, @Nullable String bridgeDomainName,
@Nullable Boolean enableBvi) {
- L2Builder l2Builder = readL2ForInterface(mountPoint, ifaceKey);
+ L2Builder l2Builder = readL2ForInterface(vppIid, ifaceKey);
L2 l2 = l2Builder.setInterconnection(new BridgeBasedBuilder()
.setBridgeDomain(bridgeDomainName)
.setBridgedVirtualInterface(enableBvi)
.build()).build();
- final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(mountPoint,
+ final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(vppIid,
VppIidFactory.getL2ForInterfaceIid(ifaceKey), l2, GbpNetconfTransaction.RETRY_COUNT);
if (transactionState) {
LOG.debug("Adding bridge domain {} to interface {}", bridgeDomainName, VppIidFactory.getInterfaceIID(ifaceKey));
}
}
- public ListenableFuture<Void> removeInterfaceFromBridgeDomain(DataBroker mountPoint, InterfaceKey ifaceKey) {
- L2Builder l2Builder = readL2ForInterface(mountPoint, ifaceKey);
+ public ListenableFuture<Void> removeInterfaceFromBridgeDomain(InstanceIdentifier<Node> vppIid, InterfaceKey ifaceKey) {
+ L2Builder l2Builder = readL2ForInterface(vppIid, ifaceKey);
if (l2Builder.getInterconnection() == null || !(l2Builder.getInterconnection() instanceof BridgeBased)) {
LOG.warn("Interface already not in bridge domain {} ", ifaceKey);
return Futures.immediateFuture(null);
}
- final boolean transactionState = GbpNetconfTransaction.netconfSyncedDelete(mountPoint,
+ final boolean transactionState = GbpNetconfTransaction.netconfSyncedDelete(vppIid,
VppIidFactory.getL2ForInterfaceIid(ifaceKey), GbpNetconfTransaction.RETRY_COUNT);
if (transactionState) {
LOG.debug("Removing bridge domain from interface {}", VppIidFactory.getInterfaceIID(ifaceKey));
}
}
- private L2Builder readL2ForInterface(DataBroker mountpoint, InterfaceKey ifaceKey) {
+ private L2Builder readL2ForInterface(InstanceIdentifier<Node> vppIid, InterfaceKey ifaceKey) {
InstanceIdentifier<L2> l2Iid = VppIidFactory.getL2ForInterfaceIid(ifaceKey);
- final ReadOnlyTransaction rwTxRead = mountpoint.newReadOnlyTransaction();
+ final ReadOnlyTransaction rwTxRead = VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey().newReadOnlyTransaction();
Optional<L2> optL2 = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, l2Iid, rwTxRead);
rwTxRead.close();
return (optL2.isPresent()) ? new L2Builder(optL2.get()) : new L2Builder();
@Nonnull AddressEndpointWithLocation addrEpWithLoc) {
// TODO update ACLs for peers
ExternalLocationCase epLoc = resolveAndValidateLocation(addrEpWithLoc);
- InstanceIdentifier<?> vppNodeIid = epLoc.getExternalNodeMountPoint();
+ InstanceIdentifier<Node> vppNodeIid = (InstanceIdentifier<Node>) epLoc.getExternalNodeMountPoint();
String interfacePath = epLoc.getExternalNodeConnector();
Optional<InstanceIdentifier<Interface>> optInterfaceIid =
new Exception("Cannot resolve interface instance-identifier for interface path" + interfacePath));
}
InstanceIdentifier<Interface> interfaceIid = optInterfaceIid.get();
-
- Optional<DataBroker> potentialVppDataProvider = mountDataProvider.getDataBrokerForMountPoint(vppNodeIid);
+ Optional<DataBroker> potentialVppDataProvider = mountDataProvider.resolveDataBrokerForMountPoint(vppNodeIid);
if (!potentialVppDataProvider.isPresent()) {
return Futures.immediateFailedFuture(new Exception("Cannot get data broker for mount point " + vppNodeIid));
}
- final DataBroker mountpoint = potentialVppDataProvider.get();
- final Optional<Interface> optInterface = GbpNetconfTransaction.read(mountpoint,
+ final Optional<Interface> optInterface = GbpNetconfTransaction.read(vppNodeIid,
LogicalDatastoreType.CONFIGURATION, interfaceIid, GbpNetconfTransaction.RETRY_COUNT);
if (!optInterface.isPresent()) {
// interface does not exist so we consider job done
interfaceIid.builder().augmentation(VppInterfaceAugmentation.class).child(L2.class).build();
LOG.debug("Deleting bridge domain from interface {}", interfacePath);
final boolean transactionState =
- GbpNetconfTransaction.netconfSyncedDelete(mountpoint, l2Iid, GbpNetconfTransaction.RETRY_COUNT);
+ GbpNetconfTransaction.netconfSyncedDelete(vppNodeIid, l2Iid, GbpNetconfTransaction.RETRY_COUNT);
if (transactionState) {
- AccessListWrapper.removeAclRefFromIface(mountpoint, interfaceIid.firstKeyOf(Interface.class));
- AccessListWrapper.removeAclsForInterface(mountpoint, interfaceIid.firstKeyOf(Interface.class));
+ AccessListWrapper.removeAclRefFromIface(vppNodeIid, interfaceIid.firstKeyOf(Interface.class));
+ AccessListWrapper.removeAclsForInterface(vppNodeIid, interfaceIid.firstKeyOf(Interface.class));
return vppEndpointLocationProvider.replaceLocationForEndpoint(
new ExternalLocationCaseBuilder().setExternalNode(null)
.setExternalNodeMountPoint(vppNodeIid)
package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.lisp.AbstractLispCommand;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.LispUtil;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
+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.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Function;
+
/**
* Created by Shakib Ahmed on 4/18/17.
*/
public class LispStateCommandExecutor {
private static final Logger LOG = LoggerFactory.getLogger(LispStateCommandExecutor.class);
- public static <T extends DataObject> boolean executePutCommand(DataBroker vppDataBroker,
+ public static <T extends DataObject> boolean executePutCommand(InstanceIdentifier<Node> nodeIid,
AbstractLispCommand<T> lispStateCommand) {
lispStateCommand.setOptions(General.Operations.PUT);
- return executeCommand(vppDataBroker, lispStateCommand);
+ return executeCommand(nodeIid, lispStateCommand);
+ }
+
+ public static <T extends DataObject> boolean executePutCommand(String hostName,
+ AbstractLispCommand<T> lispStateCommand) {
+ lispStateCommand.setOptions(General.Operations.PUT);
+ return executeCommand(LispUtil.HOSTNAME_TO_IID.apply(hostName), lispStateCommand);
}
- public static <T extends DataObject> boolean executeDeleteCommand(DataBroker vppDataBroker,
- AbstractLispCommand<T> lispStateCommand) {
+ public static <T extends DataObject> boolean executeDeleteCommand(InstanceIdentifier<Node> nodeIid,
+ AbstractLispCommand<T> lispStateCommand) {
lispStateCommand.setOptions(General.Operations.DELETE);
- return executeCommand(vppDataBroker, lispStateCommand);
+ return executeCommand(nodeIid, lispStateCommand);
}
- public static <T extends DataObject> boolean executeCommand(DataBroker vppDataBroker,
- AbstractLispCommand<T> lispStateCommand) {
- final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(vppDataBroker, lispStateCommand,
- GbpNetconfTransaction.RETRY_COUNT);
+ public static <T extends DataObject> boolean executeDeleteCommand(String hostName,
+ AbstractLispCommand<T> lispStateCommand) {
+ lispStateCommand.setOptions(General.Operations.DELETE);
+ return executeCommand(LispUtil.HOSTNAME_TO_IID.apply(hostName), lispStateCommand);
+ }
+ 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);
if (transactionState) {
LOG.trace("Successfully executed command: ", lispStateCommand);
} else {
package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp;
-import com.google.common.base.Preconditions;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import java.util.concurrent.ExecutionException;
+
+import javax.annotation.Nonnull;
+
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.lisp.AbstractLispCommand;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.lisp.LispCommandWrapper;
import org.opendaylight.groupbasedpolicy.renderer.vpp.config.ConfigUtil;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.feature.data.grouping.GpeFeatureData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.NativeForwardPathsTables;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518._native.forward.paths.tables._native.forward.paths.table.NativeForwardPath;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.feature.data.grouping.GpeFeatureData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.Lisp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.LocalMapping;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.Eid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nonnull;
-import java.util.concurrent.ExecutionException;
+import com.google.common.base.Preconditions;
/**
* Created by Shakib Ahmed on 3/29/17.
Eid eid = lispStateHelper.getEid(addressEp, vni);
String eidMappingName = lispStateHelper.constructEidMappingName(addressEp);
- addVniToVrfMappingIfNeeded(endpointHost.getHostDataBroker(), lispStateOfHost, vni, vrf);
+ addVniToVrfMappingIfNeeded(endpointHost, lispStateOfHost, vni, vrf);
if (lispStateHelper.getInterfaceIp(addressEp).getValue().equals(Constants.METADATA_IP)) {
return;
String eidMappingName)
throws LispConfigCommandFailedException {
if(!lispStateOfNode.eidSetContains(eid)) {
- addEidInEidTable(endpointHost.getHostDataBroker(), lispStateOfNode, eid, eidMappingName);
+ addEidInEidTable(endpointHost, lispStateOfNode, eid, eidMappingName);
}
}
private void enableLispOnHost(EndpointHost endpointHost, LispState lispState)
throws LispConfigCommandFailedException {
- AbstractLispCommand<Lisp>
- lispEnableCommand = LispCommandWrapper.enableLisp();
- if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), lispEnableCommand)) {
+ AbstractLispCommand<Lisp> lispEnableCommand = LispCommandWrapper.enableLisp();
+ if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostName(), lispEnableCommand)) {
lispState.setLispEnabled(true);
} else {
throw new LispConfigCommandFailedException("Lisp Enable Command failed execution!");
private void enableGpeForHost(EndpointHost endpointHost, LispState lispState)
throws LispConfigCommandFailedException {
- AbstractLispCommand<GpeFeatureData>
- gpeEnableCommand = LispCommandWrapper.enableGpe();
- if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), gpeEnableCommand)) {
+ AbstractLispCommand<GpeFeatureData> gpeEnableCommand = LispCommandWrapper.enableGpe();
+ if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostName(), gpeEnableCommand)) {
lispState.setGpeEnabled(true);
} else {
throw new LispConfigCommandFailedException("GPE Enable Command failed execution!");
try {
String locatorSetName = lispStateHelper.constructLocatorSetName(lispState.getLocatorCount());
String lispDataInterfaceName = lispStateHelper
- .getLispDataRlocInterfaceName(endpointHost.getHostName(), endpointHost.getHostDataBroker()).get();
+ .getLispDataRlocInterfaceName(endpointHost.getHostName()).get();
AbstractLispCommand<LocatorSet> addLocatorSetCommand = LispCommandWrapper.addLocatorSet(locatorSetName,
lispDataInterfaceName, DEFAULT_PRIORITY, DEFAULT_WEIGHT);
- if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), addLocatorSetCommand)) {
+ if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostName(), addLocatorSetCommand)) {
lispState.setLocIntfToLocSetNameMapping(lispDataInterfaceName, locatorSetName);
} else {
throw new LispConfigCommandFailedException("Lisp add locator set failed for host "
private void addExtraItrRlocLocatorSetIfNeeded(EndpointHost endpointHost, String lispDataInterfaceName)
throws LispNotFoundException, LispConfigCommandFailedException {
- String lispCpRlocInterfaceName = lispStateHelper.getLispCpRlocInterfaceName(endpointHost.getHostDataBroker());
+ String lispCpRlocInterfaceName = lispStateHelper.getLispCpRlocInterfaceName(endpointHost);
if (lispCpRlocInterfaceName == null
|| lispCpRlocInterfaceName.isEmpty()
|| lispCpRlocInterfaceName.equals(lispDataInterfaceName)) {
String locatorSetName = lispStateHelper.constructLocatorSetNameForItrRloc();
AbstractLispCommand<LocatorSet> addLocatorSetCommand = LispCommandWrapper.addLocatorSet(locatorSetName,
lispCpInterfaceName, DEFAULT_PRIORITY, DEFAULT_WEIGHT);
- if (!LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), addLocatorSetCommand)) {
+ if (!LispStateCommandExecutor.executePutCommand(endpointHost.getHostName(), addLocatorSetCommand)) {
throw new LispConfigCommandFailedException("Lisp add locator set failed for host "
+ endpointHost.getHostName() + " and locator interface " + lispCpInterfaceName);
}
AbstractLispCommand<ItrRemoteLocatorSet> addItrRlocCommand = LispCommandWrapper.addItrRloc(locatorSetName);
- if (!LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), addItrRlocCommand)) {
+ if (!LispStateCommandExecutor.executePutCommand(endpointHost.getHostName(), addItrRlocCommand)) {
throw new LispConfigCommandFailedException("Lisp add Itr Rloc command failed for host "
+ endpointHost.getHostName() + " and locator set " + locatorSetName);
}
AbstractLispCommand<MapResolver> addMapResolverCommand = LispCommandWrapper.
addMapResolver(mapResolverIpAddress);
- if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), addMapResolverCommand)) {
+ if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostName(), addMapResolverCommand)) {
lispState.addInMapResolverSet(mapResolverIpAddress);
} else {
throw new LispConfigCommandFailedException("Lisp add map resolver for host " + endpointHost.getHostName()
throws LispConfigCommandFailedException {
AbstractLispCommand<MapRegister> enableMapRegisterCommand = LispCommandWrapper.enableMapRegister();
- if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), enableMapRegisterCommand)) {
+ if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostName(), enableMapRegisterCommand)) {
} else {
throw new LispConfigCommandFailedException("Lisp enable mapregistration for host "
+ endpointHost.getHostName() + " failed!");
Preconditions.checkNotNull(mapServerIpAddress, "Mapserver ip not properly configured!");
AbstractLispCommand<MapServer> addMapServerCommand = LispCommandWrapper.addMapServer(mapServerIpAddress);
- if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), addMapServerCommand)) {
+ if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostName(), addMapServerCommand)) {
lispState.addInMapServerSet(mapServerIpAddress);
} else {
throw new LispConfigCommandFailedException("Lisp add map server for host " + endpointHost.getHostName()
}
}
- private void addVniToVrfMappingIfNeeded(DataBroker vppDataBroker,
+ private void addVniToVrfMappingIfNeeded(EndpointHost endpointHost,
LispState lispState,
long vni, long vrf) throws LispConfigCommandFailedException {
if (!lispState.isVniConfigured(vni)) {
AbstractLispCommand<VniTable> addVniToVrfMapping = LispCommandWrapper.mapVniToVrf(vni, vrf);
addVniToVrfMapping.setOptions(General.Operations.PUT);
- if (LispStateCommandExecutor.executePutCommand(vppDataBroker, addVniToVrfMapping)) {
+ if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostName(), addVniToVrfMapping)) {
lispState.addInVniSet(vni);
} else {
throw new LispConfigCommandFailedException("Lisp add vrf " + vrf +" for vni " +vni
}
}
- private void addNativeForwardPath(EndpointHost endpointHost, long vrf, IpAddress nativeForwardIp)
- throws LispConfigCommandFailedException {
-
- AbstractLispCommand<NativeForwardPath> lispCommand =
- LispCommandWrapper.addNativeForwardEntry(vrf, nativeForwardIp);
- if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), lispCommand)) {
- LOG.debug("Added {} as native forwarding IP");
- } else {
- throw new LispConfigCommandFailedException("Lisp add Native forward failed for VNI " + vrf);
- }
- }
-
- private void addEidInEidTable(DataBroker vppDataBroker,
+ private void addEidInEidTable(EndpointHost endpointHost,
LispState lispState,
Eid eid,
String eidMappingName) throws LispConfigCommandFailedException {
eid,
lispStateHelper.getFirstLocatorSetName(lispState),
lispStateHelper.getDefaultHmacKey());
- if (LispStateCommandExecutor.executePutCommand(vppDataBroker, addLocalMappingInEidTableCommand)) {
+ if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostName(), addLocalMappingInEidTableCommand)) {
lispState.addEidInEidSet(eid);
} else {
throw new LispConfigCommandFailedException("Lisp add local mapping for eid " + eid + "failed!");
.deleteLocalMappingFromEidTable(eidMappingName, value);
if (LispStateCommandExecutor
- .executeDeleteCommand(endpointHost.getHostDataBroker(), deleteLocalMappingCommand)) {
+ .executeDeleteCommand(endpointHost.getHostName(), deleteLocalMappingCommand)) {
LOG.debug("Successfully deleted eid {} from host {}", eid, endpointHost.getHostName());
lispState.deleteEid(eid);
} else {
private void deleteLispStatesFromHost(EndpointHost endpointHost) throws LispConfigCommandFailedException {
AbstractLispCommand<LispFeatureData> deleteLispFeatureData = LispCommandWrapper.deleteLispFeatureData();
- if (LispStateCommandExecutor.executeDeleteCommand(endpointHost.getHostDataBroker(), deleteLispFeatureData)) {
+ if (LispStateCommandExecutor.executeDeleteCommand(endpointHost.getHostName(), deleteLispFeatureData)) {
hostRelatedInfoContainer.deleteLispStateOfHost(endpointHost.getHostName());
LOG.debug("Deleted all lisp data for host {}", endpointHost.getHostName());
} else {
AbstractLispCommand<NativeForwardPathsTables> deleteNativeForwardPathsTables = LispCommandWrapper
.deleteNativeForwardPathsTables();
- if (!LispStateCommandExecutor.executeDeleteCommand(endpointHost.getHostDataBroker(),
+ if (!LispStateCommandExecutor.executeDeleteCommand(endpointHost.getHostName(),
deleteNativeForwardPathsTables)) {
throw new LispConfigCommandFailedException("Delete Native Forward Paths Tables command failed!");
}
package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.flat.overlay;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
+import javax.annotation.Nonnull;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.StaticArpCommand;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.util.IpAddressUtil;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.LispUtil;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nonnull;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
/**
* Created by Shakib Ahmed on 5/2/17.
PortInterfaces portInterfacesOfHost = hostRelatedInfoContainer.getPortInterfaceStateOfHost(hostName);
if (!portInterfacesOfHost.isInterfaceConfiguredForMetadata(metadataInterfaceName)) {
- DataBroker vppDataBroker = overlayHelper.getPotentialExternalDataBroker(externalLocation).get();
- addInterfaceInVrf(new EndpointHost(vppDataBroker, hostName), metadataInterfaceName, vrf);
+ addInterfaceInVrf(hostName, metadataInterfaceName, vrf);
String physicalAddress = resolvePhysicalAddress(hostName, metadataInterfaceName);
- addStaticArp(vppDataBroker, hostName, metadataInterfaceName, physicalAddress, metadataIp);
- addStaticRoute(vppDataBroker, hostName, vrf, metadataSubnetUuid, metadataIp,
- metadataIpPrefix, metadataInterfaceName);
+ addStaticArp(hostName, metadataInterfaceName, physicalAddress, metadataIp);
+ addStaticRoute(hostName, vrf, metadataSubnetUuid, metadataIp, metadataIpPrefix,
+ metadataInterfaceName);
portInterfacesOfHost.addInterfaceInMetadataInterfaceSet(metadataInterfaceName);
}
});
Preconditions.checkArgument(interfaceNameOptional.isPresent());
- addInterfaceInVrf(endpointHost, interfaceNameOptional.get(), vrf);
+ addInterfaceInVrf(endpointHost.getHostName(), interfaceNameOptional.get(), vrf);
}
- private void addInterfaceInVrf(EndpointHost endpointHost, String interfaceName, long vrf) {
- if (hostRelatedInfoContainer.getPortInterfaceStateOfHost(endpointHost.getHostName())
+ private void addInterfaceInVrf(String hostName, String interfaceName, long vrf) {
+ if (hostRelatedInfoContainer.getPortInterfaceStateOfHost(hostName)
.isVrfConfiguredForInterface(interfaceName)) {
return;
}
- if (!putVrfInInterface(endpointHost.getHostDataBroker(), interfaceName, vrf)) {
+ if (!putVrfInInterface(hostName, interfaceName, vrf)) {
LOG.warn("Failed to put interface {} to vrf {}", interfaceName, vrf);
} else {
hostRelatedInfoContainer
- .getPortInterfaceStateOfHost(endpointHost.getHostName())
+ .getPortInterfaceStateOfHost(hostName)
.initializeRoutingContextForInterface(interfaceName, vrf);
LOG.debug("Added interface {} to vrf {}", interfaceName, vrf);
}
}
- private boolean putVrfInInterface(DataBroker vppDataBroker,
+ private boolean putVrfInInterface(String hostName,
String interfaceName,
Long vrf) {
InstanceIdentifier<Routing> iid = VppIidFactory.getRoutingIid(new InterfaceKey(interfaceName));
RoutingBuilder builder = new RoutingBuilder();
builder.setIpv4VrfId(vrf);
- return GbpNetconfTransaction.netconfSyncedWrite(vppDataBroker, iid, builder.build(), GbpNetconfTransaction.RETRY_COUNT);
+ return GbpNetconfTransaction.netconfSyncedWrite(LispUtil.HOSTNAME_TO_IID.apply(hostName), iid,
+ builder.build(), GbpNetconfTransaction.RETRY_COUNT);
}
private void addStaticArp(AddressEndpointWithLocation addressEp) {
- DataBroker vppDataBroker = overlayHelper.getPotentialExternalDataBroker(addressEp).get();
String hostName = overlayHelper.getHostName(addressEp).get();
String physicalAddress = overlayHelper.getPhysicalAddress(addressEp);
Optional<String> interfaceNameOptional = overlayHelper.getInterfaceName(addressEp);
String interfaceName = interfaceNameOptional.get();
- addStaticArp(vppDataBroker, hostName, interfaceName, physicalAddress, overlayHelper.getInterfaceIp(addressEp));
+ addStaticArp(hostName, interfaceName, physicalAddress, overlayHelper.getInterfaceIp(addressEp));
}
- private void addStaticArp(DataBroker vppDataBroker,
- String hostName,
+ private void addStaticArp(String hostName,
String interfaceName,
String physicalAddress,
Ipv4Address ipv4Address) {
Ipv4AddressNoZone ip = new Ipv4AddressNoZone(ipv4Address);
InterfaceKey interfaceKey = new InterfaceKey(interfaceName);
- if (!putStaticArp(vppDataBroker,
+ if (!putStaticArp(hostName,
interfaceKey,
new PhysAddress(physicalAddress),
ip)) {
}
}
- private boolean putStaticArp(DataBroker vppDataBroker,
+ private boolean putStaticArp(String hostName,
InterfaceKey interfaceKey,
PhysAddress physAddress,
Ipv4AddressNoZone ip) {
staticArpCommandBuilder.setIp(ip);
staticArpCommandBuilder.setLinkLayerAddress(physAddress);
- return GbpNetconfTransaction.netconfSyncedWrite(vppDataBroker,
+ return GbpNetconfTransaction.netconfSyncedWrite(LispUtil.HOSTNAME_TO_IID.apply(hostName),
staticArpCommandBuilder.build(), GbpNetconfTransaction.RETRY_COUNT);
}
private void addStaticRoute(AddressEndpointWithLocation addressEp) {
- DataBroker vppDataBroker = overlayHelper.getPotentialExternalDataBroker(addressEp).get();
String hostName = overlayHelper.getHostName(addressEp).get();
-
long vni = getVni(addressEp.getTenant().getValue());
long vrf = vni;
Ipv4Prefix ipv4Prefix = overlayHelper.getInterfaceIpAsPrefix(addressEp);
- addStaticRoute(vppDataBroker, hostName, vrf, portSubnetUuid, ipWithoutPrefix, ipv4Prefix, outgoingInterfaceName);
+ addStaticRoute(hostName, vrf, portSubnetUuid, ipWithoutPrefix, ipv4Prefix, outgoingInterfaceName);
}
- private void addStaticRoute(DataBroker vppDataBroker, String hostName, long vrfId, String hostIpSubnetUuid,
+ private void addStaticRoute(String hostName, long vrfId, String hostIpSubnetUuid,
Ipv4Address ipWithoutPrefix, Ipv4Prefix ipv4Prefix, String outgoingInterfaceName) {
VrfHolder vrfHolderOfHost = hostRelatedInfoContainer.getVrfStateOfHost(hostName);
if (!vrfHolderOfHost.hasVrf(vrfId)) {
- if (!staticRoutingHelper.addRoutingProtocolForVrf(vppDataBroker, vrfId, vrfHolderOfHost)) {
- addStaticRouteToPublicInterface(vppDataBroker, hostName, vrfId);
+ if (!staticRoutingHelper.addRoutingProtocolForVrf(LispUtil.HOSTNAME_TO_IID.apply(hostName), vrfId,
+ vrfHolderOfHost)) {
+ addStaticRouteToPublicInterface(hostName, vrfId);
LOG.warn("Failed to add Routing protocol for host {} and vrf {}!", hostName, vrfId);
}
}
return;
}
- if (!staticRoutingHelper.addSingleStaticRouteInRoutingProtocol(vppDataBroker, hostName, vrfId, hostIpSubnetUuid,
+ if (!staticRoutingHelper.addSingleStaticRouteInRoutingProtocol(hostName, vrfId, hostIpSubnetUuid,
ipWithoutPrefix, ipv4Prefix, outgoingInterfaceName)) {
LOG.warn("Failed to add routing ({} via {}) in vrf {} in compute host {}!",
ipv4Prefix, outgoingInterfaceName, vrfId, hostName);
}
}
- private void addStaticRouteToPublicInterface(DataBroker vppDataBroker, String hostName, long vrfId) {
+ private void addStaticRouteToPublicInterface(String hostName, long vrfId) {
Ipv4Address physicalInterfaceIp = hostRelatedInfoContainer
.getPhysicalInterfaceState(hostName)
.getIp(PhysicalInterfaces.PhysicalInterfaceType.PUBLIC).getIpv4Address();
.getPhysicalInterfaceState(hostName)
.getName(PhysicalInterfaces.PhysicalInterfaceType.PUBLIC);
if (physicalInterfaceName != null && !physicalInterfaceName.isEmpty()) {
- if (!staticRoutingHelper.addSingleStaticRouteInRoutingProtocol(vppDataBroker,
- hostName, vrfId, Constants.PUBLIC_SUBNET_UUID, physicalInterfaceIp,
+ if (!staticRoutingHelper.addSingleStaticRouteInRoutingProtocol(hostName, vrfId,
+ Constants.PUBLIC_SUBNET_UUID, physicalInterfaceIp,
IpAddressUtil.toIpV4Prefix(physicalInterfaceIp), physicalInterfaceName)) {
LOG.warn("Failed to add route for physical interface in vrf {} compute host {}", vrfId, hostName);
} else {
}
private void deleteStaticRoute(AddressEndpointWithLocation addressEp) {
- DataBroker vppDataBroker = overlayHelper.getPotentialExternalDataBroker(addressEp).get();
String hostName = overlayHelper.getHostName(addressEp).get();
String interfaceName = overlayHelper.getInterfaceName(addressEp).get();
long targetRouteId = portRouteState.getRouteIdOfIp(ipWithoutPrefix);
- if (!staticRoutingHelper.deleteSingleStaticRouteFromRoutingProtocol(vppDataBroker,
- hostName,
+ if (!staticRoutingHelper.deleteSingleStaticRouteFromRoutingProtocol(hostName,
vrfId,
interfaceName,
targetRouteId)) {
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev161214.RoutingProtocolVppAttrBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev161214.VniReference;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.vpp.routing.rev161214.routing.routing.instance.routing.protocols.routing.protocol.VppProtocolAttributesBuilder;
+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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private HostRelatedInfoContainer hostRelatedInfoContainer = HostRelatedInfoContainer.getInstance();
- public synchronized boolean addRoutingProtocolForVrf(DataBroker vppDataBroker,
+ public synchronized boolean addRoutingProtocolForVrf(InstanceIdentifier<Node> nodeIid,
long vrfId,
VrfHolder vrfHolderOfHost) {
String routingProtocolName = getRoutingProtocolName(vrfId);
InstanceIdentifier<RoutingProtocol> iid = VppIidFactory
.getRoutingInstanceIid(builder.getKey());
- if (GbpNetconfTransaction.netconfSyncedWrite(vppDataBroker,
- iid, builder.build(), GbpNetconfTransaction.RETRY_COUNT)) {
+ if (GbpNetconfTransaction.netconfSyncedWrite(nodeIid, iid, builder.build(),
+ GbpNetconfTransaction.RETRY_COUNT)) {
vrfHolderOfHost.initializeVrfState(vrfId, routingProtocolName);
return true;
}
return false;
}
- public synchronized boolean addSingleStaticRouteInRoutingProtocol(DataBroker vppDataBroker,
- String hostName,
+ public synchronized boolean addSingleStaticRouteInRoutingProtocol(String hostName,
long portVrfId,
String portSubnetUuid,
Ipv4Address nextHopAddress,
.augmentation(StaticRoutes1.class)
.child(Ipv4.class);
- if (GbpNetconfTransaction
- .netconfSyncedMerge(vppDataBroker, iid, ipv4Route,
- GbpNetconfTransaction.RETRY_COUNT)) {
+ if (GbpNetconfTransaction.netconfSyncedMerge(VppIidFactory.getNetconfNodeIid(new NodeId(hostName)), iid,
+ ipv4Route, GbpNetconfTransaction.RETRY_COUNT)) {
hostVrfStateForPortVrf.addNewPortIpInVrf(portSubnetUuid, nextHopAddress);
- hostPortInterfaces.addRouteToPortInterface(outgoingInterface, portSubnetUuid,
- nextHopAddress, routeId);
+ hostPortInterfaces.addRouteToPortInterface(outgoingInterface, portSubnetUuid, nextHopAddress, routeId);
return true;
}
return false;
}
- public synchronized boolean deleteSingleStaticRouteFromRoutingProtocol(DataBroker vppDataBroker,
- String hostName,
+ public synchronized boolean deleteSingleStaticRouteFromRoutingProtocol(String hostName,
long vrfId,
String outgoingInterfaceName,
Long routeId) {
.child(Ipv4.class)
.child(Route.class, new RouteKey(routeId));
- if (!GbpNetconfTransaction.netconfSyncedDelete(vppDataBroker, iid, GbpNetconfTransaction.RETRY_COUNT)) {
+ if (!GbpNetconfTransaction.netconfSyncedDelete(VppIidFactory.getNetconfNodeIid(new NodeId(hostName)), iid,
+ GbpNetconfTransaction.RETRY_COUNT)) {
LOG.warn("Route delete failed for interface {} from {}", outgoingInterfaceName, hostName);
return false;
}
for (Ipv4Address ip : ipThroughInterface) {
long routeId = portRouteState.getRouteIdOfIp(ip);
String subnetUuidOfIp = portRouteState.getSubnetUuidOfIp(ip);
- boolean ok = deleteSingleStaticRouteFromRoutingProtocol(vppDataBroker, hostName, vrfId,
+ boolean ok = deleteSingleStaticRouteFromRoutingProtocol(hostName, vrfId,
outgoingInterfaceName, routeId);
if (ok) {
package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.loopback;
-import com.google.common.base.Preconditions;
+import javax.annotation.Nonnull;
+
import org.apache.commons.lang3.tuple.Pair;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.LoopbackCommand;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.LoopbackCommandWrapper;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.ProxyRangeCommand;
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.lisp.address.types.rev151105.Ipv4PrefixAfi;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.ExternalLocationCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.GbpSubnet;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.gpe.rev170518.gpe.entry.table.grouping.gpe.entry.table.GpeEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unnumbered.interfaces.rev170510.InterfaceUnnumberedAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unnumbered.interfaces.rev170510.InterfaceUnnumberedAugmentationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unnumbered.interfaces.rev170510.unnumbered.config.attributes.UnnumberedBuilder;
+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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nonnull;
+import com.google.common.base.Preconditions;
/**
* Created by Shakib Ahmed on 4/26/17.
LoopbackCommand bviLoopbackCommand = LoopbackCommandWrapper
.bviLoopbackPutCommand(gwInterfaceName, vni, gbpSubnetInfo.getGatewayIp(), gbpSubnetInfo.getCidr(),
bridgeDomainName);
- createLoopbackInterface(endpointHost.getHostDataBroker(), endpointHost.getHostName(),
- subnetState, bviLoopbackCommand);
+ createLoopbackInterface(endpointHost.getHostName(), subnetState, bviLoopbackCommand);
} catch (LispConfigCommandFailedException e) {
LOG.warn("LISP couldn't be configured: {}", e.getMessage());
}
if (loopbackManagerHelper.isMetadataPort(addressEp)) {
return;
}
-
- DataBroker vppDataBroker = loopbackManagerHelper.getPotentialExternalDataBroker(addressEp).get();
String hostName = loopbackManagerHelper.getHostName(addressEp).get();
long vni = getVni(addressEp.getTenant().getValue());
long vrfId = vni;
LoopbackCommand simpleLoopbackCommand = LoopbackCommandWrapper
.simpleLoopbackPutCommand(interfaceName, vrfId, gbpSubnetInfo.getGatewayIp(),
gbpSubnetInfo.getCidr());
- createLoopbackInterface(vppDataBroker, hostName, stateOfSubnetUuid, simpleLoopbackCommand);
- addProxyArpRange(vppDataBroker, hostName, vrfId, gbpSubnetInfo);
- addGpeEntry(vppDataBroker, gbpSubnetInfo, vni);
+ createLoopbackInterface(hostName, stateOfSubnetUuid, simpleLoopbackCommand);
+ addProxyArpRange(hostName, vrfId, gbpSubnetInfo);
+ addGpeEntry(VppIidFactory.getNetconfNodeIid(new NodeId(hostName)), gbpSubnetInfo, vni);
}
String gwInterfaceName = stateOfSubnetUuid.getGwInterfaceName();
}
}
- private void createLoopbackInterface(DataBroker vppDataBroker, String hostName,
+ private void createLoopbackInterface(String hostName,
SubnetState subnetState,
LoopbackCommand loopbackCommand) throws LispConfigCommandFailedException {
- if (GbpNetconfTransaction.netconfSyncedWrite(vppDataBroker,
- loopbackCommand,
- GbpNetconfTransaction.RETRY_COUNT)) {
+ if (GbpNetconfTransaction.netconfSyncedWrite(VppIidFactory.getNetconfNodeIid(new NodeId(hostName)),
+ loopbackCommand, GbpNetconfTransaction.RETRY_COUNT)) {
subnetState.setGwInterfaceName(loopbackCommand.getName());
} else {
throw new LispConfigCommandFailedException("BVI could not be created for "
if (loopbackManagerHelper.isMetadataPort(addressEp)) {
return;
}
-
- DataBroker vppDataBroker = loopbackManagerHelper.getPotentialExternalDataBroker(addressEp).get();
String hostName = loopbackManagerHelper.getHostName(addressEp).get();
String portSubnetUuid = loopbackManagerHelper.getSubnet(addressEp);
long vrfId = getVni(addressEp.getTenant().getValue());
"Invalid port!");
long vni = getVni(addressEp.getTenant().getValue());
try {
- deleteSpecificLoopback(vppDataBroker, gwInterfaceName);
- deleteProxyArpRange(vppDataBroker, hostName, vni, gbpSubnetInfo);
- deleteGpeEntry(vppDataBroker, Constants.GPE_ENTRY_PREFIX + gbpSubnetInfo.getId() + "_1");
- deleteGpeEntry(vppDataBroker, Constants.GPE_ENTRY_PREFIX + gbpSubnetInfo.getId() + "_2");
+ InstanceIdentifier<Node> iid = VppIidFactory.getNetconfNodeIid(new NodeId(hostName));
+ deleteSpecificLoopback(iid, gwInterfaceName);
+ deleteProxyArpRange(hostName, vni, gbpSubnetInfo);
+ deleteGpeEntry(iid, Constants.GPE_ENTRY_PREFIX + gbpSubnetInfo.getId() + "_1");
+ deleteGpeEntry(iid, Constants.GPE_ENTRY_PREFIX + gbpSubnetInfo.getId() + "_2");
hostRelatedInfoContainer.getVrfStateOfHost(hostName)
.getVrfState(vrfId)
.getSubnetHolder()
}
}
- private void deleteSpecificLoopback(DataBroker vppDataBroker, String interfaceName) throws LispConfigCommandFailedException {
- if (!GbpNetconfTransaction.netconfSyncedDelete(vppDataBroker,
+ private void deleteSpecificLoopback(InstanceIdentifier<Node> nodeIid, String interfaceName) throws LispConfigCommandFailedException {
+ if (!GbpNetconfTransaction.netconfSyncedDelete(nodeIid,
VppIidFactory.getInterfaceIID(new InterfaceKey(interfaceName)), GbpNetconfTransaction.RETRY_COUNT)) {
throw new LispConfigCommandFailedException("Failed to delete Loopback interface!");
} else {
}
}
- private void addProxyArpRange(DataBroker vppDataBroker,
- String hostName,
+ private void addProxyArpRange(String hostName,
long vrf,
GbpSubnet gbpSubnetInfo) throws LispConfigCommandFailedException {
Ipv4Prefix subnetPrefix = gbpSubnetInfo.getCidr().getIpv4Prefix();
Pair<Ipv4Address, Ipv4Address> startAndEndAddress = IpAddressUtil.getStartAndEndIp(subnetPrefix);
- if (!putArpRangesCommand(vppDataBroker,
+ if (!putArpRangesCommand(VppIidFactory.getNetconfNodeIid(new NodeId(hostName)),
vrf,
startAndEndAddress.getLeft(),
startAndEndAddress.getRight())) {
}
}
- private void deleteProxyArpRange(DataBroker vppDataBroker,
- String hostName,
+ private void deleteProxyArpRange(String hostName,
long vrf,
GbpSubnet gbpSubnetInfo) throws LispConfigCommandFailedException {
Ipv4Prefix subnetPrefix = gbpSubnetInfo.getCidr().getIpv4Prefix();
Pair<Ipv4Address, Ipv4Address> startAndEndAddress = IpAddressUtil.getStartAndEndIp(subnetPrefix);
- if (!deleteArpRangesCommand(vppDataBroker,
+ if (!deleteArpRangesCommand(VppIidFactory.getNetconfNodeIid(new NodeId(hostName)),
vrf,
startAndEndAddress.getLeft(),
startAndEndAddress.getRight())) {
}
}
- private boolean putArpRangesCommand(DataBroker vppDataBroker, long vrf, Ipv4Address start, Ipv4Address end) {
+ private boolean putArpRangesCommand(InstanceIdentifier<Node> iid, long vrf, Ipv4Address start, Ipv4Address end) {
ProxyRangeCommand.ProxyRangeCommandBuilder builder = new ProxyRangeCommand.ProxyRangeCommandBuilder();
builder.setOperation(General.Operations.PUT);
builder.setVrf(vrf);
builder.setStartAddress(start);
builder.setEndAddress(end);
-
- return GbpNetconfTransaction.netconfSyncedWrite(vppDataBroker,
- builder.build(),
- GbpNetconfTransaction.RETRY_COUNT);
+ return GbpNetconfTransaction.netconfSyncedWrite(iid, builder.build(), GbpNetconfTransaction.RETRY_COUNT);
}
- private boolean deleteArpRangesCommand(DataBroker vppDataBroker,
+ private boolean deleteArpRangesCommand(InstanceIdentifier<Node> iid,
long vrf,
Ipv4Address start,
Ipv4Address end) {
builder.setVrf(vrf);
builder.setStartAddress(start);
builder.setEndAddress(end);
-
- return GbpNetconfTransaction.netconfSyncedDelete(vppDataBroker,
- builder.build(),
- GbpNetconfTransaction.RETRY_COUNT);
+ return GbpNetconfTransaction.netconfSyncedDelete(iid, builder.build(), GbpNetconfTransaction.RETRY_COUNT);
}
private void addUnnumberedInterface(AddressEndpointWithLocation addressEp, String loopbackName) throws LispConfigCommandFailedException {
- DataBroker vppDataBroker = loopbackManagerHelper.getPotentialExternalDataBroker(addressEp).get();
+ ExternalLocationCase loc = ConfigManagerHelper.resolveAndValidateLocation(addressEp);
+ InstanceIdentifier<Node> nodeIid = (InstanceIdentifier<Node>) loc.getExternalNodeMountPoint();
String neutronInterfaceName = loopbackManagerHelper.getInterfaceName(addressEp).get();
-
- if (putUnnumberedInterface(vppDataBroker, neutronInterfaceName, loopbackName)) {
+ if (putUnnumberedInterface(nodeIid, neutronInterfaceName, loopbackName)) {
LOG.debug("Added Interface {} as unnumberd for {}", loopbackName, neutronInterfaceName);
} else {
throw new LispConfigCommandFailedException("Unnumbered configuration failed for " +
}
}
- private boolean putUnnumberedInterface(DataBroker vppDataBroker, String interfaceFor, String interfaceWith) {
+ private boolean putUnnumberedInterface(InstanceIdentifier<Node> iid, String interfaceFor, String interfaceWith) {
UnnumberedBuilder unnumberedBuilder = new UnnumberedBuilder();
unnumberedBuilder.setUse(interfaceWith);
InstanceIdentifier<Interface> interfaceIid = VppIidFactory.getInterfaceIID(new InterfaceKey(interfaceFor));
augBuilder.setUnnumbered(unnumberedBuilder.build());
InterfaceBuilder interfaceBuilder = new InterfaceBuilder().setKey(new InterfaceKey(interfaceFor));
interfaceBuilder.addAugmentation(InterfaceUnnumberedAugmentation.class, augBuilder.build());
- return GbpNetconfTransaction.netconfSyncedMerge(vppDataBroker,
- interfaceIid,
- interfaceBuilder.build(),
+ return GbpNetconfTransaction.netconfSyncedMerge(iid, interfaceIid, interfaceBuilder.build(),
GbpNetconfTransaction.RETRY_COUNT);
}
- private void addGpeEntry(DataBroker vppDataBroker, GbpSubnet gbpSubnetInfo, long vni) {
+ private void addGpeEntry(InstanceIdentifier<Node> iid, GbpSubnet gbpSubnetInfo, long vni) {
try {
Pair<Ipv4Prefix, Ipv4Prefix> delegatingSubnets = IpAddressUtil
.getSmallerSubnet(gbpSubnetInfo.getCidr().getIpv4Prefix());
RemoteEid firstREid = LispUtil.toRemoteEid(LispUtil.toLispIpv4Prefix(delegatingSubnets.getLeft()),
vni,
Ipv4PrefixAfi.class);
- putGpeEntry(vppDataBroker, Constants.GPE_ENTRY_PREFIX + gbpSubnetInfo.getId() + "_1", firstREid, vni, vni);
+ putGpeEntry(iid, Constants.GPE_ENTRY_PREFIX + gbpSubnetInfo.getId() + "_1", firstREid, vni, vni);
if (delegatingSubnets.getLeft().equals(delegatingSubnets.getRight())) {
return;
vni,
Ipv4PrefixAfi.class);
- putGpeEntry(vppDataBroker, Constants.GPE_ENTRY_PREFIX + gbpSubnetInfo.getId() + "_2", secondREid, vni, vni);
+ putGpeEntry(iid, Constants.GPE_ENTRY_PREFIX + gbpSubnetInfo.getId() + "_2", secondREid, vni, vni);
} catch (LispHelperArgumentException e) {
e.printStackTrace();
}
}
- private boolean putGpeEntry(DataBroker vppDataBroker, String id, RemoteEid rEid, long vni, long vrf) {
+ private boolean putGpeEntry(InstanceIdentifier<Node> iid, String id, RemoteEid rEid, long vni, long vrf) {
AbstractLispCommand<GpeEntry> gpeEntryCommand = LispCommandWrapper
.addGpeSendMapregisterAction(id, rEid, vni, vrf);
- return LispStateCommandExecutor.executePutCommand(vppDataBroker, gpeEntryCommand);
+ return LispStateCommandExecutor.executePutCommand(iid, gpeEntryCommand);
}
- private boolean deleteGpeEntry(DataBroker vppDataBroker, String id) {
+ private boolean deleteGpeEntry(InstanceIdentifier<Node> iid, String id) {
AbstractLispCommand<GpeEntry> gpeEntryDeletionCommand = LispCommandWrapper
.deleteGpeEntry(id);
- return LispStateCommandExecutor.executeDeleteCommand(vppDataBroker, gpeEntryDeletionCommand);
+ return LispStateCommandExecutor.executeDeleteCommand(iid, gpeEntryDeletionCommand);
}
private long getVni(String tenantUuid) {
private GbpSubnet getSubnetInfo(String subnetUuid) {
return subnetUuidToGbpSubnetMapper.getSubnetInfo(subnetUuid);
}
-}
+}
\ No newline at end of file
package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.util;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.Nonnull;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.groupbasedpolicy.renderer.vpp.config.ConfigUtil;
import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.VppPathMapper;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.LispStateManager;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.exception.LispNotFoundException;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.EndpointHost;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.HostRelatedInfoContainer;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.LispState;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.LispStateManager;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.exception.LispNotFoundException;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.PhysicalInterfaces;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.InterfaceUtil;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.LispUtil;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.EthernetCsmacd;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
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.inet.types.rev130715.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.ExternalLocationCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.child.endpoints.ChildEndpoint;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.relative.locations.ExternalLocation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.IpPrefixType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.MacAddressType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.parent.child.endpoints.ParentEndpointChoice;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.parent.child.endpoints.parent.endpoint.choice.ParentEndpointCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.parent.child.endpoints.parent.endpoint.choice.parent.endpoint._case.ParentEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.IpPrefixType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.L3Context;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.MacAddressType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.HmacKeyType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nonnull;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
/**
public Optional<DataBroker> getPotentialExternalDataBroker(AddressEndpointWithLocation addressEpWithLoc) {
ExternalLocationCase externalLocationCase = resolveAndValidateLocation(addressEpWithLoc);
- InstanceIdentifier<?> vppNodeIid = externalLocationCase.getExternalNodeMountPoint();
+ InstanceIdentifier<Node> vppNodeIid =
+ (InstanceIdentifier<Node>) externalLocationCase.getExternalNodeMountPoint();
String interfacePath = externalLocationCase.getExternalNodeConnector();
Optional<DataBroker>
- potentialVppDataProvider = mountedDataBrokerProvider.getDataBrokerForMountPoint(vppNodeIid);
+ potentialVppDataProvider = mountedDataBrokerProvider.resolveDataBrokerForMountPoint(vppNodeIid);
Preconditions.checkArgument(potentialVppDataProvider.isPresent(),
"Cannot resolve data broker for interface path: {}", interfacePath);
}
public Optional<DataBroker> getPotentialExternalDataBroker(ExternalLocation externalLocation) {
- InstanceIdentifier<?> vppNodeIid = externalLocation.getExternalNodeMountPoint();
+ InstanceIdentifier<Node> vppNodeIid = (InstanceIdentifier<Node>) externalLocation.getExternalNodeMountPoint();
Optional<DataBroker> potentialVppDataProvider;
- potentialVppDataProvider = mountedDataBrokerProvider.getDataBrokerForMountPoint(vppNodeIid);
+ potentialVppDataProvider = mountedDataBrokerProvider.resolveDataBrokerForMountPoint(vppNodeIid);
Preconditions.checkState(potentialVppDataProvider.isPresent(), "Data Broker missing");
public Optional<DataBroker> getPotentialExternalDataBroker(VppEndpoint vppEp) {
InstanceIdentifier<Node> vppNodeIid = VppIidFactory.getNetconfNodeIid(vppEp.getVppNodeId());
Optional<DataBroker> potentialVppDataProvider =
- mountedDataBrokerProvider.getDataBrokerForMountPoint(vppNodeIid);
+ mountedDataBrokerProvider.resolveDataBrokerForMountPoint(vppNodeIid);
Preconditions.checkArgument(potentialVppDataProvider.isPresent(),
"Cannot resolve data broker for Vpp Endpoint: {}", vppEp);
public Optional<DataBroker> getPotentialExternalDataBroker(String hostId) {
InstanceIdentifier<Node> nodeIid = VppIidFactory.getNetconfNodeIid(new NodeId(hostId));
- Optional<DataBroker> potentialVppDataProvider = mountedDataBrokerProvider.getDataBrokerForMountPoint(nodeIid);
+ Optional<DataBroker> potentialVppDataProvider =
+ mountedDataBrokerProvider.resolveDataBrokerForMountPoint(nodeIid);
Preconditions.checkArgument(potentialVppDataProvider.isPresent(),
"Data Broker not found for {}", hostId);
return potentialVppDataProvider;
return Optional.fromNullable(hostId);
}
- public ExternalLocationCase resolveAndValidateLocation(AddressEndpointWithLocation addrEpWithLoc) {
+ public static ExternalLocationCase resolveAndValidateLocation(AddressEndpointWithLocation addrEpWithLoc) {
Preconditions.checkNotNull(addrEpWithLoc.getAbsoluteLocation(), "Absolute location for " +
"AddressEndpointWithLocation missing: " + addrEpWithLoc.toString() );
LocationType locationType = addrEpWithLoc.getAbsoluteLocation().getLocationType();
}
//This is almost identical to VBD's equivalent method
- public ListenableFuture<String> getLispDataRlocInterfaceName(@Nonnull String hostName,
- @Nonnull DataBroker vppDataBroker) {
+ public ListenableFuture<String> getLispDataRlocInterfaceName(@Nonnull String hostName) {
Preconditions.checkNotNull(hostName, "Hostname is null!");
- Preconditions.checkNotNull(vppDataBroker, "Vpp DataBroker is null!");
PhysicalInterfaces physicalInterfaces = HostRelatedInfoContainer.getInstance()
.getPhysicalInterfaceState(hostName);
String publicInterfaceName = physicalInterfaces == null ? "" : physicalInterfaces
.getName(PhysicalInterfaces.PhysicalInterfaceType.PUBLIC);
- final Optional<InterfacesState> opInterfaceState = GbpNetconfTransaction.read(vppDataBroker,
- LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(InterfacesState.class),
- GbpNetconfTransaction.RETRY_COUNT);
+ final Optional<InterfacesState> opInterfaceState =
+ GbpNetconfTransaction.read(LispUtil.HOSTNAME_TO_IID.apply(hostName), LogicalDatastoreType.OPERATIONAL,
+ InstanceIdentifier.create(InterfacesState.class), GbpNetconfTransaction.RETRY_COUNT);
if (!opInterfaceState.isPresent()) {
LOG.debug("There appear to be no interfaces on node {}.", hostName);
}
final Optional<Interfaces> opInterfaces =
- GbpNetconfTransaction.read(vppDataBroker, LogicalDatastoreType.CONFIGURATION,
+ GbpNetconfTransaction.read(LispUtil.HOSTNAME_TO_IID.apply(hostName), LogicalDatastoreType.CONFIGURATION,
InstanceIdentifier.create(Interfaces.class), GbpNetconfTransaction.RETRY_COUNT);
return ip != null;
}
- public String getLispCpRlocInterfaceName(@Nonnull DataBroker vppDataBroker) {
- List<Interface> operationalInterfaceList = InterfaceUtil.getOperationalInterfaces(vppDataBroker);
+ public String getLispCpRlocInterfaceName(@Nonnull EndpointHost endpointHost) {
+ List<Interface> operationalInterfaceList =
+ InterfaceUtil.getOperationalInterfaces(LispUtil.HOSTNAME_TO_IID.apply(endpointHost.getHostName()));
if (operationalInterfaceList == null) {
return null;
import org.opendaylight.groupbasedpolicy.util.IidFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererPolicy;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import com.google.common.eventbus.EventBus;
public class RendererPolicyListener extends DataTreeChangeHandler<RendererPolicy> {
- private static final Logger LOG = LoggerFactory.getLogger(RendererPolicyListener.class);
private EventBus eventBus;
public RendererPolicyListener(@Nonnull DataBroker dataProvider, @Nonnull EventBus eventBus) {
InstanceIdentifier<RendererPolicy> rootIdentifier) {
RendererPolicyConfEvent event =
new RendererPolicyConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter());
- LOG.trace("Dispatching event on write: {}", event.getClass());
eventBus.post(event);
}
InstanceIdentifier<RendererPolicy> rootIdentifier) {
RendererPolicyConfEvent event =
new RendererPolicyConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter());
- LOG.trace("Dispatching event on delete: {}", event.getClass());
eventBus.post(event);
}
InstanceIdentifier<RendererPolicy> rootIdentifier) {
RendererPolicyConfEvent event =
new RendererPolicyConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter());
- LOG.trace("Dispatching event on subtree modified: {}", event.getClass());
eventBus.post(event);
}
InstanceIdentifier<VppEndpoint> rootIdentifier) {
VppEndpointConfEvent event =
new VppEndpointConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter());
- LOG.trace("Dispatching event on write: {}", event.getClass());
+ LOG.debug("Dispatching event on write: {}", event.getClass());
eventBus.post(event);
}
InstanceIdentifier<VppEndpoint> rootIdentifier) {
VppEndpointConfEvent event =
new VppEndpointConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter());
- LOG.trace("Dispatching event on delete: {}", event.getClass());
eventBus.post(event);
}
InstanceIdentifier<VppEndpoint> rootIdentifier) {
VppEndpointConfEvent event =
new VppEndpointConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter());
- LOG.trace("Dispatching event on subtree modified: {}", event.getClass());
+ LOG.debug("Dispatching event on subtree modified: {}", event.getClass());
eventBus.post(event);
}
@Override
public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Node>> changes) {
- LOG.debug("Netconf topology node change detected, VppNodeListener processing started.");
for (DataTreeModification<Node> modification : changes) {
+ InstanceIdentifier<Node> iid = modification.getRootPath().getRootIdentifier();
+ LOG.debug("Change detected for network topology node {}.", iid.firstKeyOf(Node.class));
DataObjectModification<Node> rootNode = modification.getRootNode();
Node dataAfter = rootNode.getDataAfter();
Node dataBefore = rootNode.getDataBefore();
- NodeOperEvent event =
- new NodeOperEvent(modification.getRootPath().getRootIdentifier(), dataBefore, dataAfter);
+ NodeOperEvent event = new NodeOperEvent(iid, dataBefore, dataAfter);
eventBus.post(event);
nodeManager.syncNodes(dataAfter, dataBefore);
}
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.MountPoint;
import org.opendaylight.controller.md.sal.binding.api.MountPointService;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.HostRelatedInfoContainer;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.PhysicalInterfaces;
import org.opendaylight.groupbasedpolicy.renderer.vpp.nat.NatUtil;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppRendererProcessingException;
import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
public class VppNodeManager {
- private static final short DURATION = 3000;
private static final TopologyId TOPOLOGY_ID = new TopologyId("topology-netconf");
private static final Logger LOG = LoggerFactory.getLogger(VppNodeManager.class);
private static final String V3PO_CAPABILITY = "(urn:opendaylight:params:xml:ns:yang:v3po?revision=2017-06-07)v3po";
private final List<String> requiredCapabilities;
private final MountPointService mountService;
private final HostRelatedInfoContainer hostRelatedInfoContainer = HostRelatedInfoContainer.getInstance();
+ private final MountedDataBrokerProvider mountProvider;
public VppNodeManager(@Nonnull final DataBroker dataBroker,
@Nonnull final BindingAwareBroker.ProviderContext session, @Nullable String physicalInterfaces) {
this.dataBroker = Preconditions.checkNotNull(dataBroker);
this.mountService = Preconditions.checkNotNull(session.getSALService(MountPointService.class));
+ this.mountProvider = new MountedDataBrokerProvider(mountService, dataBroker);
requiredCapabilities = initializeRequiredCapabilities();
if (!Strings.isNullOrEmpty(physicalInterfaces) && !Objects.equals(physicalInterfaces, NO_PUBLIC_INT_SPECIFIED)) {
loadPhysicalInterfaces(physicalInterfaces);
/**
* Synchronizes nodes to DataStore based on their modification state which results in
* create/update/remove of Node.
+ * @param dataAfter data after modification
+ * @param dataBefore data Before modification
*/
public void syncNodes(final Node dataAfter, final Node dataBefore) {
if (isControllerConfigNode(dataAfter, dataBefore)) {
final String message = String.format("Node %s is not connected", nodeId);
return Futures.immediateFuture(message);
}
- final DataBroker mountpoint = getNodeMountPoint(mountPointIid);
- if (mountpoint == null) {
+ final Optional<DataBroker> mountpoint = mountProvider.resolveDataBrokerForMountPoint(mountPointIid);
+ if (mountpoint.isPresent()) {
final String message = String.format("Mountpoint not available for node %s", nodeId);
return Futures.immediateFuture(message);
}
final boolean submit = DataStoreHelper.submitToDs(wTx);
if (submit) {
final String message = String.format("Node %s is capable and ready", nodeId);
- syncPhysicalInterfacesInLocalDs(mountpoint, mountPointIid);
- NatUtil.resolveOutboundNatInterface(mountpoint, mountPointIid, node.getNodeId(), extInterfaces);
+ syncPhysicalInterfacesInLocalDs(mountpoint.get(), mountPointIid);
+ NatUtil.resolveOutboundNatInterface(mountPointIid, node.getNodeId(), extInterfaces);
return Futures.immediateFuture(message);
} else {
final String message = String.format("Failed to resolve connected node %s", nodeId);
}
}
- @Nullable
- private DataBroker getNodeMountPoint(final InstanceIdentifier<Node> mountPointIid) {
- final Future<Optional<MountPoint>> futureOptionalObject = getMountpointFromSal(mountPointIid);
- try {
- final Optional<MountPoint> optionalObject = futureOptionalObject.get();
- LOG.debug("Optional mountpoint object: {}", optionalObject);
- MountPoint mountPoint;
- if (optionalObject.isPresent()) {
- mountPoint = optionalObject.get();
- Optional<DataBroker> optionalDataBroker = mountPoint.getService(DataBroker.class);
- if (optionalDataBroker.isPresent()) {
- return optionalDataBroker.get();
- } else {
- LOG.warn("Cannot obtain data broker from mountpoint {}", mountPoint);
- }
- } else {
- LOG.warn("Cannot obtain mountpoint with IID {}", mountPointIid);
- }
- return null;
- } catch (ExecutionException | InterruptedException e) {
- LOG.warn("Unable to obtain mountpoint ... {}", e);
- return null;
- }
- }
-
private RendererNode remapNode(final InstanceIdentifier<Node> path) {
final RendererNodeBuilder rendererNodeBuilder = new RendererNodeBuilder();
rendererNodeBuilder.setKey(new RendererNodeKey(path)).setNodePath(path);
return Arrays.asList(capabilityEntries);
}
- // TODO bug 7699
- // This works as a workaround for mountpoint registration in cluster. If application is registered on different
- // node as netconf service, it obtains mountpoint registered by SlaveSalFacade (instead of MasterSalFacade). However
- // this service registers mountpoint a moment later then connectionStatus is set to "Connected". If NodeManager hits
- // state where device is connected but mountpoint is not yet available, try to get it again in a while
- private Future<Optional<MountPoint>> getMountpointFromSal(final InstanceIdentifier<Node> iid) {
- final ExecutorService executorService = Executors.newSingleThreadExecutor();
- final Callable<Optional<MountPoint>> task = () -> {
- byte attempt = 0;
- do {
- try {
- final Optional<MountPoint> optionalMountpoint = mountService.getMountPoint(iid);
- if (optionalMountpoint.isPresent()) {
- return optionalMountpoint;
- }
- LOG.warn("Mountpoint {} is not registered yet", iid);
- Thread.sleep(DURATION);
- } catch (InterruptedException e) {
- LOG.warn("Thread interrupted to ", e);
- }
- attempt++;
- } while (attempt <= 3);
- return Optional.absent();
- };
- return executorService.submit(task);
- }
-
private void syncPhysicalInterfacesInLocalDs(DataBroker mountPointDataBroker, InstanceIdentifier<Node> nodeIid) {
ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
ReadOnlyTransaction rTx = mountPointDataBroker.newReadOnlyTransaction();
import java.util.concurrent.atomic.AtomicInteger;\r
import java.util.stream.Collectors;\r
\r
+import javax.annotation.Nullable;\r
+\r
import org.apache.commons.net.util.SubnetUtils;\r
import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.ExternalIpAddressPool;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.nodes.RendererNode;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.renderers.renderer.renderer.nodes.renderer.node.PhysicalInterface;\r
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;\r
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
import com.google.common.base.Optional;\r
\r
-import javax.annotation.Nullable;\r
-\r
public class NatManager {\r
\r
private static final Logger LOG = LoggerFactory.getLogger(NatManager.class);\r
LOG.trace("Preparing to submit NAT changes {} on physical interfaces", sNatEntries.toArray(), physIfacesIid);\r
}\r
for (InstanceIdentifier<PhysicalInterface> iidPhysIface : physIfacesIid) {\r
- InstanceIdentifier<?> nodeIid = iidPhysIface.firstKeyOf(RendererNode.class).getNodePath();\r
- Optional<DataBroker> mountPointDataBroker = mountDataProvider.getDataBrokerForMountPoint(nodeIid);\r
- if (!mountPointDataBroker.isPresent()) {\r
- throw new IllegalStateException("Cannot find data broker for mount point " + nodeIid);\r
- }\r
+ InstanceIdentifier<Node> nodeIid = (InstanceIdentifier<Node>) iidPhysIface.firstKeyOf(RendererNode.class).getNodePath();\r
String phInterfaceName = iidPhysIface.firstKeyOf(PhysicalInterface.class).getInterfaceName();\r
InstanceIdentifier<Interface> interfaceIID =\r
VppIidFactory.getInterfaceIID(new InterfaceKey(phInterfaceName));\r
\r
Optional<Interface> readIface =\r
- GbpNetconfTransaction.read(mountPointDataBroker.get(), LogicalDatastoreType.CONFIGURATION, interfaceIID,\r
+ GbpNetconfTransaction.read(nodeIid, LogicalDatastoreType.CONFIGURATION, interfaceIID,\r
GbpNetconfTransaction.RETRY_COUNT);\r
\r
if (!readIface.isPresent()) {\r
if (add) {\r
NatInstance natInstance =\r
buildNatInstance(sNatEntries, NatUtil.resolveDynamicNat(policyCtx, sNatEntries));\r
- GbpNetconfTransaction.netconfSyncedWrite(mountPointDataBroker.get(),\r
+ GbpNetconfTransaction.netconfSyncedWrite(nodeIid,\r
VppIidFactory.getNatInstanceIid(id), natInstance, GbpNetconfTransaction.RETRY_COUNT);\r
} else {\r
- if (GbpNetconfTransaction.read(mountPointDataBroker.get(), LogicalDatastoreType.CONFIGURATION,\r
+ if (GbpNetconfTransaction.read(nodeIid, LogicalDatastoreType.CONFIGURATION,\r
VppIidFactory.getNatInstanceIid(id), GbpNetconfTransaction.RETRY_COUNT).isPresent()) {\r
- GbpNetconfTransaction.netconfSyncedDelete(mountPointDataBroker.get(),\r
+ GbpNetconfTransaction.netconfSyncedDelete(nodeIid,\r
VppIidFactory.getNatInstanceIid(id), GbpNetconfTransaction.RETRY_COUNT);\r
}\r
}\r
import javax.annotation.Nullable;\r
\r
import org.apache.commons.net.util.SubnetUtils;\r
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;\r
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;\r
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;\r
import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;\r
import org.opendaylight.groupbasedpolicy.util.NetUtils;\r
+import org.opendaylight.vbd.impl.transaction.VbdNetconfTransaction;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;\r
wTx.put(LogicalDatastoreType.CONFIGURATION, natIid, nat);\r
}\r
\r
- public static void setOutboundInterface(Interface iface, DataBroker dataBroker) {\r
+ public static void setOutboundInterface(Interface iface, InstanceIdentifier<Node> vppIid) {\r
InstanceIdentifier<Nat> natIid = buildNatIid(VppIidFactory.getInterfaceIID(iface.getKey()));\r
Nat nat = new NatBuilder().setOutbound(new OutboundBuilder().build()).build();\r
- GbpNetconfTransaction.netconfSyncedWrite(dataBroker, natIid, nat, GbpNetconfTransaction.RETRY_COUNT);\r
+ GbpNetconfTransaction.netconfSyncedWrite(vppIid, natIid, nat, GbpNetconfTransaction.RETRY_COUNT);\r
\r
}\r
\r
- public static void unsetOutboundInterface(Interface iface, DataBroker dataBroker) {\r
+ public static void unsetOutboundInterface(Interface iface, InstanceIdentifier<Node> vppIid) {\r
InstanceIdentifier<Nat> natIid = buildNatIid(VppIidFactory.getInterfaceIID(iface.getKey()));\r
- GbpNetconfTransaction.netconfSyncedDelete(dataBroker, natIid, GbpNetconfTransaction.RETRY_COUNT);\r
+ GbpNetconfTransaction.netconfSyncedDelete(vppIid, natIid, GbpNetconfTransaction.RETRY_COUNT);\r
}\r
\r
public static InstanceIdentifier<Nat> buildNatIid(InstanceIdentifier<Interface> ifaceIid) {\r
return extCache;\r
}\r
\r
- public static void resolveOutboundNatInterface(DataBroker mountpoint, InstanceIdentifier<Node> mountPointIid,\r
+ public static void resolveOutboundNatInterface(InstanceIdentifier<Node> mountPointIid,\r
NodeId nodeId, Map<NodeId, PhysicalInterfaceKey> extInterfaces) {\r
if (extInterfaces.containsKey(nodeId)){\r
PhysicalInterfaceKey physicalInterfaceKey = extInterfaces.get(nodeId);\r
Optional<Interfaces> readIfaces = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION,\r
- InstanceIdentifier.create(Interfaces.class), mountpoint.newReadOnlyTransaction());\r
+ InstanceIdentifier.create(Interfaces.class),\r
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(mountPointIid).getKey().newReadOnlyTransaction());\r
if(readIfaces.isPresent() ) {\r
for (Interface nodeInterface : readIfaces.get().getInterface()) {\r
if (nodeInterface.getName().equals(physicalInterfaceKey.getInterfaceName())) {\r
LOG.trace("Setting outbound NAT on interface {} on node: {}", nodeInterface.getName(), mountPointIid);\r
- NatUtil.setOutboundInterface(nodeInterface, mountpoint);\r
+ NatUtil.setOutboundInterface(nodeInterface, mountPointIid);\r
}\r
}\r
\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VxlanVni;
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
String l2FloodDomain = optL2FloodDomain.get();
try {
ifaceManager.addBridgeDomainToInterface(l2FloodDomain, rEp, aclManager.resolveAclsOnInterface(
- rEpKey, policyCtx), isBviForEndpoint(rEp)).get();
+ rEpKey, policyCtx).get(), isBviForEndpoint(rEp)).get();
LOG.debug("Interface added to bridge-domain {} for endpoint {}", l2FloodDomain, rEp);
if (ConfigUtil.getInstance().isLispOverlayEnabled()) {
List<InstanceIdentifier<PhysicalInterface>>
physIfacesIid = resolvePhysicalInterfacesForNat(fwd.getRendererNetworkDomain());
- Map<InstanceIdentifier<?>, RoutingCommand> routingCommandMap =
+ Map<InstanceIdentifier<Node>, RoutingCommand> routingCommandMap =
routingManager.createRouting(fwd, physIfacesIid, General.Operations.PUT);
routingCommandMap.forEach((node, command) -> {
List<InstanceIdentifier<PhysicalInterface>>
physIfacesIid = resolvePhysicalInterfacesForNat(fwd.getRendererNetworkDomain());
- Map<InstanceIdentifier<?>, RoutingCommand> routingCommandMap =
+ Map<InstanceIdentifier<Node>, RoutingCommand> routingCommandMap =
routingManager.createRouting(fwd, physIfacesIid, General.Operations.DELETE);
routingCommandMap.forEach((node, command) -> {
if (command != null && routingManager.submitRouting(command, node)) {
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.rule.groups.RuleGroupKey;
import com.google.common.base.Preconditions;
+import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.ImmutableTable.Builder;
import com.google.common.collect.Maps;
+import com.google.common.collect.SetMultimap;
public class PolicyContext {
private final ImmutableMap<AddressEndpointKey, AddressEndpointWithLocation> addrEpByKey;
private final ImmutableTable<TenantId, RendererForwardingContextKey, RendererForwardingContext> forwardingCtxTable;
private final ImmutableTable<TenantId, RendererNetworkDomainKey, RendererNetworkDomain> networkDomainTable;
+ private final ImmutableSetMultimap<RuleGroupKey, RendererEndpointKey> endpointsByRuleGroups;
public PolicyContext(@Nonnull RendererPolicy policy) {
this.policy = Preconditions.checkNotNull(policy);
Configuration config = optConfig.get();
this.ruleGroupByKey = resolveRuleGroups(config);
List<RendererEndpoint> rendererEps = resolveRendererEndpoints(config);
- this.policyTable = resolvePolicy(rendererEps, ruleGroupByKey);
+ SetMultimap<RuleGroupKey, RendererEndpointKey> epsByRules = HashMultimap.create();
+ this.policyTable = resolvePolicy(rendererEps, ruleGroupByKey, epsByRules);
+ this.endpointsByRuleGroups = ImmutableSetMultimap.<RuleGroupKey, RendererEndpointKey>copyOf(epsByRules);
addrEpByKey = resolveAddrEpWithLoc(config);
this.forwardingCtxTable = resolveForwardingCtxTable(config);
this.networkDomainTable = resolveNetworkDomainTable(config);
this.addrEpByKey = ImmutableMap.of();
this.forwardingCtxTable = ImmutableTable.of();
this.networkDomainTable = ImmutableTable.of();
+ this.endpointsByRuleGroups = ImmutableSetMultimap.<RuleGroupKey, RendererEndpointKey>of();
}
}
}
private static ImmutableTable<RendererEndpointKey, PeerEndpointKey, ImmutableSortedSet<RendererResolvedPolicy>> resolvePolicy(
- List<RendererEndpoint> rendererEps, Map<RuleGroupKey, ResolvedRuleGroup> ruleGroupInfoByRuleGroupKey) {
+ List<RendererEndpoint> rendererEps, Map<RuleGroupKey, ResolvedRuleGroup> ruleGroupInfoByRuleGroupKey, SetMultimap<RuleGroupKey, RendererEndpointKey> epsByRules) {
Builder<RendererEndpointKey, PeerEndpointKey, ImmutableSortedSet<RendererResolvedPolicy>> resultBuilder =
new Builder<>();
Supplier<TreeSet<RendererResolvedPolicy>> rendererPolicySupplier = () -> new TreeSet<>();
ruleGroupInfoByRuleGroupKey.get(KeyFactory.ruleGroupKey(ruleGroup.getKey()))))
.collect(Collectors.collectingAndThen(Collectors.toCollection(rendererPolicySupplier),
ImmutableSortedSet::copyOfSorted));
+ peer.getRuleGroupWithRendererEndpointParticipation()
+ .forEach(ruleGroup -> epsByRules.put(KeyFactory.ruleGroupKey(ruleGroup.getKey()), rEp.getKey()));
resultBuilder.put(rEp.getKey(), KeyFactory.peerEndpointKey(peer.getKey()),
ImmutableSortedSet.copyOfSorted(rPolicy));
});
return networkDomainTable;
}
+ public @Nonnull ImmutableSetMultimap<RuleGroupKey, RendererEndpointKey> getEndpointsByRuleGroups() {
+ return endpointsByRuleGroups;
+ }
+
@Override
public String toString() {
return "PolicyContext [policyTable=" + policyTable + ", ruleGroupByKey=" + ruleGroupByKey + ", addrEpByKey="
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.contract.subject.Rule;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.rule.groups.RuleGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.rule.groups.RuleGroupKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.resolved.policy.rev150828.has.resolved.rules.ResolvedRule;
import com.google.common.collect.ComparisonChain;
return relatedSubject;
}
+ public RuleGroupKey getRelatedRuleGroupKey() {
+ return new RuleGroupKey(contractId, relatedSubject, contractTenantId);
+ }
+
@Override
public int hashCode() {
final int prime = 31;
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.groupbasedpolicy.renderer.util.AddressEndpointUtils;
import org.opendaylight.groupbasedpolicy.renderer.vpp.config.ConfigUtil;
import org.opendaylight.groupbasedpolicy.renderer.vpp.event.NodeOperEvent;
import org.opendaylight.groupbasedpolicy.renderer.vpp.event.RendererPolicyConfEvent;
import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl.AclManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.KeyFactory;
import org.opendaylight.groupbasedpolicy.util.IidFactory;
-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.absolute.location.location.type.ExternalLocationCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.rule.group.with.renderer.endpoint.participation.RuleGroupWithRendererEndpointParticipation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererPolicy;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.RendererPolicyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.RendererForwarding;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.RendererEndpointKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.renderer.endpoint.PeerEndpoint;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.rule.groups.RuleGroupKey;
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 com.google.common.collect.Sets;
import com.google.common.collect.Sets.SetView;
import com.google.common.eventbus.Subscribe;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
public class VppRendererPolicyManager {
RendererPolicy response = responseBuilder.build();
wTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.rendererIid(VppRenderer.NAME).child(RendererPolicy.class),
response, true);
- Futures.addCallback(wTx.submit(), new FutureCallback<Void>() {
-
- @Override
- public void onSuccess(Void result) {
- LOG.info("Renderer updated renderer policy to version {}", response.getVersion());
- }
-
- @Override
- public void onFailure(Throwable t) {
- LOG.warn("Renderer failed to update renderer-policy to version {}", response.getVersion());
- }
- });
+ try {
+ wTx.submit().get();
+ } catch (Exception ex) {
+ LOG.trace("Got Exception in renderer policy update. Exception: {}", ex);
+ }
}
private void rendererPolicyUpdated(RendererPolicy rPolicyBefore, RendererPolicy rPolicyAfter) {
fwManager.createForwardingForEndpoint(rEpKey, policyCtxAfter);
}
});
- updatePolicy(policyCtxBefore, policyCtxAfter);
- }
-
- /**
- * Looks for changed rule groups in {@code policyCtxBefore} and {@code policyCtxAfter}.
- * Access lists are updated for endpoints in {@code policyCtxAfter} affected by changed rule
- * groups.
- *
- * @param policyCtxBefore policy before
- * @param policyCtxAfter policy after
- */
- private void updatePolicy(PolicyContext policyCtxBefore, PolicyContext policyCtxAfter) {
- LOG.info("Updating policy by rule groups.");
- Set<RuleGroupKey> diffRuleGroups = new HashSet<>();
- diffRuleGroups.addAll(Sets.difference(policyCtxBefore.getRuleGroupByKey().keySet(),
- policyCtxAfter.getRuleGroupByKey().keySet()));
- diffRuleGroups.addAll(Sets.difference(policyCtxAfter.getRuleGroupByKey().keySet(), policyCtxBefore.getRuleGroupByKey().keySet()));
- LOG.trace("Rule groups changed: {} ", diffRuleGroups.size());
- Set<RendererEndpointKey> updates = new HashSet<>();
- for (PolicyContext policy : new PolicyContext[] {policyCtxBefore, policyCtxAfter}) {
- if (policy.getPolicy().getConfiguration() == null
- || policy.getPolicy().getConfiguration().getRendererEndpoints() == null
- || policy.getPolicy().getConfiguration().getRendererEndpoints().getRendererEndpoint() == null) {
- continue;
- }
- policy.getPolicy()
- .getConfiguration()
- .getRendererEndpoints()
- .getRendererEndpoint()
- .stream()
- .filter(rEp -> !updates.contains(rEp.getKey()))
- .forEach(rEp -> {
- for (PeerEndpoint pEp : rEp.getPeerEndpoint()) {
- for (RuleGroupWithRendererEndpointParticipation rg : pEp
- .getRuleGroupWithRendererEndpointParticipation()) {
- if (!diffRuleGroups.contains(
- new RuleGroupKey(rg.getContractId(), rg.getSubjectName(), rg.getTenantId()))) {
- continue;
- }
- if (!policy.equals(policyCtxBefore)) {
- updates.add(rEp.getKey());
- AddressEndpointKey k1 = AddressEndpointUtils.fromPeerEpKey(pEp.getKey());
- updates.add(AddressEndpointUtils.toRendererEpKey(k1));
- }
- }
- }
- });
- }
- for (RendererEndpointKey rEpKey : updates) {
- aclManager.updateAclsForRendEp(rEpKey, policyCtxAfter);
- }
+ ImmutableSet<RuleGroupKey> rulesBefore = policyCtxAfter.getRuleGroupByKey().keySet();
+ ImmutableSet<RuleGroupKey> rulesAfter = policyCtxBefore.getRuleGroupByKey().keySet();
+ SetView<RuleGroupKey> removedRules = Sets.difference(rulesAfter, rulesBefore);
+ SetView<RuleGroupKey> createdRules = Sets.difference(rulesBefore, rulesAfter);
+ LOG.debug("Removed rules {}", removedRules);
+ LOG.debug("Created rules {}", createdRules);
+ aclManager.resolveRulesToConfigure(policyCtxBefore, removedRendEps, removedRules, false);
+ aclManager.resolveRulesToConfigure(policyCtxAfter, createdRendEps, createdRules, true);
}
private static boolean isLocationChanged(AddressEndpointWithLocation before, AddressEndpointWithLocation after) {
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.parent.child.endpoints.parent.endpoint.choice.parent.endpoint._case.ParentEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.RuleName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.SubnetAugmentRenderer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.has.subnet.Subnet;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction;
public class AccessListUtil {
private static final Logger LOG = LoggerFactory.getLogger(AccessListUtil.class);
- private static final String UNDERSCORE = "_";
+ static final String UNDERSCORE = "_";
private static final String PERMIT_EXTERNAL_INGRESS = "permit_external_ingress";
private static final String PERMIT_EXTERNAL_EGRESS = "permit_external_egress";
private static final String DENY_INGRESS_IPV4 = "deny_ingress_ipv4";
.forEach(peerEpKey -> {
ctx.getPolicyTable().get(rEpKey, peerEpKey).forEach(resolvedRules -> {
List<GbpAceBuilder> rules = new ArrayList<>();
- LOG.debug("Resolving policy for {} and peer endpoint {}", rEpKey, peerEpKey);
Direction classifDir = calculateClassifDirection(resolvedRules.getRendererEndpointParticipation(),
policyDirection);
- rules.addAll(resolveAclRulesFromPolicy(resolvedRules, classifDir,
- rEpKey.getAddress() + UNDERSCORE + peerEpKey.getAddress()));
+ rules.addAll(resolveAclRulesFromPolicy(resolvedRules, classifDir, rEpKey, peerEpKey));
updateAddressesInRules(rules, rEpKey, peerEpKey, ctx, policyDirection, true);
aclWrapper.writeRules(rules);
* @param direction EGRESS or INGRESS
* @return Direction that classifiers should match for given policy direction.
*/
- private static Direction calculateClassifDirection(EndpointPolicyParticipation participation, ACE_DIRECTION direction) {
+ static Direction calculateClassifDirection(EndpointPolicyParticipation participation, ACE_DIRECTION direction) {
if (EndpointPolicyParticipation.PROVIDER.equals(participation) && ACE_DIRECTION.INGRESS.equals(direction)) {
return Direction.Out;
}
return Direction.In;
}
- private static void updateAddressesInRules(List<GbpAceBuilder> rules, RendererEndpointKey rEpKey,
+ static void updateAddressesInRules(List<GbpAceBuilder> rules, RendererEndpointKey rEpKey,
PeerEndpointKey peerEpKey, PolicyContext ctx, ACE_DIRECTION policyDirection,
boolean resolveForLocationPeers) {
for (AddressMapper addrMapper : Arrays.asList(new SourceMapper(policyDirection),
* @param direction rules matching corresponding direction will be collected
* @return resolved ACE entries
*/
+
+ static @Nonnull String resolveAceName(@Nonnull RuleName ruleName, @Nonnull RendererEndpointKey key,
+ @Nonnull PeerEndpointKey peer) {
+ return ruleName.getValue() + "_" + key.getAddress() + "_" + peer.getAddress();
+ }
+
private static List<GbpAceBuilder> resolveAclRulesFromPolicy(RendererResolvedPolicy resolvedPolicy,
- Direction direction, String namePasphrase) {
+ Direction direction, RendererEndpointKey r, PeerEndpointKey p) {
List<GbpAceBuilder> aclRules = new ArrayList<>();
for (ResolvedRule resolvedRule : resolvedPolicy.getRuleGroup().getRules()) {
- Map<String, ParameterValue> params = resolveClassifParamsForDir(direction, resolvedRule.getClassifier());
- if (params.isEmpty()) {
- continue;
+ Optional<GbpAceBuilder> resolveAce = resolveAceClassifersAndAction(resolvedRule, direction, resolveAceName(resolvedRule.getName(), r, p));
+ if(resolveAce.isPresent()) {
+ aclRules.add(resolveAce.get());
}
- LOG.debug("Processing classifification params {} in resolved rule {}.", params,
- resolvedRule.getName() + UNDERSCORE + namePasphrase);
- org.opendaylight.groupbasedpolicy.renderer.vpp.sf.Classifier classif =
- resolveImplementedClassifForDir(direction, resolvedRule.getClassifier());
- GbpAceBuilder aclRuleBuilder =
- new GbpAceBuilder(resolvedRule.getName().getValue() + UNDERSCORE + namePasphrase);
- boolean updated = classif != null && classif.updateMatch(aclRuleBuilder, params);
- Optional<Actions> optAction = resolveActions(resolvedRule.getAction());
- if (!optAction.isPresent() || !updated) {
- LOG.error("Failed to process rule {}. Resolved parameters {}, resolved classifier. Actions resolved: {}"
- + "{}.", resolvedRule.getName().getValue(), params, classif, optAction.isPresent());
- continue;
- }
- aclRuleBuilder.setAction(optAction.get());
- aclRules.add(aclRuleBuilder);
}
return aclRules;
}
+ public static Optional<GbpAceBuilder> resolveAceClassifersAndAction(ResolvedRule resolvedRule, Direction direction, String ruleName) {
+ Map<String, ParameterValue> params = resolveClassifParamsForDir(direction, resolvedRule.getClassifier());
+ if (params.isEmpty()) {
+ return Optional.absent();
+ }
+ org.opendaylight.groupbasedpolicy.renderer.vpp.sf.Classifier classif =
+ resolveImplementedClassifForDir(direction, resolvedRule.getClassifier());
+ GbpAceBuilder aclRuleBuilder = new GbpAceBuilder(ruleName);
+ //new GbpAceBuilder(resolvedRule.getName().getValue() + UNDERSCORE + namePasphrase);
+ boolean updated = classif != null && classif.updateMatch(aclRuleBuilder, params);
+ Optional<Actions> optAction = resolveActions(resolvedRule.getAction());
+ if (!optAction.isPresent() || !updated) {
+ LOG.error("Failed to process rule {}. Resolved parameters {}, resolved classifier. Actions resolved: {}"
+ + "{}.", resolvedRule.getName().getValue(), params, classif, optAction.isPresent());
+ return Optional.absent();
+ }
+ aclRuleBuilder.setAction(optAction.get());
+ return Optional.of(aclRuleBuilder);
+ }
+
private static org.opendaylight.groupbasedpolicy.renderer.vpp.sf.Classifier resolveImplementedClassifForDir(
@Nonnull Direction direction, @Nonnull List<Classifier> classifiers) {
org.opendaylight.groupbasedpolicy.renderer.vpp.sf.Classifier feasibleClassifier = null;
classifier.stream()
.filter(classif -> direction.equals(classif.getDirection()) || direction.equals(Direction.Bidirectional))
.forEach(classif -> {
- LOG.trace("Resolving parameters for classiifier: {} with direction", classif, direction);
classif.getParameterValue()
.stream()
.filter(v -> params.get(v.getName().getValue()) == null) // not unique
.filter(v -> v.getIntValue() != null || v.getStringValue() != null || v.getRangeValue() != null)
.forEach(v -> params.put(v.getName().getValue(), v));
- LOG.trace("Resolved parameters {} for classiifier: {} with direction {}", params, classif, direction);
});
return params;
}
for (Action action : actions) {
if (AllowActionDefinition.ID
.equals(action.getActionDefinitionId())) {
- LOG.trace("Applying supported action: {}", action);
return Optional
.of(new ActionsBuilder().setPacketHandling(new PermitBuilder().setPermit(true).build()).build());
}
}
- LOG.warn("No supported action found among actions: {}", actions);
return Optional.absent();
}
import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl.AccessListUtil.ACE_DIRECTION;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
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.InterfaceKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppAcl;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract AccessListUtil.ACE_DIRECTION getDirection();
- public abstract void writeAclRefOnIface(@Nonnull DataBroker mountPoint,
+ public abstract void writeAclRefOnIface(@Nonnull InstanceIdentifier<Node> vppIid,
@Nonnull InstanceIdentifier<Interface> ifaceIid);
public Acl buildVppAcl(@Nonnull InterfaceKey ifaceKey) {
.build();
}
- public void writeAcl(@Nonnull DataBroker mountPoint, @Nonnull InterfaceKey ifaceKey) {
+ public void writeAcl(@Nonnull InstanceIdentifier<Node> vppIid, @Nonnull InterfaceKey ifaceKey) {
Acl builtAcl = this.buildVppAcl(ifaceKey);
LOG.trace("Writing access-list {}", builtAcl.getAclName());
- boolean write = GbpNetconfTransaction.netconfSyncedWrite(mountPoint,
+ boolean write = GbpNetconfTransaction.netconfSyncedWrite(vppIid,
VppIidFactory.getVppAcl(resolveAclName(ifaceKey)), builtAcl, GbpNetconfTransaction.RETRY_COUNT);
if (!write) {
LOG.error("Failed to write rule {}", builtAcl);
}
}
- public static void removeAclsForInterface(@Nonnull DataBroker mountPoint, @Nonnull InterfaceKey ifaceKey) {
+ public static void removeAclsForInterface(@Nonnull InstanceIdentifier<Node> vppIid, @Nonnull InterfaceKey ifaceKey) {
LOG.debug("Removing access-list {}", ifaceKey);
for (ACE_DIRECTION dir : new ACE_DIRECTION[] {ACE_DIRECTION.INGRESS, ACE_DIRECTION.EGRESS}) {
- GbpNetconfTransaction.netconfSyncedDelete(mountPoint,
+ GbpNetconfTransaction.netconfSyncedDelete(vppIid,
VppIidFactory.getVppAcl(ifaceKey.getName() + dir), GbpNetconfTransaction.RETRY_COUNT);
}
}
- public static void removeAclRefFromIface(@Nonnull DataBroker mountPoint, @Nonnull InterfaceKey ifaceKey) {
+ public static void removeAclRefFromIface(@Nonnull InstanceIdentifier<Node> vppIid, @Nonnull InterfaceKey ifaceKey) {
LOG.debug("Removing access-lists from interface {}", ifaceKey.getName());
- GbpNetconfTransaction.netconfSyncedDelete(mountPoint,
+ GbpNetconfTransaction.netconfSyncedDelete(vppIid,
VppIidFactory.getAclInterfaceRef(VppIidFactory.getInterfaceIID(ifaceKey)),
GbpNetconfTransaction.RETRY_COUNT);
}
package org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
import java.util.function.Predicate;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.InterfaceManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.VppPathMapper;
import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.PolicyContext;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.RendererResolvedPolicy;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.ResolvedRuleGroup;
import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl.AccessListUtil.ACE_DIRECTION;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.KeyFactory;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
import org.opendaylight.groupbasedpolicy.util.EndpointUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.AclKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.AccessListEntries;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.access.lists.acl.access.list.entries.Ace;
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.InterfaceKey;
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.absolute.location.location.type.ExternalLocationCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.L2BridgeDomain;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.HasDirection.Direction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.RendererEndpoint;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.RendererEndpointKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.renderer.endpoint.PeerEndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.rule.groups.RuleGroupKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppAcl;
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;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSetMultimap;
+import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.ImmutableTable.Builder;
+import com.google.common.collect.SetMultimap;
import com.google.common.collect.Sets;
+import com.google.common.collect.Sets.SetView;
+import com.google.common.collect.Table;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+import com.google.common.util.concurrent.SettableFuture;
public class AclManager {
private static final Logger LOG = LoggerFactory.getLogger(AclManager.class);
private final MountedDataBrokerProvider mountDataProvider;
- private static ImmutableTable<NodeId, InterfaceKey, ImmutableSet<AddressEndpointKey>> multipleEndpointsOnInterface;
+ private static ImmutableTable<NodeId, InterfaceKey, ImmutableSet<AddressEndpointKey>> endpointsByInterface;
+ private final InterfaceManager interfaceManager;
+ ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(30));
- public AclManager(@Nonnull MountedDataBrokerProvider mountDataProvider) {
+ public AclManager(@Nonnull MountedDataBrokerProvider mountDataProvider, InterfaceManager interfaceManager) {
this.mountDataProvider = Preconditions.checkNotNull(mountDataProvider);
+ this.interfaceManager = Preconditions.checkNotNull(interfaceManager);
}
- public List<AccessListWrapper> resolveAclsOnInterface(RendererEndpointKey rEpKey, PolicyContext ctx) {
- List<AccessListWrapper> aclWrappers = new ArrayList<>();
- for (ACE_DIRECTION dir : new ACE_DIRECTION[] {ACE_DIRECTION.INGRESS, ACE_DIRECTION.EGRESS}) {
- aclWrappers.add(buildAccessListWrappers(dir, ctx, rEpKey));
- }
- return aclWrappers;
+ public ListenableFuture<List<AccessListWrapper>> resolveAclsOnInterface(RendererEndpointKey rEpKey,
+ PolicyContext ctx) {
+ Callable<List<AccessListWrapper>> aclBuildExecutor = new Callable<List<AccessListWrapper>>() {
+
+ @Override
+ public List<AccessListWrapper> call() throws Exception {
+ LOG.info("Resolving ACL for renderer endpoint {}", rEpKey);
+ List<AccessListWrapper> aclWrappers = new ArrayList<>();
+ for (ACE_DIRECTION dir : new ACE_DIRECTION[] {ACE_DIRECTION.INGRESS, ACE_DIRECTION.EGRESS}) {
+ aclWrappers.add(buildAccessListWrappers(dir, ctx, rEpKey));
+ }
+ return aclWrappers;
+ }
+ };
+ ListenableFuture<List<AccessListWrapper>> accessListFuture = executor.submit(aclBuildExecutor);
+ return accessListFuture;
}
/**
return aclWrapper;
}
+ public void resolveRulesToConfigure(@Nonnull PolicyContext policyCtx,
+ @Nonnull SetView<RendererEndpointKey> changedEndpoints, @Nonnull SetView<RuleGroupKey> changedRules, boolean write) {
+ Table<NodeId, AclKey, List<Ace>> aceTable = HashBasedTable.<NodeId, AclKey, List<Ace>>create();
+ Map<RendererEndpointKey, Set<RuleGroupKey>> endpointsToUpdate = new HashMap<>();
+ // rules changed
+ changedRules.forEach(changedGroupRuleKey -> {
+ policyCtx.getEndpointsByRuleGroups().get(changedGroupRuleKey).forEach(rendEp -> {
+ endpointsToUpdate.put(rendEp, changedRules);
+ });
+ });
+ // end-points changed
+ for (RendererEndpointKey rendEp : changedEndpoints) {
+ policyCtx.getPolicyTable().row(rendEp).keySet().forEach(peer -> {
+ ImmutableSortedSet<RendererResolvedPolicy> resolvedPolicy =
+ policyCtx.getPolicyTable().get(rendEp, peer);
+ if (resolvedPolicy == null) {
+ return;
+ }
+ Set<RuleGroupKey> ruleGroupsToUpdate = resolvedPolicy.stream()
+ .map(policy -> policy.getRuleGroup().getRelatedRuleGroupKey())
+ .collect(Collectors.toSet());
+ if (endpointsToUpdate.get(rendEp) != null) {
+ endpointsToUpdate.put(rendEp,
+ Stream.concat(endpointsToUpdate.get(rendEp).stream(), ruleGroupsToUpdate.stream())
+ .collect(Collectors.toSet()));
+ } else {
+ endpointsToUpdate.put(rendEp, ruleGroupsToUpdate);
+ }
+ });
+ }
+ for (ACE_DIRECTION aceDirection : new ACE_DIRECTION[] {ACE_DIRECTION.INGRESS, ACE_DIRECTION.EGRESS}) {
+ endpointsToUpdate.forEach((endpointKey, rulesToUpdate) -> {
+ java.util.Optional<RendererEndpoint> endpointToUpdate = policyCtx.getPolicy()
+ .getConfiguration()
+ .getRendererEndpoints()
+ .getRendererEndpoint()
+ .stream()
+ .filter(rendEpInPolicy -> rendEpInPolicy.getKey().equals(endpointKey))
+ .findAny();
+ Builder<RendererEndpointKey, PeerEndpointKey, List<RendererResolvedPolicy>> updateTreeBuilder = new Builder<>();
+ endpointToUpdate.get()
+ .getPeerEndpoint()
+ .stream()
+ .filter(peer -> policyCtx.getPolicyTable().get(endpointKey, peer.getKey()) != null)
+ .forEach(peer -> {updateTreeBuilder.put(endpointKey, peer.getKey(),
+ policyCtx.getPolicyTable()
+ .get(endpointKey, peer.getKey())
+ .stream()
+ .filter(rrp -> rulesToUpdate.contains(rrp.getRuleGroup().getRelatedRuleGroupKey()))
+ .collect(Collectors.toList()));
+ });
+ ImmutableTable<RendererEndpointKey, PeerEndpointKey, List<RendererResolvedPolicy>> updateTree = updateTreeBuilder.build();
+ List<GbpAceBuilder> aceBuilders = new ArrayList<>();
+ updateTree.columnKeySet().stream().filter(p -> updateTree.get(endpointKey, p) != null).forEach(peer -> {
+ updateTree.get(endpointKey, peer).stream().forEach(rendererResolvedPolicy -> {
+ if (write) {
+ aceBuilders.addAll(generateRulesForEndpointPair(policyCtx, endpointKey, peer,
+ rendererResolvedPolicy, aceDirection));
+ } else {
+ // we only need to resolve rule names when removing ACE
+ aceBuilders.addAll(rendererResolvedPolicy.getRuleGroup()
+ .getRules()
+ .stream()
+ .map(rule -> new GbpAceBuilder(
+ AccessListUtil.resolveAceName(rule.getName(), endpointKey, peer)))
+ .collect(Collectors.toList()));
+ }
+ });
+ });
+ ImmutableSetMultimap<NodeId, InterfaceKey> interfacesForEndpoint =
+ getInterfacesForEndpoint(policyCtx, KeyFactory.addressEndpointKey(endpointKey));
+ interfacesForEndpoint.keySet().forEach(nodeId -> {
+ ImmutableSet<InterfaceKey> intfcsOnNode = interfacesForEndpoint.get(nodeId);
+ intfcsOnNode.forEach(intf -> {
+ if (aceTable.get(nodeId, intf) != null) {
+ List<Ace> aces = Stream
+ .concat(aceTable.get(nodeId, intf).stream(),
+ aceBuilders.stream().map(aceBuilder -> aceBuilder.build()))
+ .collect(Collectors.toList());
+ aceTable.put(nodeId, new AclKey(intf.getName() + aceDirection, VppAcl.class), aces);
+ } else {
+ aceTable.put(nodeId, new AclKey(intf.getName() + aceDirection, VppAcl.class),
+ aceBuilders.stream()
+ .map(aceBuilder -> aceBuilder.build())
+ .collect(Collectors.toList()));
+ }
+ });
+ });
+ });
+ }
+ updateRules(ImmutableTable.copyOf(aceTable), write);
+ }
+
+ private void updateRules(ImmutableTable<NodeId, AclKey, List<Ace>> rulesToUpdate, boolean write) {
+ List<ListenableFuture<Void>> sync = new ArrayList<>();
+ rulesToUpdate.rowKeySet().forEach(nodeId -> {
+ Callable<Void> syncExecutor = new Callable<Void>() {
+
+ @Override
+ public Void call() throws Exception {
+ LOG.debug("Updating node {}", nodeId);
+ InstanceIdentifier<Node> vppIid = VppIidFactory.getNetconfNodeIid(nodeId);
+ Optional<DataBroker> dataBroker =
+ mountDataProvider.resolveDataBrokerForMountPoint(vppIid);
+ if (dataBroker.isPresent()) {
+ LOG.error("Failed to update ACLs for endpoints on node {}. Mount point does not exist.",
+ nodeId);
+ }
+ ImmutableMap<AclKey, List<Ace>> row = rulesToUpdate.row(nodeId);
+ row.keySet().forEach(aclKey -> {
+ Map<InstanceIdentifier<Ace>, Ace> entries = new HashMap<>();
+ row.get(aclKey).forEach(ace -> {
+ entries.put(VppIidFactory.getVppAcl(aclKey)
+ .builder()
+ .child(AccessListEntries.class)
+ .child(Ace.class, ace.getKey())
+ .build(), ace);
+ });
+ if (entries.isEmpty()) {
+ return;
+ }
+ LOG.info("Updating ACL: Action={}, Node={}, ACL={}", write, nodeId.getValue(),
+ aclKey.getAclName());
+ boolean result = (write) ? GbpNetconfTransaction.netconfSyncedWrite(vppIid, entries,
+ GbpNetconfTransaction.RETRY_COUNT) : GbpNetconfTransaction.netconfSyncedDelete(
+ vppIid, entries.keySet(), GbpNetconfTransaction.RETRY_COUNT);
+ if (!result) {
+ LOG.error("Failed to remove rules from ACL {} on mount point {}", aclKey,
+ nodeId.getValue());
+ }
+ });
+ return null;
+ }
+ };
+ sync.add(executor.submit(syncExecutor));
+ });
+ try {
+ Futures.allAsList(sync).get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Failed to sync ACLs on VPP nodes. {}", e);
+ }
+ }
+
+ private List<GbpAceBuilder> generateRulesForEndpointPair(PolicyContext ctx, RendererEndpointKey r,
+ PeerEndpointKey p, RendererResolvedPolicy rrp, ACE_DIRECTION aceDirection) {
+ List<GbpAceBuilder> rules = new ArrayList<>();
+ Direction direction =
+ AccessListUtil.calculateClassifDirection(rrp.getRendererEndpointParticipation(), aceDirection);
+ ResolvedRuleGroup resolvedRuleGroup = ctx.getRuleGroupByKey().get(rrp.getRuleGroup().getRelatedRuleGroupKey());
+ resolvedRuleGroup.getRules().forEach(rule -> {
+ Optional<GbpAceBuilder> ace = AccessListUtil.resolveAceClassifersAndAction(rule, direction,
+ AccessListUtil.resolveAceName(rule.getName(), r, p));
+ if (ace.isPresent()) {
+ rules.add(ace.get());
+ }
+ });
+ AccessListUtil.updateAddressesInRules(rules, r, p, ctx, aceDirection, true);
+ return rules;
+ }
+
+ //TODO remove
public void updateAclsForPeers(PolicyContext policyCtx, RendererEndpointKey rEpKey) {
ImmutableSet<PeerEndpointKey> peers = policyCtx.getPolicyTable().row(rEpKey).keySet();
+ List<ListenableFuture<Void>> sync = new ArrayList<>();
for (RendererEndpointKey peerRendEp : peers.stream()
.map(AddressEndpointUtils::fromPeerEpKey)
.collect(Collectors.toList())
.stream()
.map(AddressEndpointUtils::toRendererEpKey)
.collect(Collectors.toList())) {
- updateAclsForRendEp(peerRendEp, policyCtx);
+ sync.add(updateAclsForRendEp(peerRendEp, policyCtx));
+ }
+ try {
+ Futures.allAsList(sync).get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Failed to update ACLs for peers of {}. {}", rEpKey, e);
}
}
- public void updateAclsForRendEp(RendererEndpointKey rEpKey, PolicyContext policyCtx) {
- LOG.info("Updating policy for endpoint {}", rEpKey);
+ public ListenableFuture<Void> updateAclsForRendEp(RendererEndpointKey rEpKey, PolicyContext policyCtx) {
+ SettableFuture<Void> sf = SettableFuture.create();
AddressEndpointWithLocation peerAddrEp = policyCtx.getAddrEpByKey().get(KeyFactory.addressEndpointKey(rEpKey));
ExternalLocationCase epLoc;
try {
} catch (NullPointerException | IllegalArgumentException e) {
//TODO investigate, don't just move on.
LOG.warn("Peer {} has no location. Moving on...", peerAddrEp, e.getMessage());
- return;
+ return Futures.immediateFuture(null);
}
- InstanceIdentifier<?> vppNodeIid = epLoc.getExternalNodeMountPoint();
+ InstanceIdentifier<Node> vppNodeIid = (InstanceIdentifier<Node>) epLoc.getExternalNodeMountPoint();
Optional<InstanceIdentifier<Interface>> optInterfaceIid =
VppPathMapper.interfaceToInstanceIdentifier(epLoc.getExternalNodeConnector());
if (!optInterfaceIid.isPresent()) {
LOG.warn("Cannot find interface for endpoint {}. ACLs for endpoint not updated {}. ", rEpKey);
- return;
+ return Futures.immediateFuture(null);
}
- Optional<DataBroker> optMountPoint = mountDataProvider.getDataBrokerForMountPoint(vppNodeIid);
- resolveAclsOnInterface(rEpKey, policyCtx).forEach(aclWrapper -> aclWrapper
- .writeAcl(optMountPoint.get(), optInterfaceIid.get().firstKeyOf(Interface.class)));
+ if (interfaceManager.isExcludedFromPolicy(vppNodeIid.firstKeyOf(Node.class).getNodeId(),
+ optInterfaceIid.get().firstKeyOf(Interface.class).getName())) {
+ return Futures.immediateFuture(null);
+ }
+ LOG.info("Updating policy for endpoint {}", rEpKey);
+ ListenableFuture<List<AccessListWrapper>> future = resolveAclsOnInterface(rEpKey, policyCtx);
+ Futures.addCallback(future, new FutureCallback<List<AccessListWrapper>>() {
+
+ @Override
+ public void onSuccess(List<AccessListWrapper> result) {
+ result.forEach(
+ acl -> acl.writeAcl(vppNodeIid, optInterfaceIid.get().firstKeyOf(Interface.class)));
+ sf.set(null);
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ LOG.error("Failed to update ACL for interface {} on node {}",
+ optInterfaceIid.get().firstKeyOf(Interface.class), vppNodeIid.firstKeyOf(Node.class));
+ sf.set(null);
+ }
+ }, MoreExecutors.directExecutor());
+ return sf;
}
/**
* Cache end-points accessible via a single interface for further processing.
+ *
+ * @param ctx policy context
*/
public void cacheMultiInterfaces(@Nonnull PolicyContext ctx) {
Builder<NodeId, InterfaceKey, ImmutableSet<AddressEndpointKey>> resultBuilder = new Builder<>();
resolveEndpointsOnMultipleInterface(ImmutableList.copyOf(ctx.getAddrEpByKey().values()), resultBuilder);
- multipleEndpointsOnInterface = resultBuilder.build();
+ endpointsByInterface = resultBuilder.build();
}
/**
public @Nonnull static ImmutableSet<AddressEndpointKey> otherEndpointsOnTheSameInterface(@Nonnull PolicyContext ctx,
@Nonnull AddressEndpointKey key) {
- if (multipleEndpointsOnInterface != null) {
- for (InterfaceKey ifaceKey : multipleEndpointsOnInterface.columnKeySet()) {
- for (NodeId nodeId : multipleEndpointsOnInterface.column(ifaceKey).keySet()) {
- ImmutableSet<AddressEndpointKey> addrEps = multipleEndpointsOnInterface.get(nodeId, ifaceKey);
+ if (endpointsByInterface != null) {
+ for (InterfaceKey ifaceKey : endpointsByInterface.columnKeySet()) {
+ for (NodeId nodeId : endpointsByInterface.column(ifaceKey).keySet()) {
+ ImmutableSet<AddressEndpointKey> addrEps = endpointsByInterface.get(nodeId, ifaceKey);
if (addrEps != null && addrEps.contains(key) && addrEps.size() > 1) {
- return multipleEndpointsOnInterface.get(nodeId, ifaceKey);
+ return endpointsByInterface.get(nodeId, ifaceKey);
}
}
}
}
return ImmutableSet.copyOf(Sets.newHashSet());
}
+
+ public @Nonnull static ImmutableSetMultimap<NodeId, InterfaceKey> getInterfacesForEndpoint(@Nonnull PolicyContext ctx,
+ @Nonnull AddressEndpointKey key) {
+ SetMultimap<NodeId, InterfaceKey> interfaces = HashMultimap.create();
+ if (endpointsByInterface != null) {
+ for (InterfaceKey ifaceKey : endpointsByInterface.columnKeySet()) {
+ for (NodeId nodeId : endpointsByInterface.column(ifaceKey).keySet()) {
+ ImmutableSet<AddressEndpointKey> addrEps = endpointsByInterface.get(nodeId, ifaceKey);
+ if (addrEps != null && addrEps.contains(key)) {
+ interfaces.put(nodeId, ifaceKey);
+ }
+ }
+ }
+ }
+ return ImmutableSetMultimap.copyOf(interfaces);
+ }
}
}
address = parentEndpoints.get(0).getAddress();
}
- LOG.trace("Setting dst IP address {} in rule {}", address, aclRuleBuilder);
try {
AccessListUtil.setDestinationL3Address(aclRuleBuilder, address);
} catch (UnknownHostException e) {
import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl.AccessListUtil.ACE_DIRECTION;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAcls;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAclsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppAcl;
+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;
import com.google.common.collect.ImmutableList;
}
@Override
- public void writeAclRefOnIface(@Nonnull DataBroker mountPoint, @Nonnull InstanceIdentifier<Interface> ifaceIid) {
+ public void writeAclRefOnIface(@Nonnull InstanceIdentifier<Node> vppIid, @Nonnull InstanceIdentifier<Interface> ifaceIid) {
InstanceIdentifier<Egress> egressRefIid = VppIidFactory.getAclInterfaceRef(ifaceIid).child(Egress.class);
VppAcls vppAcl = new VppAclsBuilder().setName(resolveAclName(ifaceIid.firstKeyOf(Interface.class)))
.setType(VppAcl.class)
.build();
Egress egressAcl = new EgressBuilder().setVppAcls(ImmutableList.<VppAcls>of(vppAcl)).build();
- GbpNetconfTransaction.netconfSyncedWrite(mountPoint, egressRefIid, egressAcl,
+ GbpNetconfTransaction.netconfSyncedWrite(vppIid, egressRefIid, egressAcl,
GbpNetconfTransaction.RETRY_COUNT);
}
}
import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl.AccessListUtil.ACE_DIRECTION;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAcls;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.vpp.acls.base.attributes.VppAclsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.acl.rev170615.VppAcl;
+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;
import com.google.common.collect.ImmutableList;
}
@Override
- public void writeAclRefOnIface(@Nonnull DataBroker mountPoint, @Nonnull InstanceIdentifier<Interface> ifaceIid) {
+ public void writeAclRefOnIface(@Nonnull InstanceIdentifier<Node> vppIid, @Nonnull InstanceIdentifier<Interface> ifaceIid) {
InstanceIdentifier<Ingress> ingressRefIid = VppIidFactory.getAclInterfaceRef(ifaceIid).child(Ingress.class);
VppAcls vppAcl = new VppAclsBuilder().setName(resolveAclName(ifaceIid.firstKeyOf(Interface.class)))
.setType(VppAcl.class)
.build();
Ingress egressAcl = new IngressBuilder().setVppAcls(ImmutableList.<VppAcls>of(vppAcl)).build();
- GbpNetconfTransaction.netconfSyncedWrite(mountPoint, ingressRefIid, egressAcl,
+ GbpNetconfTransaction.netconfSyncedWrite(vppIid, ingressRefIid, egressAcl,
GbpNetconfTransaction.RETRY_COUNT);
}
}
}
address = parentEndpoints.get(0).getAddress();
}
- LOG.trace("Setting src IP address {} in rule {}", address, aclRuleBuilder);
try {
AccessListUtil.setSourceL3Address(aclRuleBuilder, address);
} catch (UnknownHostException e) {
package org.opendaylight.groupbasedpolicy.renderer.vpp.routing;
-import com.google.common.base.Optional;
-import com.google.common.base.Strings;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Nonnull;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.forwarding.RendererForwardingByTenant;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.forwarding.renderer.forwarding.by.tenant.RendererNetworkDomain;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.renderers.renderer.renderer.nodes.renderer.node.PhysicalInterface;
+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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nonnull;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import com.google.common.base.Optional;
+import com.google.common.base.Strings;
public class RoutingManager {
private static final Logger LOG = LoggerFactory.getLogger(RoutingManager.class);
this.mountDataProvider = mountDataProvider;
}
- public Map<InstanceIdentifier<?>, RoutingCommand> createRouting(
+ public Map<InstanceIdentifier<Node>, RoutingCommand> createRouting(
@Nonnull RendererForwardingByTenant forwardingByTenant, List<InstanceIdentifier<PhysicalInterface>> physIntIids,
General.Operations operation) {
- Map<InstanceIdentifier<?>, RoutingCommand> routingCommands = new HashMap<>();
+ Map<InstanceIdentifier<Node>, RoutingCommand> routingCommands = new HashMap<>();
getExternalGateways(forwardingByTenant.getRendererNetworkDomain()).forEach((gateways, virtualRouterIp) -> {
LOG.trace("Creating routing for Tenant {}, gateway {}, virtualRouterIp {}.",
forwardingByTenant.getTenantId(), gateways, virtualRouterIp);
List<Route> ipv4Routes = new ArrayList<>();
PhysicalInterface outboundInterface = resolveOutboundInterface(virtualRouterIp, physIntIids);
- InstanceIdentifier<?> node = resolveOutboundNode(virtualRouterIp, physIntIids);
+ InstanceIdentifier<Node> node = resolveOutboundNode(virtualRouterIp, physIntIids);
String outboundIntName = outboundInterface != null ? outboundInterface.getInterfaceName() : null;
return null;
}
- private InstanceIdentifier<?> resolveOutboundNode(@Nonnull IpAddress extIfaceIp,
+ private InstanceIdentifier<Node> resolveOutboundNode(@Nonnull IpAddress extIfaceIp,
List<InstanceIdentifier<PhysicalInterface>> physIntIids) {
for (InstanceIdentifier<PhysicalInterface> identifier : physIntIids) {
Optional<PhysicalInterface> physicalInterfaceOptional = DataStoreHelper.readFromDs(
continue;
}
if (physicalInterfaceOptional.get().isExternal()) {
- return identifier.firstKeyOf(RendererNode.class).getNodePath();
+ return (InstanceIdentifier<Node>) identifier.firstKeyOf(RendererNode.class).getNodePath();
}
if (physicalInterfaceOptional.get().getAddress().contains(extIfaceIp)){
- return identifier.firstKeyOf(RendererNode.class).getNodePath();
+ return (InstanceIdentifier<Node>) identifier.firstKeyOf(RendererNode.class).getNodePath();
}
}
return null;
}
- public boolean submitRouting(@Nonnull RoutingCommand routing, InstanceIdentifier<?> nodeIid) {
+ public boolean submitRouting(@Nonnull RoutingCommand routing, InstanceIdentifier<Node> nodeIid) {
if (nodeIid == null) {
LOG.info("NodeId is null Cannot create routing. RoutingCommand: {}", routing);
return false;
}
LOG.trace("Submitting routing for routing command: {}, nodeId: {}", routing, nodeIid);
- Optional<DataBroker> mountPointDataBroker = mountDataProvider.getDataBrokerForMountPoint(nodeIid);
- if (!mountPointDataBroker.isPresent()) {
+ Optional<DataBroker> mountPointDataBroker = mountDataProvider.resolveDataBrokerForMountPoint(nodeIid);
+ if (mountPointDataBroker.isPresent()) {
throw new IllegalStateException("Cannot find data broker for mount point " + nodeIid);
}
LOG.info("Routing was created for forwarding. Routing: {}, for node: {}", routing, nodeIid);
if (routing.getOperation() == General.Operations.PUT){
- return GbpNetconfTransaction.netconfSyncedWrite(mountPointDataBroker.get(), routing,
+ return GbpNetconfTransaction.netconfSyncedWrite(nodeIid, routing,
GbpNetconfTransaction.RETRY_COUNT);
} else if (routing.getOperation() == General.Operations.DELETE){
- return GbpNetconfTransaction.netconfSyncedDelete(mountPointDataBroker.get(), routing,
+ return GbpNetconfTransaction.netconfSyncedDelete(nodeIid, routing,
GbpNetconfTransaction.RETRY_COUNT);
}
return false;
package org.opendaylight.groupbasedpolicy.renderer.vpp.util;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+
import javax.annotation.Nonnull;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.AbstractConfigCommand;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.AbstractInterfaceCommand;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.RoutingCommand;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.interfaces.ConfigCommand;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.lisp.AbstractLispCommand;
import org.opendaylight.vbd.impl.transaction.VbdNetconfTransaction;
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.routing.rev140524.routing.routing.instance.routing.protocols.RoutingProtocol;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.routing.instance.routing.protocols.RoutingProtocolKey;
+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.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
/***
* Netconf wrapper for write and delete operation on a Netconf Device
- * @param mountpoint netconf device
+ * @param vppIid destination node
* @param iid path for Data to be written to
* @param data data to be written
* @param retryCounter retry counter, will repeat the operation for specified amount of times if transaction fails
* @param <T> data type
* @return true if transaction is successful, false otherwise
*/
- public static <T extends DataObject> boolean netconfSyncedWrite(@Nonnull final DataBroker mountpoint,
+ public static <T extends DataObject> boolean netconfSyncedWrite(@Nonnull final InstanceIdentifier<Node> vppIid,
@Nonnull final InstanceIdentifier<T> iid, @Nonnull final T data, byte retryCounter) {
- VbdNetconfTransaction.REENTRANT_LOCK.lock();
- boolean result = write(mountpoint, iid, data, retryCounter);
- VbdNetconfTransaction.REENTRANT_LOCK.unlock();
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().lock();
+ boolean result = write(VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey(), iid, data, retryCounter);
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().unlock();
return result;
}
+ public static <T extends DataObject> boolean netconfSyncedWrite(@Nonnull final InstanceIdentifier<Node> vppIid,
+ @Nonnull final Map<InstanceIdentifier<T>,T> data, byte retryCounter) {
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().lock();
+ boolean result = write(VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey(), data, retryCounter);
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().unlock();
+ return result;
+ }
+
/***
* Netconf wrapper for merge operation on a Netconf Device
- * @param mountpoint netconf device
+ * @param vppIid destination node
* @param iid path for Data to be merged to
* @param data data to be merged
* @param retryCounter retry counter, will repeat the operation for specified amount of times if transaction fails
* @param <T> data type
* @return true if transaction is successful, false otherwise
*/
- public static <T extends DataObject> boolean netconfSyncedMerge(@Nonnull final DataBroker mountpoint,
+ public static <T extends DataObject> boolean netconfSyncedMerge(@Nonnull final InstanceIdentifier<Node> vppIid,
@Nonnull final InstanceIdentifier<T> iid, @Nonnull final T data, byte retryCounter) {
- VbdNetconfTransaction.REENTRANT_LOCK.lock();
- boolean result = merge(mountpoint, iid, data, retryCounter);
- VbdNetconfTransaction.REENTRANT_LOCK.unlock();
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().lock();
+ boolean result = merge(VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey(), iid, data, retryCounter);
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().unlock();
return result;
}
/***
* Netconf wrapper method for synced requests for write operation on a Netconf Device
- * @param mountpoint netconf device
+ * @param vppIid destination node
* @param command config command that needs to be executed
* @param retryCounter retry counter, will repeat the operation for specified amount of times if transaction fails
* @return true if transaction is successful, false otherwise
*/
- public static boolean netconfSyncedWrite(@Nonnull final DataBroker mountpoint, @Nonnull final ConfigCommand command,
+ public static boolean netconfSyncedWrite(@Nonnull final InstanceIdentifier<Node> vppIid, @Nonnull final ConfigCommand command,
byte retryCounter) {
- VbdNetconfTransaction.REENTRANT_LOCK.lock();
- boolean result = write(mountpoint, command, retryCounter);
- VbdNetconfTransaction.REENTRANT_LOCK.unlock();
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().lock();
+ boolean result = write(VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey(), command, retryCounter);
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().unlock();
return result;
}
/***
* Netconf wrapper method for synced requests for write operation on a Netconf Device
- * @param mountpoint netconf device
- * @param command abstract lisp command that needs to be executed
+ * @param vppIid destination node
+ * @param command routing command that needs to be executed
* @param retryCounter retry counter, will repeat the operation for specified amount of times if transaction fails
* @return true if transaction is successful, false otherwise
*/
- public static <T extends DataObject> boolean netconfSyncedWrite(@Nonnull final DataBroker mountpoint,
- @Nonnull final AbstractLispCommand<T> command,
- byte retryCounter) {
- VbdNetconfTransaction.REENTRANT_LOCK.lock();
- boolean result = write(mountpoint, command, retryCounter);
- VbdNetconfTransaction.REENTRANT_LOCK.unlock();
+ public static boolean netconfSyncedWrite(@Nonnull final InstanceIdentifier<Node> vppIid, @Nonnull final RoutingCommand command,
+ byte retryCounter) {
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().lock();
+ boolean result = write(VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey(), command, retryCounter);
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().unlock();
return result;
}
/***
* Netconf wrapper method for synced requests for delete operation on a Netconf Device
- * @param mountpoint netconf device
+ * @param vppIid destination node
* @param iid path for Data to be written to
* @param retryCounter retry counter, will repeat the operation for specified amount of times if transaction fails
* @param <T> data type
* @return true if transaction is successful, false otherwise
*/
- public static <T extends DataObject> boolean netconfSyncedDelete(@Nonnull final DataBroker mountpoint,
+ public static <T extends DataObject> boolean netconfSyncedDelete(@Nonnull final InstanceIdentifier<Node> vppIid,
@Nonnull final InstanceIdentifier<T> iid, byte retryCounter) {
- VbdNetconfTransaction.REENTRANT_LOCK.lock();
- boolean result = deleteIfExists(mountpoint, iid, retryCounter);
- VbdNetconfTransaction.REENTRANT_LOCK.unlock();
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().lock();
+ boolean result = deleteIfExists(vppIid, iid, retryCounter);
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().unlock();
return result;
}
+ public static <T extends DataObject> boolean netconfSyncedDelete(@Nonnull final InstanceIdentifier<Node> vppIid,
+ @Nonnull Set<InstanceIdentifier<T>> iids , byte retryCounter) {
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().lock();
+ boolean result = deleteIfExists(vppIid, iids, retryCounter);
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().unlock();
+ return result;
+ }
+
/***
* Netconf wrapper method for synced requests for delete operation on a Netconf Device
- * @param mountpoint netconf device
+ * @param vppIid destination node
* @param command config command that needs to be executed
* @param retryCounter retry counter, will repeat the operation for specified amount of times if transaction fails
* @return true if transaction is successful, false otherwise
*/
- public static boolean netconfSyncedDelete(@Nonnull final DataBroker mountpoint,
- @Nonnull final AbstractInterfaceCommand command, byte retryCounter) {
- VbdNetconfTransaction.REENTRANT_LOCK.lock();
- boolean result = deleteIfExists(mountpoint, command, retryCounter);
- VbdNetconfTransaction.REENTRANT_LOCK.unlock();
+ public static boolean netconfSyncedDelete(@Nonnull final InstanceIdentifier<Node> vppIid,
+ @Nonnull final ConfigCommand command, byte retryCounter) {
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().lock();
+ boolean result = deleteIfExists(vppIid, command.getIid(), retryCounter);
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().unlock();
return result;
}
/***
* Netconf wrapper method for synced requests for delete operation on a Netconf Device
- * @param mountpoint netconf device
+ * @param vppIid destination node
* @param command routing command that needs to be executed
* @param retryCounter retry counter, will repeat the operation for specified amount of times if transaction fails
* @return true if transaction is successful, false otherwise
*/
- public static boolean netconfSyncedDelete(@Nonnull final DataBroker mountpoint,
- @Nonnull final AbstractConfigCommand command, byte retryCounter) {
- VbdNetconfTransaction.REENTRANT_LOCK.lock();
- boolean result = deleteIfExists(mountpoint, command, retryCounter);
- VbdNetconfTransaction.REENTRANT_LOCK.unlock();
+ public static boolean netconfSyncedDelete(@Nonnull final InstanceIdentifier<Node> vppIid,
+ @Nonnull final RoutingCommand command, byte retryCounter) {
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().lock();
+ boolean result = deleteIfExists(vppIid, command.getIid(), retryCounter);
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().unlock();
return result;
}
}
}
- /**
- * Use {@link AbstractLispCommand} to put data into netconf transaction and submit. Transaction is restarted if failed
- *
- * @param mountpoint to access remote device
- * @param command abstract lisp command with data, datastore type and iid
- * @param retryCounter number of attempts
- * @return true if transaction is successful, false otherwise
- */
private static <T extends DataObject> boolean write(final DataBroker mountpoint,
- final AbstractLispCommand<T> command,
- byte retryCounter) {
+ @Nonnull final Map<InstanceIdentifier<T>, T> data, byte retryCounter) {
LOG.trace("Netconf WRITE transaction started. RetryCounter: {}", retryCounter);
Preconditions.checkNotNull(mountpoint);
+ Preconditions.checkNotNull(data);
+ Preconditions.checkArgument(!data.isEmpty());
final ReadWriteTransaction rwTx = mountpoint.newReadWriteTransaction();
try {
- command.execute(rwTx);
+ data.forEach((k, v) -> {
+ rwTx.put(LogicalDatastoreType.CONFIGURATION, k, v);
+ });
final CheckedFuture<Void, TransactionCommitFailedException> futureTask = rwTx.submit();
futureTask.get();
- LOG.trace("Netconf WRITE transaction done for command {}", command);
+ LOG.trace("Netconf WRITE transaction done for {}",
+ data.keySet().stream().map(iid -> iid.getPathArguments()));
return true;
} catch (Exception e) {
// Retry
if (retryCounter > 0) {
LOG.warn("Netconf WRITE transaction failed to {}. Restarting transaction ... ", e.getMessage());
- rwTx.cancel();
- return write(mountpoint, command, --retryCounter);
+ return write(mountpoint, data, --retryCounter);
} else {
LOG.warn("Netconf WRITE transaction unsuccessful. Maximal number of attempts reached. Trace: {}", e);
return false;
/**
* Read data from remote device. Transaction is restarted if failed.
*
- * @param mountpoint to access remote device
* @param datastoreType {@link LogicalDatastoreType}
+ * @param vppIid destination node
* @param iid data identifier
* @param retryCounter number of attempts
* @param <T> generic data type. Has to be child of {@link DataObject}
* @return optional data object if successful, {@link Optional#absent()} if failed
*/
- public static synchronized <T extends DataObject> Optional<T> read(final DataBroker mountpoint,
+ public static synchronized <T extends DataObject> Optional<T> read(final InstanceIdentifier<Node> vppIid,
final LogicalDatastoreType datastoreType, final InstanceIdentifier<T> iid, byte retryCounter) {
LOG.trace("Netconf READ transaction started. RetryCounter: {}", retryCounter);
- Preconditions.checkNotNull(mountpoint);
+ Preconditions.checkNotNull(vppIid);
+ DataBroker mountpoint = VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey();
final ReadOnlyTransaction rTx = mountpoint.newReadOnlyTransaction();
Optional<T> data;
try {
if (retryCounter > 0) {
LOG.warn("Netconf READ transaction failed to {}. Restarting transaction ... ", e.getMessage());
rTx.close();
- return read(mountpoint, datastoreType, iid, --retryCounter);
+ return read(vppIid, datastoreType, iid, --retryCounter);
} else {
LOG.warn("Netconf READ transaction unsuccessful. Maximal number of attempts reached. Trace: {}", e);
return Optional.absent();
/**
* Remove data from remote device using {@link ConfigCommand}
- *
- * @param mountpoint to access remote device
+ * @param vppIid destination node
* @param command config command with data, datastore type and iid
* @param retryCounter number of attempts
* @return true if transaction is successful, false otherwise
*/
- private static boolean deleteIfExists(final DataBroker mountpoint,
- final AbstractInterfaceCommand command,
- byte retryCounter) {
- Preconditions.checkNotNull(mountpoint);
+ private static boolean deleteIfExists(final InstanceIdentifier<Node> vppIid, final AbstractInterfaceCommand command, byte retryCounter) {
+ Preconditions.checkNotNull(vppIid);
InstanceIdentifier<Interface> iid = VppIidFactory.getInterfaceIID(command.getInterfaceBuilder().getKey());
- return deleteIfExists(mountpoint, iid, retryCounter);
- }
-
- /**
- * Remove data from remote device using {@link ConfigCommand}
- *
- * @param mountpoint to access remote device
- * @param command config command with data, datastore type and iid
- * @param retryCounter number of attempts
- * @return true if transaction is successful, false otherwise
- */
- private static boolean deleteIfExists(final DataBroker mountpoint, final AbstractConfigCommand command,
- byte retryCounter) {
- Preconditions.checkNotNull(mountpoint);
-
- return deleteIfExists(mountpoint, command.getIid(), retryCounter);
+ return deleteIfExists(vppIid, iid, retryCounter);
}
/**
* Remove data from remote device. Data presence is verified before removal. Transaction is restarted if failed.
- *
- * @param mountpoint to access remote device
+ * @param vppIid destination node
* @param iid data identifier
* @param retryCounter number of attempts
* @param <T> generic data type. Has to be child of {@link DataObject}
* @return true if transaction is successful, false otherwise
*/
- private static <T extends DataObject> boolean deleteIfExists(final DataBroker mountpoint,
+ private static <T extends DataObject> boolean deleteIfExists(final InstanceIdentifier<Node> vppIid,
final InstanceIdentifier<T> iid, byte retryCounter) {
LOG.trace("Netconf DELETE transaction started. Data will be read at first. RetryCounter: {}", retryCounter);
- Preconditions.checkNotNull(mountpoint);
- final Optional<T> optionalObject = read(mountpoint, LogicalDatastoreType.CONFIGURATION, iid, RETRY_COUNT);
+ Preconditions.checkNotNull(vppIid);
+ DataBroker mountpoint = VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey();
+ final Optional<T> optionalObject = read(vppIid, LogicalDatastoreType.CONFIGURATION, iid, RETRY_COUNT);
if (!optionalObject.isPresent()) {
LOG.warn("Netconf DELETE transaction aborted. Data to remove are not present or cannot be read. Iid: {}",
iid);
// Retry
if (retryCounter > 0) {
LOG.warn("Netconf DELETE transaction failed to {}. Restarting transaction ... ", e.getMessage());
- return deleteIfExists(mountpoint, iid, --retryCounter);
+ return deleteIfExists(vppIid, iid, --retryCounter);
+ } else {
+ LOG.warn("Netconf DELETE transaction unsuccessful. Maximal number of attempts reached. Trace: {}", e);
+ return false;
+ }
+ }
+ }
+
+ private static <T extends DataObject> boolean deleteIfExists(final InstanceIdentifier<Node> vppIid,
+ final Set<InstanceIdentifier<T>> iids, byte retryCounter) {
+ LOG.trace("Netconf DELETE transaction started. Data will be read at first. RetryCounter: {}", retryCounter);
+ Preconditions.checkNotNull(vppIid);
+ final ReadWriteTransaction rwTx = VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey().newReadWriteTransaction();
+ for (InstanceIdentifier<T> iid : iids) {
+ short microReadRetries = 3;
+ while (microReadRetries > 0) {
+ try {
+ if (rwTx.read(LogicalDatastoreType.CONFIGURATION, iid).get().isPresent()) {
+ rwTx.delete(LogicalDatastoreType.CONFIGURATION, iid);
+ } else {
+ LOG.warn("Node {} does not exist. It won't be removed.", iid.getPathArguments());
+ iids.remove(iid);
+ }
+ break;
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.warn("Failed to read {}. Retrying... ", iid.getPathArguments());
+ microReadRetries--;
+ }
+ }
+ }
+ try {
+ final CheckedFuture<Void, TransactionCommitFailedException> futureTask = rwTx.submit();
+ futureTask.get();
+ LOG.trace("Netconf DELETE transaction done for {}", iids);
+ return true;
+ } catch (Exception e) {
+ // Retry
+ if (retryCounter > 0) {
+ LOG.warn("Netconf DELETE transaction failed to {}. Restarting transaction ... ", e.getMessage());
+ return deleteIfExists(vppIid, iids, --retryCounter);
} else {
LOG.warn("Netconf DELETE transaction unsuccessful. Maximal number of attempts reached. Trace: {}", e);
return false;
*/
package org.opendaylight.groupbasedpolicy.renderer.vpp.util;
-import com.google.common.base.Optional;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import java.util.List;
+
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
+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;
-import java.util.List;
+import com.google.common.base.Optional;
/**
* Created by Shakib Ahmed on 7/18/17.
*/
public class InterfaceUtil {
- public static List<Interface> getOperationalInterfaces(DataBroker vppDataBroker) {
- final Optional<InterfacesState> opInterfaceState = GbpNetconfTransaction.read(vppDataBroker,
- LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(InterfacesState.class),
- GbpNetconfTransaction.RETRY_COUNT);
+ public static List<Interface> getOperationalInterfaces(InstanceIdentifier<Node> nodeIid) {
+ final Optional<InterfacesState> opInterfaceState =
+ GbpNetconfTransaction.read(nodeIid, LogicalDatastoreType.OPERATIONAL,
+ InstanceIdentifier.create(InterfacesState.class), GbpNetconfTransaction.RETRY_COUNT);
if (!opInterfaceState.isPresent()) {
return null;
package org.opendaylight.groupbasedpolicy.renderer.vpp.util;
+import java.security.InvalidParameterException;
+
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.lisp.dom.EidDom;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.lisp.dom.HmacKeyDom;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.HmacKeyType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.Eid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.hmac.key.grouping.HmacKey;
+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;
-import java.security.InvalidParameterException;
+import com.google.common.base.Function;
/**
* Created by Shakib Ahmed on 3/21/17.
}
+ public static Function<String, InstanceIdentifier<Node>> HOSTNAME_TO_IID = host -> {
+ return VppIidFactory.getNetconfNodeIid(new NodeId(host));
+ };
+
public static Eid toEid(Address address, long vni, Class<? extends LispAddressFamily> addressType) {
EidDom eidDom = new EidDom();
eidDom.setAddress(address);
package org.opendaylight.groupbasedpolicy.renderer.vpp.util;
-import javax.annotation.Nonnull;
+import java.util.AbstractMap;
+import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.SettableFuture;
+import java.util.concurrent.locks.ReentrantLock;
+
+import javax.annotation.Nonnull;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.MountPoint;
import org.opendaylight.controller.md.sal.binding.api.MountPointService;
+import org.opendaylight.vbd.impl.transaction.VbdNetconfTransaction;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.SettableFuture;
+
public class MountedDataBrokerProvider {
private static final Logger LOG = LoggerFactory.getLogger(MountedDataBrokerProvider.class);
+ private static final short DURATION = 3000;
private final MountPointService mountService;
private final DataBroker dataBroker;
@SuppressWarnings("FieldCanBeLocal")
this.dataBroker = Preconditions.checkNotNull(dataBroker);
}
- public Optional<DataBroker> getDataBrokerForMountPoint(@Nonnull InstanceIdentifier<?> iidToMountPoint) {
+ public Optional<DataBroker> resolveDataBrokerForMountPoint(@Nonnull InstanceIdentifier<Node> iidToMountPoint) {
try {
+ if (VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(iidToMountPoint) != null) {
+ return Optional.of(VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(iidToMountPoint).getKey());
+ }
final SettableFuture<Boolean> futureNodeStatus = SettableFuture.create();
final NodeKey nodeKey = iidToMountPoint.firstKeyOf(Node.class);
new GbpVppNetconfConnectionProbe(nodeKey, futureNodeStatus, dataBroker);
if (futureNodeStatus.get(NODE_CONNECTION_TIMER, TimeUnit.SECONDS)) {
LOG.debug("Node connected, mountpoint with iid {} available", iidToMountPoint);
- Optional<MountPoint> potentialMountPoint = mountService.getMountPoint(iidToMountPoint);
+ Future<Optional<MountPoint>> mountPointfuture = getMountpointFromSal(iidToMountPoint);
+ Optional<MountPoint> potentialMountPoint = mountPointfuture.get();
if (potentialMountPoint.isPresent()) {
- return potentialMountPoint.get().getService(DataBroker.class);
+ final Optional<DataBroker> dataBrokerOpt = potentialMountPoint.get().getService(DataBroker.class);
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.put(iidToMountPoint,
+ new AbstractMap.SimpleEntry(dataBrokerOpt.get(), new ReentrantLock()));
+ LOG.info("Lock created for {}", iidToMountPoint);
+ return dataBrokerOpt;
} else {
LOG.warn("Mount point does not exist for {}", iidToMountPoint);
return Optional.absent();
}
} catch (TimeoutException e) {
LOG.warn("Mountpoint not obtained within {} seconds. Iid: {}", NODE_CONNECTION_TIMER, iidToMountPoint, e);
- return Optional.absent();
+ return null;
} catch (ExecutionException | InterruptedException e) {
LOG.warn("Error while getting mountpoint. Iid: {}", iidToMountPoint, e);
- return Optional.absent();
+ return null;
}
}
+
+ // TODO bug 7699
+ // This works as a workaround for mountpoint registration in cluster. If application is registered on different
+ // node as netconf service, it obtains mountpoint registered by SlaveSalFacade (instead of MasterSalFacade). However
+ // this service registers mountpoint a moment later then connectionStatus is set to "Connected". If NodeManager hits
+ // state where device is connected but mountpoint is not yet available, try to get it again in a while
+ private Future<Optional<MountPoint>> getMountpointFromSal(final InstanceIdentifier<Node> iid) {
+ final ExecutorService executorService = Executors.newSingleThreadExecutor();
+ final Callable<Optional<MountPoint>> task = () -> {
+ byte attempt = 0;
+ do {
+ try {
+ final Optional<MountPoint> optionalMountpoint = mountService.getMountPoint(iid);
+ if (optionalMountpoint.isPresent()) {
+ return optionalMountpoint;
+ }
+ LOG.warn("Mountpoint {} is not registered yet", iid);
+ Thread.sleep(DURATION);
+ } catch (InterruptedException e) {
+ LOG.warn("Thread interrupted to ", e);
+ }
+ attempt++;
+ } while (attempt <= 3);
+ return Optional.absent();
+ };
+ return executorService.submit(task);
+ }
}
.build();
}
+ public static InstanceIdentifier<Acl> getVppAcl(AclKey aclKey) {
+ return InstanceIdentifier.builder(AccessLists.class).child(Acl.class, aclKey).build();
+ }
+
public static InstanceIdentifier<Acl> getVppAcl(String aclName) {
return InstanceIdentifier.builder(AccessLists.class)
.child(Acl.class, new AclKey(aclName, VppAcl.class))
.setOperation(General.Operations.PUT)\r
.setInterfaceName(INTERFACE_NAME)\r
.setDescription(DESCRIPTION)\r
- .setBvi(IS_BVI)\r
+ .setBvi(true)\r
.setPhysAddress(MAC_ADDRESS)\r
.setIpPrefix(IP_PREFIX)\r
.setIpAddress(IP_ADDRESS)\r
\r
Assert.assertTrue(optional.isPresent());\r
Assert.assertEquals(BASIC_INTERFACE_WITH_BD, optional.get());\r
-\r
}\r
\r
private Optional<Interface> executeCommand(ReadWriteTransaction rwTx, LoopbackCommand addCommand)\r
package org.opendaylight.groupbasedpolicy.renderer.vpp.dhcp;
-import com.google.common.base.Optional;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.SetMultimap;
+import java.util.AbstractMap;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.locks.ReentrantLock;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.vbd.impl.transaction.VbdNetconfTransaction;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
+import com.google.common.base.Optional;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.SetMultimap;
public class DhcpRelayHandlerTest extends VppRendererDataBrokerTest {
public void init() throws ExecutionException, InterruptedException {
dataBroker = getDataBroker();
mountedDataProviderMock = Mockito.mock(MountedDataBrokerProvider.class);
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.put(VppIidFactory.getNetconfNodeIid(TEST_NODE),
+ new AbstractMap.SimpleEntry<DataBroker,ReentrantLock>(dataBroker, new ReentrantLock()));
vppNodesByL2Fd.put(TEST_BD, TEST_NODE);
- Mockito.when(mountedDataProviderMock.getDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
+ Mockito.when(mountedDataProviderMock.resolveDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
.thenReturn(Optional.of(dataBroker));
writeBasicDhcpVppEp();
}
package org.opendaylight.groupbasedpolicy.renderer.vpp.iface;
+import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
+import java.util.concurrent.locks.ReentrantLock;
import org.junit.Assert;
import org.junit.Before;
import org.opendaylight.groupbasedpolicy.renderer.vpp.event.VppEndpointConfEvent;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.flat.overlay.FlatOverlayManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
import org.opendaylight.groupbasedpolicy.test.CustomDataBrokerTest;
import org.opendaylight.groupbasedpolicy.util.IidFactory;
+import org.opendaylight.vbd.impl.transaction.VbdNetconfTransaction;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
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.InterfaceKey;
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.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.BridgeDomains;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VhostUser;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VhostUserRole;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.BridgeDomains;
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.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
mountPointDataBroker = getDataBroker();
setup(); // initialize new data broker for ODL data store
dataBroker = getDataBroker();
- Mockito.when(mountedDataProviderMock.getDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
+ Mockito.when(mountedDataProviderMock.resolveDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
.thenReturn(Optional.of(mountPointDataBroker));
manager = new InterfaceManager(mountedDataProviderMock, dataBroker, flatOverlayManager);
}
wTx.submit().get();
VppEndpoint vhostEp = vhostVppEpBuilder().build();
VppEndpointConfEvent event = new VppEndpointConfEvent(BASIC_VPP_EP_IID, null, vhostEp);
-
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.put(VppIidFactory.getNetconfNodeIid(vhostEp.getVppNodeId()),
+ new AbstractMap.SimpleEntry(mountPointDataBroker, new ReentrantLock()));
manager.vppEndpointChanged(event);
// assert state on data store behind mount point
ReadOnlyTransaction rTxMount = mountPointDataBroker.newReadOnlyTransaction();
VppEndpoint vhostEp = vhostVppEpBuilder().build();
VppEndpointConfEvent createVppEpEvent = new VppEndpointConfEvent(BASIC_VPP_EP_IID, null, vhostEp);
VppEndpointConfEvent deleteVppEpEvent = new VppEndpointConfEvent(BASIC_VPP_EP_IID, vhostEp, null);
-
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.put(VppIidFactory.getNetconfNodeIid(vhostEp.getVppNodeId()),
+ new AbstractMap.SimpleEntry(mountPointDataBroker, new ReentrantLock()));
manager.vppEndpointChanged(createVppEpEvent);
manager.vppEndpointChanged(deleteVppEpEvent);
// assert state on data store behind mount point
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import org.junit.After;
import org.junit.Assert;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
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.ReadFailedException;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.groupbasedpolicy.renderer.vpp.VppRendererDataBrokerTest;
import org.opendaylight.groupbasedpolicy.renderer.vpp.listener.VppNodeListener;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import com.google.common.base.Optional;
import com.google.common.eventbus.EventBus;
-import com.google.common.util.concurrent.CheckedFuture;
/**
* Test for {@link VppNodeManager} and {@link VppNodeListener}.
@Test
public void connectNode() throws Exception {
- WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
- Node testVppNode = createNode(NODE_NAME, NetconfNodeConnectionStatus.ConnectionStatus.Connected);
-
- writeTransaction.put(LogicalDatastoreType.OPERATIONAL, NODE_IID, testVppNode, true);
-
- writeTransaction.submit().get();
-
- ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();
- CheckedFuture<Optional<Renderer>, ReadFailedException> future =
- readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL,
- VppIidFactory.getRendererIID(new RendererKey(VppRenderer.NAME)));
- Optional<Renderer> rendererOptional = future.checkedGet();
-
- Assert.assertTrue(rendererOptional.isPresent());
- Assert.assertEquals(1, rendererOptional.get().getRendererNodes().getRendererNode().size());
- Assert.assertEquals(NODE_IID, rendererOptional.get().getRendererNodes().getRendererNode().get(0).getNodePath());
+ final ExecutorService executorService = Executors.newFixedThreadPool(2);
+ executorService.submit(() -> {
+ WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
+ Node testVppNode = createNode(NODE_NAME, NetconfNodeConnectionStatus.ConnectionStatus.Connected);
+
+ writeTransaction.put(LogicalDatastoreType.OPERATIONAL, NODE_IID, testVppNode, true);
+
+ DataStoreHelper.submitToDs(writeTransaction);
+
+ ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();
+ Optional<Renderer> rendererOptional = DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL,
+ VppIidFactory.getRendererIID(new RendererKey(VppRenderer.NAME)), readOnlyTransaction);
+ Assert.assertTrue(rendererOptional.isPresent());
+ Assert.assertEquals(1, rendererOptional.get().getRendererNodes().getRendererNode().size());
+ Assert.assertEquals(NODE_IID,
+ rendererOptional.get().getRendererNodes().getRendererNode().get(0).getNodePath());
+ });
}
@Test
public void disconnectNode() throws Exception {
- WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
+ final ExecutorService executorService = Executors.newFixedThreadPool(2);
+ executorService.submit(() -> {
+ WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
Node testVppNode = createNode(NODE_NAME, NetconfNodeConnectionStatus.ConnectionStatus.Connected);
- writeTransaction.put(LogicalDatastoreType.OPERATIONAL, NODE_IID, testVppNode, true);
+ wTx.put(LogicalDatastoreType.OPERATIONAL, NODE_IID, testVppNode, true);
- writeTransaction.submit().get();
-
- ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();
- CheckedFuture<Optional<Renderer>, ReadFailedException> future =
- readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL,
- VppIidFactory.getRendererIID(new RendererKey(VppRenderer.NAME)));
- Optional<Renderer> rendererOptional = future.checkedGet();
+ DataStoreHelper.submitToDs(wTx);
+ ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
+ Optional<Renderer> rendererOptional = DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL,
+ VppIidFactory.getRendererIID(new RendererKey(VppRenderer.NAME)), tx);
+ tx.close();
Assert.assertTrue(rendererOptional.isPresent());
Assert.assertEquals(1, rendererOptional.get().getRendererNodes().getRendererNode().size());
Assert.assertEquals(NODE_IID, rendererOptional.get().getRendererNodes().getRendererNode().get(0).getNodePath());
writeTransaction2.submit();
- ReadOnlyTransaction readOnlyTransaction2 = dataBroker.newReadOnlyTransaction();
- CheckedFuture<Optional<Renderer>, ReadFailedException> future2 =
- readOnlyTransaction2.read(LogicalDatastoreType.OPERATIONAL,
- VppIidFactory.getRendererIID(new RendererKey(VppRenderer.NAME)));
- Optional<Renderer> rendererOptional2 = future2.checkedGet();
-
+ tx = dataBroker.newReadOnlyTransaction();
+ Optional<Renderer> rendererOptional2 = DataStoreHelper.readFromDs(LogicalDatastoreType.OPERATIONAL,
+ VppIidFactory.getRendererIID(new RendererKey(VppRenderer.NAME)), tx);
Assert.assertTrue(rendererOptional2.isPresent());
+ tx.close();
Assert.assertEquals(0, rendererOptional2.get().getRendererNodes().getRendererNode().size());
+ });
}
@After
import org.opendaylight.groupbasedpolicy.renderer.vpp.dhcp.DhcpRelayHandler;
import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.InterfaceManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.LispStateManager;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.loopback.LoopbackManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.flat.overlay.FlatOverlayManager;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.loopback.LoopbackManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.nat.NatManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl.AccessListWrapper;
import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl.AclManager;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.Configuration;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.RendererEndpoint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.renderer.endpoints.RendererEndpointKey;
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.NetworkTypeBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.VlanNetwork;
fwdManager =
new ForwardingManager(ifaceManager, aclManager, natManager, routingManager, bdManager, lispStateManager,
loopbackManager, flatOverlayManager, dhcpRelayHandler, getDataBroker());
+ Mockito.when(aclManager.resolveAclsOnInterface(Mockito.any(RendererEndpointKey.class),
+ Mockito.any(PolicyContext.class)))
+ .thenReturn(Futures.immediateFuture(null));
}
@Override
package org.opendaylight.groupbasedpolicy.renderer.vpp.policy;
+import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import org.junit.Assert;
import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.InterfaceManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.VppEndpointLocationProvider;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.LispStateManager;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.loopback.LoopbackManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.flat.overlay.FlatOverlayManager;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.loopback.LoopbackManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.nat.NatManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl.AclManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.routing.RoutingManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
import org.opendaylight.groupbasedpolicy.test.CustomDataBrokerTest;
import org.opendaylight.groupbasedpolicy.util.IidFactory;
+import org.opendaylight.vbd.impl.transaction.VbdNetconfTransaction;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160708.AccessLists;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
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.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpointKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.BridgeDomains;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VppInterfaceAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.VxlanVni;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.interfaces._interface.L2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.Interconnection;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.l2.config.attributes.interconnection.BridgeBased;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.BridgeDomains;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.acl.rev161214.VppAclInterfaceAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.topology.rev160129.TopologyVbridgeAugment;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.tunnel.vxlan.rev170327.TunnelTypeVxlan;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.tunnel.vxlan.rev170327.network.topology.topology.tunnel.parameters.VxlanTunnelParameters;
mountPointDataBroker = getDataBroker();
setup(); // initialize new data broker for ODL data store
dataBroker = getDataBroker();
- Mockito.when(mountedDataProviderMock.getDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
+ Mockito.when(mountedDataProviderMock.resolveDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
.thenReturn(Optional.of(mountPointDataBroker));
lispStateManager = new LispStateManager(mountedDataProviderMock);
loopbackManager = new LoopbackManager(mountedDataProviderMock);
flatOverlayManager = new FlatOverlayManager(dataBroker, mountedDataProviderMock);
ifaceManager = new InterfaceManager(mountedDataProviderMock, dataBroker, flatOverlayManager);
- aclManager = new AclManager(mountedDataProviderMock);
+ aclManager = new AclManager(mountedDataProviderMock, ifaceManager);
natManager = new NatManager(dataBroker, mountedDataProviderMock);
routingManager = new RoutingManager(dataBroker, mountedDataProviderMock);
bdManager = new BridgeDomainManagerImpl(mountPointDataBroker);
lispStateManager, loopbackManager, flatOverlayManager, dhcpRelayHandler, dataBroker);
vppRendererPolicyManager = new VppRendererPolicyManager(fwManager, aclManager, dataBroker);
fwManager.setTimer((byte) 1);
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.put(DtoFactory.VPP_NODE_1_IID,
+ new AbstractMap.SimpleEntry(mountPointDataBroker, new ReentrantLock()));
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.put(DtoFactory.VPP_NODE_2_IID,
+ new AbstractMap.SimpleEntry(mountPointDataBroker, new ReentrantLock()));
}
@Test
import org.junit.Test;
import org.mockito.Mockito;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.InterfaceManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.PolicyContext;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
ctx = super.createPolicyContext();
mountedDataProviderMock = Mockito.mock(MountedDataBrokerProvider.class);
mountPointDataBroker = Mockito.mock(DataBroker.class);
- Mockito.when(mountedDataProviderMock.getDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
+ Mockito.when(mountedDataProviderMock.resolveDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
.thenReturn(Optional.of(mountPointDataBroker));
}
@Test
- public void resolveAclsOnInterfaceTest() {
+ public void resolveAclsOnInterfaceTest() throws Exception {
// TODO add more checking
- AclManager aclManager = new AclManager(mountedDataProviderMock);
+ AclManager aclManager = new AclManager(mountedDataProviderMock, Mockito.mock(InterfaceManager.class));
List<AccessListWrapper> acls =
- aclManager.resolveAclsOnInterface(rendererEndpoint(l2AddrEp2).build().getKey(), ctx);
+ aclManager.resolveAclsOnInterface(rendererEndpoint(l2AddrEp2).build().getKey(), ctx).get();
Assert.assertEquals(2, acls.size());
Assert.assertEquals(2, acls.stream().map(AccessListWrapper::getDirection).collect(Collectors.toSet()).size());
acls.stream().forEach(ace -> {
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
+import java.util.AbstractMap;
+import java.util.concurrent.locks.ReentrantLock;
+
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.AbstractInterfaceCommand;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.interfaces.ConfigCommand;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.LoopbackCommand;
+import org.opendaylight.vbd.impl.transaction.VbdNetconfTransaction;
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.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+
public class GbpNetconfTransactionTest {
private final String INTERFACE_KEY = "interface-key";
public void init() {
when(dataBroker.newReadOnlyTransaction()).thenReturn(rTx);
when(dataBroker.newReadWriteTransaction()).thenReturn(rwTx);
+ VbdNetconfTransaction.NODE_DATA_BROKER_MAP.put(nodeIid,
+ new AbstractMap.SimpleEntry(dataBroker, new ReentrantLock()));
}
@Test
public void writeConfigCommandReattemptTest() {
doThrow(new IllegalStateException()).when(command).execute(rwTx);
- final boolean result = GbpNetconfTransaction.netconfSyncedWrite(dataBroker, command, (byte) 5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedWrite(nodeIid, command, (byte) 5);
verify(dataBroker, times(6)).newReadWriteTransaction();
assertFalse(result);
}
doNothing().when(command).execute(rwTx);
when(future.get()).thenReturn(null);
- final boolean result = GbpNetconfTransaction.netconfSyncedWrite(dataBroker, command, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedWrite(nodeIid, command, (byte)5);
verify(dataBroker, times(1)).newReadWriteTransaction();
assertTrue(result);
}
public void writeDataReattemptTest() {
doThrow(new IllegalStateException()).when(rwTx).put(LogicalDatastoreType.CONFIGURATION, nodeIid, node, true);
- final boolean result = GbpNetconfTransaction.netconfSyncedWrite(dataBroker, nodeIid, node, (byte) 5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedWrite(nodeIid, nodeIid, node, (byte) 5);
verify(dataBroker, times(6)).newReadWriteTransaction();
assertFalse(result);
}
doNothing().when(rwTx).put(LogicalDatastoreType.CONFIGURATION, nodeIid, node, true);
when(future.get()).thenReturn(null);
- final boolean result = GbpNetconfTransaction.netconfSyncedWrite(dataBroker, nodeIid, node, (byte) 5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedWrite(nodeIid, nodeIid, node, (byte) 5);
verify(dataBroker, times(1)).newReadWriteTransaction();
assertTrue(result);
}
public void readDataReattemptTest() {
doThrow(new IllegalStateException()).when(rTx).read(LogicalDatastoreType.CONFIGURATION, nodeIid);
- final Optional<Node> result = GbpNetconfTransaction.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ final Optional<Node> result = GbpNetconfTransaction.read(nodeIid, LogicalDatastoreType.CONFIGURATION,
nodeIid, (byte)5);
verify(dataBroker, times(6)).newReadOnlyTransaction();
assertFalse(result.isPresent());
when(futureNode.get()).thenReturn(Optional.of(new NodeBuilder()
.setKey(new NodeKey(new NodeId(NODE_ID))).build()));
- final Optional<Node> result = GbpNetconfTransaction.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ final Optional<Node> result = GbpNetconfTransaction.read(nodeIid, LogicalDatastoreType.CONFIGURATION,
nodeIid, (byte)5);
verify(dataBroker, times(1)).newReadOnlyTransaction();
assertTrue(result.isPresent());
public void deleteConfigCommandMissingDataTest() throws Exception {
final InstanceIdentifier<Interface> iid = VppIidFactory.getInterfaceIID(interfaceBuilder.getKey());
when(command.getInterfaceBuilder()).thenReturn(interfaceBuilder);
+ when(command.getIid()).thenReturn(iid);
when(rTx.read(LogicalDatastoreType.CONFIGURATION, iid)).thenReturn(futureInterface);
when(futureInterface.get()).thenReturn(Optional.absent());
doThrow(new IllegalStateException()).when(command).execute(rwTx);
- final boolean result = GbpNetconfTransaction.netconfSyncedDelete(dataBroker, command, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedDelete(nodeIid, command, (byte)5);
verify(dataBroker, times(1)).newReadOnlyTransaction();
assertTrue(result);
}
public void deleteConfigCommandReattemptTest() throws Exception {
final InstanceIdentifier<Interface> iid = VppIidFactory.getInterfaceIID(interfaceBuilder.getKey());
when(command.getInterfaceBuilder()).thenReturn(interfaceBuilder);
+ when(command.getIid()).thenReturn(iid);
when(rTx.read(LogicalDatastoreType.CONFIGURATION, iid)).thenReturn(futureInterface);
when(futureInterface.get()).thenReturn(Optional.of(new InterfaceBuilder()
.setKey(new InterfaceKey(INTERFACE_KEY)).build()));
doThrow(new IllegalStateException()).when(command).execute(rwTx);
-
- final boolean result = GbpNetconfTransaction.netconfSyncedDelete(dataBroker, command, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedDelete(nodeIid, command, (byte)5);
verify(dataBroker, times(6)).newReadWriteTransaction();
assertFalse(result);
}
public void deleteConfigCommandTest() throws Exception {
final InstanceIdentifier<Interface> iid = VppIidFactory.getInterfaceIID(interfaceBuilder.getKey());
when(command.getInterfaceBuilder()).thenReturn(interfaceBuilder);
+ when(command.getIid()).thenReturn(iid);
when(rTx.read(LogicalDatastoreType.CONFIGURATION, iid)).thenReturn(futureInterface);
when(futureInterface.get()).thenReturn(Optional.of(new InterfaceBuilder()
.setKey(new InterfaceKey(INTERFACE_KEY)).build()));
doNothing().when(command).execute(rwTx);
when(future.get()).thenReturn(null);
- final boolean result = GbpNetconfTransaction.netconfSyncedDelete(dataBroker, command, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedDelete(nodeIid, command, (byte)5);
verify(dataBroker, times(1)).newReadWriteTransaction();
assertTrue(result);
}
when(futureNode.get()).thenReturn(Optional.absent());
doThrow(new IllegalStateException()).when(command).execute(rwTx);
- final boolean result = GbpNetconfTransaction.netconfSyncedDelete(dataBroker, nodeIid, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedDelete(nodeIid, nodeIid, (byte)5);
verify(dataBroker, times(1)).newReadOnlyTransaction();
assertTrue(result);
}
.setKey(new NodeKey(new NodeId(NODE_ID))).build()));
doThrow(new IllegalStateException()).when(rwTx).delete(LogicalDatastoreType.CONFIGURATION, nodeIid);
- final boolean result = GbpNetconfTransaction.netconfSyncedDelete(dataBroker, nodeIid, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedDelete(nodeIid, nodeIid, (byte)5);
verify(dataBroker, times(6)).newReadWriteTransaction();
assertFalse(result);
}
doNothing().when(rwTx).delete(LogicalDatastoreType.CONFIGURATION, nodeIid);
when(future.get()).thenReturn(null);
- final boolean result = GbpNetconfTransaction.netconfSyncedDelete(dataBroker, nodeIid, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedDelete(nodeIid, nodeIid, (byte)5);
verify(dataBroker, times(1)).newReadWriteTransaction();
assertTrue(result);
}