EventBus dtoEventBus = new EventBus((exception, context) -> LOG.error("Could not dispatch event: {} to {}",
context.getSubscriber(), context.getSubscriberMethod(), exception));
- interfaceManager = new InterfaceManager(mountDataProvider, dataBroker);
- AclManager aclManager = new AclManager(mountDataProvider);
- NatManager natManager = new NatManager(dataBroker, mountDataProvider);
LispStateManager lispStateManager = new LispStateManager(mountDataProvider);
FlatOverlayManager flatOverlayManager = new FlatOverlayManager(dataBroker, mountDataProvider);
LoopbackManager loopbackManager = new LoopbackManager(mountDataProvider);
+
+ interfaceManager = new InterfaceManager(mountDataProvider, dataBroker, flatOverlayManager);
+ AclManager aclManager = new AclManager(mountDataProvider);
+ NatManager natManager = new NatManager(dataBroker, mountDataProvider);
subnetEventManager = new GbpSubnetEventManager(loopbackManager);
dtoEventBus.register(interfaceManager);
dtoEventBus.register(subnetEventManager);
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.lisp.flat.overlay.FlatOverlayManager;
import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl.AccessListWrapper;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General.Operations;
private final MountedDataBrokerProvider mountDataProvider;
private final VppEndpointLocationProvider vppEndpointLocationProvider;
private final SetMultimap<NodeId, String> excludedFromPolicy = HashMultimap.create();
+ private final FlatOverlayManager flatOverlayManager;
- public InterfaceManager(@Nonnull MountedDataBrokerProvider mountDataProvider, @Nonnull DataBroker dataProvider) {
+ public InterfaceManager(@Nonnull MountedDataBrokerProvider mountDataProvider, @Nonnull DataBroker dataProvider,
+ FlatOverlayManager flatOverlayManager) {
this.mountDataProvider = Preconditions.checkNotNull(mountDataProvider);
this.vppEndpointLocationProvider = new VppEndpointLocationProvider(dataProvider);
+ this.flatOverlayManager = flatOverlayManager;
}
@Subscribe
}
}
+
if (!potentialIfaceCommand.isPresent()) {
LOG.debug("Interface/DELETE command was not created for VppEndpoint point {}", vppEndpoint);
return Futures.immediateFuture(null);
return Futures.immediateFailedFuture(new VppRendererProcessingException(message));
}
DataBroker vppDataBroker = potentialVppDataProvider.get();
+
+ if (ConfigUtil.getInstance().isL3FlatEnabled()) {
+ flatOverlayManager.handleInterfaceDeleteForFlatOverlay(vppDataBroker, vppEndpoint);
+ }
+
return deleteIfaceOnVpp(ifaceWithoutBdCommand, vppDataBroker, vppEndpoint, vppNodeIid);
}
+++ /dev/null
-/*
- * Copyright (c) 2017 Cisco Systems. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
-
-/**
- * Created by Shakib Ahmed on 6/23/17.
- */
-public class InterfaceInfo {
- private String interfaceName;
- private IpAddress interfaceIp;
-
- public InterfaceInfo(String interfaceName, IpAddress interfaceIp) {
- this.interfaceName = interfaceName;
- this.interfaceIp = interfaceIp;
- }
-
- public String getInterfaceName() {
- return interfaceName;
- }
-
- public IpAddress getInterfaceIp() {
- return interfaceIp;
- }
-}
import org.opendaylight.groupbasedpolicy.renderer.vpp.config.ConfigUtil;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.exception.LispConfigCommandFailedException;
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.mappers.NeutronTenantToVniMapper;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.util.ConfigManagerHelper;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.util.Constants;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
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.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
-import java.util.HashMap;
import java.util.concurrent.ExecutionException;
/**
public class LispStateManager {
private static final Logger LOG = LoggerFactory.getLogger(LispStateManager.class);
- private HashMap<String, LispState> lispStateMapper;
+ private HostRelatedInfoContainer hostRelatedInfoContainer;
private MountedDataBrokerProvider mountedDataBrokerProvider;
private ConfigManagerHelper lispStateHelper;
private static final short DEFAULT_WEIGHT = 1;
public static final String DEFAULT_XTR_KEY = "admin";
public static final String DEFAULT_LOCATOR_SET_NAME_PREFIX = "LS";
- public static final String DEFAULT_MAPPINGRECORD_NAME_PREFIX = "MR";
+ public static final String DEFAULT_MAPPINGRECORD_NAME_PREFIX = "MR_";
public LispStateManager(@Nonnull MountedDataBrokerProvider mountedDataBrokerProvider) {
Preconditions.checkNotNull(mountedDataBrokerProvider,
"MountedDataBrokerProvider found to be null!");
- lispStateMapper = new HashMap<>();
+ hostRelatedInfoContainer = HostRelatedInfoContainer.getInstance();
this.mountedDataBrokerProvider= mountedDataBrokerProvider;
this.lispStateHelper = new ConfigManagerHelper(this.mountedDataBrokerProvider);
neutronTenantToVniMapper = NeutronTenantToVniMapper.getInstance();
}
- public synchronized void configureEndPoint(AddressEndpointWithLocation addressEp) {
+ public synchronized void processCreateEndPoint(AddressEndpointWithLocation addressEp) {
try {
if (lispStateHelper.isMetadataPort(addressEp)) {
return;
}
- DataBroker dataBroker = lispStateHelper.getPotentialExternalDataBroker(addressEp).get();
- String hostName = lispStateHelper.getHostName(addressEp).get();
- LispState lispStateOfNode = configureHostIfNeeded(hostName, dataBroker);
+ EndpointHost endpointHost = lispStateHelper.getEndpointHostInformation(addressEp);
+ LispState lispStateOfHost = configureHostIfNeeded(endpointHost);
long vni = getVni(addressEp.getTenant().getValue());
long vrf = vni;
- addVniToVrfMappingIfNeeded(dataBroker, lispStateOfNode, vni, vrf);
Eid eid = lispStateHelper.getEid(addressEp, vni);
+ String eidMappingName = lispStateHelper.constructEidMappingName(addressEp);
- if(!lispStateOfNode.eidSetContains(eid)) {
- addEidInEidTable(dataBroker, lispStateOfNode, eid);
+ addVniToVrfMappingIfNeeded(endpointHost.getHostDataBroker(), lispStateOfHost, vni, vrf);
+
+ if (lispStateHelper.getInterfaceIp(addressEp).getValue().equals(Constants.METADATA_IP)) {
+ return;
}
+ addEidOnHostIfNeeded(endpointHost, lispStateOfHost, eid, eidMappingName);
} catch (LispConfigCommandFailedException e) {
LOG.warn("Lisp endpoint configuration failed for address endpoint: {}", addressEp);
}
}
- public synchronized LispState configureHostIfNeeded(String hostName, DataBroker vppDataBroker) throws LispConfigCommandFailedException {
- LispState lispStateOfNode = lispStateMapper.get(hostName);
+ private void addEidOnHostIfNeeded(EndpointHost endpointHost, LispState lispStateOfNode, Eid eid,
+ String eidMappingName)
+ throws LispConfigCommandFailedException {
+ if(!lispStateOfNode.eidSetContains(eid)) {
+ addEidInEidTable(endpointHost.getHostDataBroker(), lispStateOfNode, eid, eidMappingName);
+ }
+ }
- if (lispStateOfNode == null) {
- lispStateOfNode = new LispState(hostName);
- try {
- enableLispForNode(vppDataBroker, lispStateOfNode);
+ private synchronized LispState configureHostIfNeeded(EndpointHost endpointHost)
+ throws LispConfigCommandFailedException {
+ LispState lispStateOfHost = hostRelatedInfoContainer.getLispStateOfHost(endpointHost.getHostName());
- if (ConfigUtil.getInstance().isL3FlatEnabled()) {
- enableGpeForNode(vppDataBroker, lispStateOfNode);
- }
+ if (lispStateOfHost == null) {
+ LOG.debug("Configuring host {} for LISP", endpointHost.getHostName());
+ lispStateOfHost = new LispState();
+ try {
+ enableLispOnHost(endpointHost, lispStateOfHost);
+ enableGpeOnHostIfNeeded(endpointHost, lispStateOfHost);
+ addLocatorSetOnHost(endpointHost, lispStateOfHost);
+ addMapResolverOnHost(endpointHost, lispStateOfHost);
+ enableMapRegistrationOnHostIfNeeded(endpointHost, lispStateOfHost);
- addLocatorSet(vppDataBroker, lispStateOfNode);
- addMapResolver(vppDataBroker, lispStateOfNode);
- if (ConfigUtil.getInstance().isLispMapRegisterEnabled()) {
- enableMapRegister(vppDataBroker, lispStateOfNode);
- addMapServer(vppDataBroker, lispStateOfNode);
- }
- lispStateMapper.put(hostName, lispStateOfNode);
+ hostRelatedInfoContainer.setLispStateOfHost(endpointHost.getHostName(), lispStateOfHost);
} catch (LispNotFoundException e) {
LOG.warn("Lisp host configuration failed: ", e.getMessage());
throw new LispConfigCommandFailedException("Failed LISP configuration!");
}
}
- return lispStateOfNode;
+ return lispStateOfHost;
}
- public synchronized void deleteLispConfigurationForEndpoint(AddressEndpointWithLocation addressEp) {
- try {
- DataBroker vppDataBroker = lispStateHelper.getPotentialExternalDataBroker(addressEp).get();
- String hostName = lispStateHelper.getHostName(addressEp).get();
-
- LispState lispState = lispStateMapper.get(hostName);
-
- if (lispState == null) {
- LOG.debug("Endpoint not configured for LISP. EndPoint: {}", addressEp);
- } else {
- long vni = getVni(addressEp.getTenant().getValue());
- Eid eid = lispStateHelper.getEid(addressEp, vni);
-
- if (lispState.eidSetContains(eid)) {
- deleteEidFromEidTable(vppDataBroker, lispState, eid);
- }
+ private void enableGpeOnHostIfNeeded(EndpointHost endpointHost, LispState lispStateOfHost)
+ throws LispConfigCommandFailedException {
+ if (ConfigUtil.getInstance().isL3FlatEnabled()) {
+ enableGpeForHost(endpointHost, lispStateOfHost);
+ }
+ }
- if (lispState.eidCount() == 0) {
- deleteLispStatesInEndPoints(vppDataBroker, lispState);
- }
- }
- } catch (LispConfigCommandFailedException e) {
- LOG.warn("Lisp command execution failed: {}", e.getMessage());
+ private void enableMapRegistrationOnHostIfNeeded(EndpointHost endpointHost, LispState lispStateOfHost)
+ throws LispConfigCommandFailedException {
+ if (ConfigUtil.getInstance().isLispMapRegisterEnabled()) {
+ enableMapRegister(endpointHost);
+ addMapServer(endpointHost, lispStateOfHost);
}
}
- private void enableLispForNode(DataBroker vppDataBroker, LispState lispState) throws LispConfigCommandFailedException {
+ private void enableLispOnHost(EndpointHost endpointHost, LispState lispState)
+ throws LispConfigCommandFailedException {
AbstractLispCommand<Lisp>
lispEnableCommand = LispCommandWrapper.enableLisp();
- if (LispStateCommandExecutor.executePutCommand(vppDataBroker, lispEnableCommand)) {
+ if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), lispEnableCommand)) {
lispState.setLispEnabled(true);
} else {
throw new LispConfigCommandFailedException("Lisp Enable Command failed execution!");
}
}
- private void enableGpeForNode(DataBroker vppDataBroker, LispState lispState) throws LispConfigCommandFailedException {
+ private void enableGpeForHost(EndpointHost endpointHost, LispState lispState)
+ throws LispConfigCommandFailedException {
AbstractLispCommand<GpeFeatureData>
gpeEnableCommand = LispCommandWrapper.enableGpe();
- if (LispStateCommandExecutor.executePutCommand(vppDataBroker, gpeEnableCommand)) {
+ if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), gpeEnableCommand)) {
lispState.setGpeEnabled(true);
} else {
throw new LispConfigCommandFailedException("GPE Enable Command failed execution!");
}
}
- private void addLocatorSet(DataBroker vppDataBroker, LispState lispState) throws LispNotFoundException, LispConfigCommandFailedException {
+ private void addLocatorSetOnHost(EndpointHost endpointHost, LispState lispState)
+ throws LispNotFoundException, LispConfigCommandFailedException {
try {
String locatorSetName = lispStateHelper.constructLocatorSetName(lispState.getLocatorCount());
- String interfaceName = lispStateHelper.readRlocInterface(lispState.getHostName(), vppDataBroker).get();
+ String interfaceName = lispStateHelper
+ .readRlocInterface(endpointHost.getHostName(), endpointHost.getHostDataBroker()).get();
AbstractLispCommand<LocatorSet> addLocatorSetCommand = LispCommandWrapper.addLocatorSet(locatorSetName,
interfaceName, DEFAULT_PRIORITY, DEFAULT_WEIGHT);
- if (LispStateCommandExecutor.executePutCommand(vppDataBroker, addLocatorSetCommand)) {
+ if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), addLocatorSetCommand)) {
lispState.setLocIntfToLocSetNameMapping(interfaceName, locatorSetName);
} else {
throw new LispConfigCommandFailedException("Lisp add locator set failed for host "
- + lispState.getHostName() + " and locator interface " + interfaceName);
+ + endpointHost.getHostName() + " and locator interface " + interfaceName);
}
} catch (InterruptedException | ExecutionException e) {
throw new LispNotFoundException("No interface with Ip Address found!");
}
- private void addMapResolver(DataBroker vppDataBroker, LispState lispState) throws LispConfigCommandFailedException {
+ private void addMapResolverOnHost(EndpointHost endpointHost, LispState lispState)
+ throws LispConfigCommandFailedException {
IpAddress mapResolverIpAddress = ConfigUtil.getInstance().getOdlTenantIp();
Preconditions.checkNotNull(mapResolverIpAddress, "Map Resolver ip not properly configured!");
AbstractLispCommand<MapResolver> addMapResolverCommand = LispCommandWrapper.
addMapResolver(mapResolverIpAddress);
- if (LispStateCommandExecutor.executePutCommand(vppDataBroker, addMapResolverCommand)) {
+ if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), addMapResolverCommand)) {
lispState.addInMapResolverSet(mapResolverIpAddress);
} else {
- throw new LispConfigCommandFailedException("Lisp add map resolver for host " + lispState.getHostName()
+ throw new LispConfigCommandFailedException("Lisp add map resolver for host " + endpointHost.getHostName()
+ " failed for ODL ip " + mapResolverIpAddress);
}
}
- private void addMapServer(DataBroker vppDataBroker, LispState lispState) throws LispConfigCommandFailedException {
- IpAddress mapServerIpAddress = ConfigUtil.getInstance().getOdlTenantIp();
- Preconditions.checkNotNull(mapServerIpAddress, "Mapserver ip not properly configured!");
- AbstractLispCommand<MapServer> addMapServerCommand = LispCommandWrapper.addMapServer(mapServerIpAddress);
+ private void enableMapRegister(EndpointHost endpointHost)
+ throws LispConfigCommandFailedException {
+ AbstractLispCommand<MapRegister> enableMapRegisterCommand = LispCommandWrapper.enableMapRegister();
- if (LispStateCommandExecutor.executePutCommand(vppDataBroker, addMapServerCommand)) {
- lispState.addInMapServerSet(mapServerIpAddress);
+ if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), enableMapRegisterCommand)) {
} else {
- throw new LispConfigCommandFailedException("Lisp add map server for host " + lispState.getHostName()
- + " failed for ODL ip " + mapServerIpAddress);
+ throw new LispConfigCommandFailedException("Lisp enable mapregistration for host "
+ + endpointHost.getHostName() + " failed!");
}
+
}
- private void enableMapRegister(DataBroker vppDataBroker, LispState lispState) throws LispConfigCommandFailedException {
- AbstractLispCommand<MapRegister> enableMapRegisterCommand = LispCommandWrapper.enableMapRegister();
+ private void addMapServer(EndpointHost endpointHost, LispState lispState) throws LispConfigCommandFailedException {
+ IpAddress mapServerIpAddress = ConfigUtil.getInstance().getOdlTenantIp();
+ Preconditions.checkNotNull(mapServerIpAddress, "Mapserver ip not properly configured!");
+ AbstractLispCommand<MapServer> addMapServerCommand = LispCommandWrapper.addMapServer(mapServerIpAddress);
- if (LispStateCommandExecutor.executePutCommand(vppDataBroker, enableMapRegisterCommand)) {
- lispState.setMapRegisteredEnabled(true);
+ if (LispStateCommandExecutor.executePutCommand(endpointHost.getHostDataBroker(), addMapServerCommand)) {
+ lispState.addInMapServerSet(mapServerIpAddress);
} else {
- throw new LispConfigCommandFailedException("Lisp enable mapregistration for host "
- + lispState.getHostName() + " failed!");
+ throw new LispConfigCommandFailedException("Lisp add map server for host " + endpointHost.getHostName()
+ + " failed for ODL ip " + mapServerIpAddress);
}
-
}
private void addVniToVrfMappingIfNeeded(DataBroker vppDataBroker,
LispState lispState,
long vni, long vrf) throws LispConfigCommandFailedException {
- if (!lispState.vniSetContains(vni)) {
+ if (!lispState.isVniConfigured(vni)) {
AbstractLispCommand<VniTable> addVniToVrfMapping = LispCommandWrapper.mapVniToVrf(vni, vrf);
addVniToVrfMapping.setOptions(General.Operations.PUT);
if (LispStateCommandExecutor.executePutCommand(vppDataBroker, addVniToVrfMapping)) {
private void addEidInEidTable(DataBroker vppDataBroker,
LispState lispState,
- Eid eid) throws LispConfigCommandFailedException {
- String mappingId = lispStateHelper.constructMappingName(lispState.getInterfaceId());
+ Eid eid,
+ String eidMappingName) throws LispConfigCommandFailedException {
AbstractLispCommand<LocalMapping> addLocalMappingInEidTableCommand = LispCommandWrapper
- .addLocalMappingInEidTable(mappingId,
+ .addLocalMappingInEidTable(eidMappingName,
eid,
lispStateHelper.getFirstLocatorSetName(lispState),
lispStateHelper.getDefaultHmacKey());
if (LispStateCommandExecutor.executePutCommand(vppDataBroker, addLocalMappingInEidTableCommand)) {
- lispState.addInEidSet(eid, mappingId);
+ lispState.addEidInEidSet(eid);
} else {
throw new LispConfigCommandFailedException("Lisp add local mapping for eid " + eid + "failed!");
}
}
- private void deleteLispStatesInEndPoints(DataBroker vppDataBroker,
- LispState lispState) throws LispConfigCommandFailedException {
- AbstractLispCommand<LispFeatureData> deleteLispFeatureData = LispCommandWrapper.deleteLispFeatureData();
+ public synchronized void processDeleteEndpoint(AddressEndpointWithLocation addressEp) {
+ try {
- if (LispStateCommandExecutor.executeDeleteCommand(vppDataBroker, deleteLispFeatureData)) {
- String computeNode = lispState.getHostName();
- lispStateMapper.remove(computeNode);
- } else {
- throw new LispConfigCommandFailedException("Lisp delete feature data command failed!");
+ if (lispStateHelper.isMetadataPort(addressEp)) {
+ return;
+ }
+
+ EndpointHost endpointHost = lispStateHelper.getEndpointHostInformation(addressEp);
+
+ LispState lispState = hostRelatedInfoContainer.getLispStateOfHost(endpointHost.getHostName());
+
+ if (lispState == null) {
+ LOG.debug("Endpoint not configured for LISP. EndPoint: {}", addressEp);
+ } else {
+ long vni = getVni(addressEp.getTenant().getValue());
+ Eid eid = lispStateHelper.getEid(addressEp, vni);
+ String eidMappingName = lispStateHelper.constructEidMappingName(addressEp);
+
+ deleteEidFromLocalEidTableOfHostIfNeeded(endpointHost, lispState, eid, eidMappingName);
+
+ if (lispState.eidCount() == 0) {
+ deleteLispStatesFromHost(endpointHost);
+ }
+ }
+ } catch (LispConfigCommandFailedException e) {
+ LOG.warn("Lisp command execution failed: {}", e.getMessage());
+ }
+ }
+
+ private void deleteEidFromLocalEidTableOfHostIfNeeded(EndpointHost endpointHost, LispState lispState, Eid eid, String eidMappingName) throws LispConfigCommandFailedException {
+ if (lispState.eidSetContains(eid)) {
+ deleteEidFromLocalEidTableOfHost(endpointHost, lispState, eid, eidMappingName);
}
}
- private void deleteEidFromEidTable(DataBroker vppDataBroker,
+ private void deleteEidFromLocalEidTableOfHost(EndpointHost endpointHost,
LispState lispState,
- Eid eid) throws LispConfigCommandFailedException {
- String mappingId = lispState.getEidMapping(eid);
+ Eid eid,
+ String eidMappingName) throws LispConfigCommandFailedException {
long value = eid.getVirtualNetworkId().getValue();
AbstractLispCommand<LocalMapping> deleteLocalMappingCommand = LispCommandWrapper
- .deleteLocalMappingFromEidTable(mappingId, value);
+ .deleteLocalMappingFromEidTable(eidMappingName, value);
- if (LispStateCommandExecutor.executeDeleteCommand(vppDataBroker, deleteLocalMappingCommand)) {
+ if (LispStateCommandExecutor
+ .executeDeleteCommand(endpointHost.getHostDataBroker(), deleteLocalMappingCommand)) {
+ LOG.debug("Successfully deleted eid {} from host {}", eid, endpointHost.getHostName());
lispState.deleteEid(eid);
} else {
throw new LispConfigCommandFailedException("Lisp delete local mapping command failed!");
}
}
+
+ private void deleteLispStatesFromHost(EndpointHost endpointHost) throws LispConfigCommandFailedException {
+ AbstractLispCommand<LispFeatureData> deleteLispFeatureData = LispCommandWrapper.deleteLispFeatureData();
+
+ if (LispStateCommandExecutor.executeDeleteCommand(endpointHost.getHostDataBroker(), deleteLispFeatureData)) {
+ hostRelatedInfoContainer.deleteLispStateOfHost(endpointHost.getHostName());
+ LOG.debug("Deleted all lisp data for host {}", endpointHost.getHostName());
+ } else {
+ throw new LispConfigCommandFailedException("Lisp delete feature data command failed!");
+ }
+ }
+
private long getVni(String tenantUuid) {
return neutronTenantToVniMapper.getVni(tenantUuid);
}
private void processSubnetDeleted(String subnetUuid) {
subnetUuidToGbpSubnetInfoMapper.removeSubnetInfo(subnetUuid);
- loopbackManager.deleteLoopbackIfExists(subnetUuid);
}
}
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.mappers.HostIdToMetadataInterfaceMapper;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers.HostVrfRoutingInformationMapper;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers.InterfaceNameToStaticInfoMapper;
+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.PortInterfaces;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.PortRouteState;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.SubnetState;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.VrfHolder;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.VrfState;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers.NeutronTenantToVniMapper;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.util.ConfigManagerHelper;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.util.Constants;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
private DataBroker dataBroker;
private NeutronTenantToVniMapper neutronTenantToVniMapper = NeutronTenantToVniMapper.getInstance();
- private HostVrfRoutingInformationMapper hostVrfInfo = HostVrfRoutingInformationMapper.getInstance();
- private HostIdToMetadataInterfaceMapper
- hostIdToMetadataInterfaceMapper = HostIdToMetadataInterfaceMapper.getInstance();
-
- private InterfaceNameToStaticInfoMapper interfaceNameToStaticInfoMapper;
+ private HostRelatedInfoContainer hostRelatedInfoContainer = HostRelatedInfoContainer.getInstance();
private StaticRoutingHelper staticRoutingHelper;
- public FlatOverlayManager(@Nonnull DataBroker dataBroker, @Nonnull MountedDataBrokerProvider mountedDataBrokerProvider) {
+ public FlatOverlayManager(@Nonnull DataBroker dataBroker,
+ @Nonnull MountedDataBrokerProvider mountedDataBrokerProvider) {
this.overlayHelper = new ConfigManagerHelper(mountedDataBrokerProvider);
- this.interfaceNameToStaticInfoMapper = InterfaceNameToStaticInfoMapper.getInstance();
- staticRoutingHelper = new StaticRoutingHelper(interfaceNameToStaticInfoMapper);
+ staticRoutingHelper = new StaticRoutingHelper();
this.dataBroker = dataBroker;
}
public void configureEndpointForFlatOverlay(AddressEndpointWithLocation addressEp) {
- if (!overlayHelper.isMetadataPort(addressEp)) {
+ if (!overlayHelper.hasRelativeLocations(addressEp)) {
configureInterfaceForFlatOverlay(addressEp);
addStaticArp(addressEp);
addStaticRoute(addressEp);
long vrf = getVni(addressEp.getTenant().getValue());
- if (!hostIdToMetadataInterfaceMapper.isMetadataInterfaceConfigured(hostName, metadataInterfaceName)) {
+ String metadataSubnetUuid = Constants.METADATA_SUBNET_UUID;
+
+ PortInterfaces portInterfacesOfHost = hostRelatedInfoContainer.getPortInterfaceStateOfHost(hostName);
+
+ if (!portInterfacesOfHost.isInterfaceConfiguredForMetadata(metadataInterfaceName)) {
DataBroker vppDataBroker = overlayHelper.getPotentialExternalDataBroker(externalLocation).get();
- addInterfaceInVrf(vppDataBroker, metadataInterfaceName, vrf);
+ addInterfaceInVrf(new EndpointHost(vppDataBroker, hostName), metadataInterfaceName, vrf);
String physicalAddress = resolvePhysicalAddress(hostName, metadataInterfaceName);
addStaticArp(vppDataBroker, hostName, metadataInterfaceName, physicalAddress, metadataIp);
- addStaticRoute(vppDataBroker, hostName, vrf, metadataIp, metadataIpPrefix, metadataInterfaceName);
- hostIdToMetadataInterfaceMapper.addMetadataInterfaceInHost(hostName, metadataInterfaceName);
+ addStaticRoute(vppDataBroker, hostName, vrf, metadataSubnetUuid, metadataIp,
+ metadataIpPrefix, metadataInterfaceName);
+ portInterfacesOfHost.addInterfaceInMetadataInterfaceSet(metadataInterfaceName);
}
});
}
}
public void handleEndpointDeleteForFlatOverlay(AddressEndpointWithLocation addressEp) {
+ if (overlayHelper.hasRelativeLocations(addressEp)) {
+ // okay to ignore
+ // routes will be deleted on interface delete
+ return;
+ }
deleteStaticRoute(addressEp);
}
+ public void handleInterfaceDeleteForFlatOverlay(DataBroker vppDataBroker, VppEndpoint vppEndpoint) {
+ String hostName = vppEndpoint.getVppNodeId().getValue();
+ String interfaceName = vppEndpoint.getVppInterfaceName();
+
+ staticRoutingHelper.deleteAllRoutesThroughInterface(vppDataBroker, hostName, interfaceName);
+
+ PortInterfaces portInterfaces = hostRelatedInfoContainer.getPortInterfaceStateOfHost(hostName);
+ portInterfaces.removePortInterface(interfaceName);
+ }
+
private void configureInterfaceForFlatOverlay(AddressEndpointWithLocation addressEp) {
addInterfaceInVrf(addressEp);
}
private void addInterfaceInVrf(AddressEndpointWithLocation addressEp) {
- DataBroker vppDataBroker = overlayHelper.getPotentialExternalDataBroker(addressEp).get();
+ EndpointHost endpointHost = overlayHelper.getEndpointHostInformation(addressEp);
long vni = getVni(addressEp.getTenant().getValue());
long vrf = vni;
Optional<String> interfaceNameOptional = overlayHelper.getInterfaceName(addressEp);
Preconditions.checkArgument(interfaceNameOptional.isPresent());
- addInterfaceInVrf(vppDataBroker, interfaceNameOptional.get(), vrf);
+ addInterfaceInVrf(endpointHost, interfaceNameOptional.get(), vrf);
}
- private void addInterfaceInVrf(DataBroker vppDataBroker, String interfaceName, long vrf) {
- if (!putVrfInInterface(vppDataBroker, interfaceName, vrf)) {
+ private void addInterfaceInVrf(EndpointHost endpointHost, String interfaceName, long vrf) {
+ if (hostRelatedInfoContainer.getPortInterfaceStateOfHost(endpointHost.getHostName())
+ .isVrfConfiguredForInterface(interfaceName)) {
+ return;
+ }
+
+ if (!putVrfInInterface(endpointHost.getHostDataBroker(), interfaceName, vrf)) {
LOG.warn("Failed to put interface {} to vrf {}", interfaceName, vrf);
} else {
+ hostRelatedInfoContainer
+ .getPortInterfaceStateOfHost(endpointHost.getHostName())
+ .initializeRoutingContextForInterface(interfaceName, vrf);
LOG.debug("Added interface {} to vrf {}", interfaceName, vrf);
}
}
long vni = getVni(addressEp.getTenant().getValue());
long vrf = vni;
+ String portSubnetUuid = overlayHelper.getSubnet(addressEp);
+
String outgoingInterfaceName = overlayHelper.getInterfaceName(addressEp).get();
Ipv4Address ipWithoutPrefix = overlayHelper.getInterfaceIp(addressEp);
+
+ if (overlayHelper.isMetadataPort(addressEp)) {
+ //override original port subnet to handle the Absolute location case of address endpoint
+ portSubnetUuid = Constants.METADATA_SUBNET_UUID;
+ }
+
Ipv4Prefix ipv4Prefix = overlayHelper.getInterfaceIpAsPrefix(addressEp);
- addStaticRoute(vppDataBroker, hostName, vrf, ipWithoutPrefix, ipv4Prefix, outgoingInterfaceName);
+ addStaticRoute(vppDataBroker, hostName, vrf, portSubnetUuid, ipWithoutPrefix, ipv4Prefix, outgoingInterfaceName);
}
- private void addStaticRoute(DataBroker vppDataBroker, String hostName, long vrf, Ipv4Address ipWithoutPrefix,
- Ipv4Prefix ipv4Prefix, String outgoingInterfaceName) {
+ private void addStaticRoute(DataBroker vppDataBroker, String hostName, long vrfId, String hostIpSubnetUuid,
+ Ipv4Address ipWithoutPrefix, Ipv4Prefix ipv4Prefix, String outgoingInterfaceName) {
- if (!hostVrfInfo.vrfExists(hostName, vrf)) {
- if (!staticRoutingHelper.addRoutingProtocolForVrf(vppDataBroker, hostName, vrf)) {
- LOG.warn("Failed to add Routing protocol for host {} and vrf {}!", hostName, vrf);
+ VrfHolder vrfHolderOfHost = hostRelatedInfoContainer.getVrfStateOfHost(hostName);
+
+ if (!vrfHolderOfHost.hasVrf(vrfId)) {
+ if (!staticRoutingHelper.addRoutingProtocolForVrf(vppDataBroker, vrfId, vrfHolderOfHost)) {
+ LOG.warn("Failed to add Routing protocol for host {} and vrf {}!", hostName, vrfId);
}
}
- if (staticRoutingHelper.endPointRoutingExists(outgoingInterfaceName, ipWithoutPrefix)) {
- return;
- }
+ VrfState vrfStateOfVrfId = vrfHolderOfHost.getVrfState(vrfId);
- if (staticRoutingHelper.routeAlreadyExistsInHostVrf(hostName, vrf, ipWithoutPrefix)) {
- LOG.warn("Ip already exists in host {} vrf {} ip {}", hostName, vrf, ipWithoutPrefix);
+ if (vrfStateOfVrfId.getSubnetHolder().getSubnetState(hostIpSubnetUuid).isIpPresent(ipWithoutPrefix)) {
+ LOG.info("Ip already exists in host {} vrf {} ip {}", hostName, vrfId, ipWithoutPrefix);
return;
}
- if (!staticRoutingHelper.addSingleStaticRouteInRoutingProtocol(vppDataBroker,
- hostName,
- vrf,
- ipWithoutPrefix,
- ipv4Prefix,
- outgoingInterfaceName)) {
+ if (!staticRoutingHelper.addSingleStaticRouteInRoutingProtocol(vppDataBroker, hostName, vrfId, hostIpSubnetUuid,
+ ipWithoutPrefix, ipv4Prefix, outgoingInterfaceName)) {
LOG.warn("Failed to add routing ({} via {}) in vrf {} in compute host {}!",
- ipv4Prefix, outgoingInterfaceName, vrf, hostName);
+ ipv4Prefix, outgoingInterfaceName, vrfId, hostName);
} else {
LOG.debug("Added route ({} via {}) in vrf {} in compute host {}",
- ipv4Prefix, outgoingInterfaceName, vrf, hostName);
+ ipv4Prefix, outgoingInterfaceName, vrfId, hostName);
}
}
String interfaceName = overlayHelper.getInterfaceName(addressEp).get();
long vni = getVni(addressEp.getTenant().getValue());
- long vrf = vni;
+ long vrfId = vni;
+
+ String ipSubnetUuid = overlayHelper.getSubnet(addressEp);
+
+ if (overlayHelper.isMetadataPort(addressEp)) {
+ //override original port subnet to handle the Absolute location case of address endpoint
+ ipSubnetUuid = Constants.METADATA_SUBNET_UUID;
+ }
Ipv4Address ipWithoutPrefix = overlayHelper.getInterfaceIp(addressEp);
+ PortRouteState portRouteState = hostRelatedInfoContainer
+ .getPortInterfaceStateOfHost(hostName)
+ .getPortRouteState(interfaceName);
+
+ SubnetState subnetState = hostRelatedInfoContainer
+ .getVrfStateOfHost(hostName)
+ .getVrfState(vrfId)
+ .getSubnetHolder()
+ .getSubnetState(ipSubnetUuid);
+
+ if (!subnetState.isIpPresent(ipWithoutPrefix)) {
+ LOG.debug("Route {} already deleted from vrf {} of host {}", ipWithoutPrefix, vrfId, hostName);
+ return;
+ }
+
+ long targetRouteId = portRouteState.getRouteIdOfIp(ipWithoutPrefix);
+
if (!staticRoutingHelper.deleteSingleStaticRouteFromRoutingProtocol(vppDataBroker,
- hostName,
- vrf,
- interfaceName)) {
+ hostName,
+ vrfId,
+ interfaceName,
+ targetRouteId)) {
LOG.warn("Failed to delete route ({} via {}) from vrf {} from host{}",
- ipWithoutPrefix, interfaceName, vrf, hostName);
+ ipWithoutPrefix, interfaceName, vrfId, hostName);
} else {
+ portRouteState.removeIp(ipWithoutPrefix);
+ subnetState.removeIp(ipWithoutPrefix);
LOG.debug("Delete Static Route ({} via {}) from vrf {} from host {}",
- ipWithoutPrefix, interfaceName, vrf, hostName);
+ ipWithoutPrefix, interfaceName, vrfId, hostName);
}
}
+++ /dev/null
-/*
- * Copyright (c) 2017 Cisco Systems. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.flat.overlay;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Created by Shakib Ahmed on 5/4/17.
- */
-public class RoutingInfo {
- private String ProtocolName;
- private int count = 0;
- private Set<Ipv4Address> allIpsInVrf;
-
- public RoutingInfo() {
- allIpsInVrf = new HashSet<>();
- }
-
- public String getProtocolName() {
- return ProtocolName;
- }
-
- public void setProtocolName(String protocolName) {
- ProtocolName = protocolName;
- }
-
- public int getCount() {
- return count;
- }
-
- public void addIpInVrf(Ipv4Address ip) {
- allIpsInVrf.add(ip);
- incrementCount();
- }
-
- public boolean ipAlreadyExistsinVrf(Ipv4Address ip) {
- return allIpsInVrf.contains(ip);
- }
-
- private void incrementCount() {
- count++;
- }
-}
*/
package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.flat.overlay;
+import com.google.common.base.Preconditions;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers.HostVrfRoutingInformationMapper;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers.InterfaceNameToStaticInfoMapper;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.HostRelatedInfoContainer;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.PortInterfaces;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.PortRouteState;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.VrfHolder;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.VrfState;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.util.Constants;
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.inet.types.rev130715.Ipv4Address;
public class StaticRoutingHelper {
private static final Logger LOG = LoggerFactory.getLogger(StaticRoutingHelper.class);
- private static final String ROUTING_PROTOCOL_NAME_PREFIX = "static-routing-";
- private static final String DEFAULT_DESCRIPTION = "Static route added from GBP for flat L3 overlay";
-
- private HostVrfRoutingInformationMapper hostVrfInfo = HostVrfRoutingInformationMapper.getInstance();
-
- private InterfaceNameToStaticInfoMapper interfaceNameToStaticInfoMapper;
-
- public StaticRoutingHelper(InterfaceNameToStaticInfoMapper interfaceNameToStaticInfoMapper) {
- this.interfaceNameToStaticInfoMapper = interfaceNameToStaticInfoMapper;
- }
+ private HostRelatedInfoContainer hostRelatedInfoContainer = HostRelatedInfoContainer.getInstance();
public synchronized boolean addRoutingProtocolForVrf(DataBroker vppDataBroker,
- String hostId,
- long vrf) {
- String routingProtocolName = getRoutingProtocolName(vrf);
+ long vrfId,
+ VrfHolder vrfHolderOfHost) {
+ String routingProtocolName = getRoutingProtocolName(vrfId);
RoutingProtocolBuilder builder = new RoutingProtocolBuilder();
builder.setKey(new RoutingProtocolKey(routingProtocolName));
builder.setName(routingProtocolName);
builder.setType(Static.class);
- builder.setDescription(DEFAULT_DESCRIPTION);
+ builder.setDescription(Constants.DEFAULT_ROUTING_DESCRIPTION);
RoutingProtocolVppAttrBuilder vppAugmentationBuilder = new RoutingProtocolVppAttrBuilder();
vppAugmentationBuilder.
setVppProtocolAttributes(new VppProtocolAttributesBuilder()
- .setPrimaryVrf(new VniReference(vrf)).build());
+ .setPrimaryVrf(new VniReference(vrfId)).build());
builder.addAugmentation(RoutingProtocolVppAttr.class, vppAugmentationBuilder.build());
.getRoutingInstanceIid(builder.getKey());
if (GbpNetconfTransaction.netconfSyncedWrite(vppDataBroker,
iid, builder.build(), GbpNetconfTransaction.RETRY_COUNT)) {
- RoutingInfo info = new RoutingInfo();
- info.setProtocolName(routingProtocolName);
- hostVrfInfo.addRoutingVrfToHost(hostId, vrf, info);
+ vrfHolderOfHost.initializeVrfState(vrfId, routingProtocolName);
return true;
}
return false;
}
- public boolean endPointRoutingExists(String interfaceName, Ipv4Address ip) {
- return interfaceNameToStaticInfoMapper.routeAlreadyExists(interfaceName, ip);
- }
-
- public boolean routeAlreadyExistsInHostVrf(String hostId, long vrf, Ipv4Address ip) {
- return hostVrfInfo.ipAlreadyExistsInHostVrf(hostId, vrf, ip);
- }
-
public synchronized boolean addSingleStaticRouteInRoutingProtocol(DataBroker vppDataBroker,
- String hostId,
- long vrf,
- Ipv4Address nextHopAddress,
- Ipv4Prefix ipPrefix,
- String outgoingInterface) {
+ String hostName,
+ long portVrfId,
+ String portSubnetUuid,
+ Ipv4Address nextHopAddress,
+ Ipv4Prefix ipPrefix,
+ String outgoingInterface) {
RouteBuilder builder = new RouteBuilder();
- Long routingId = hostVrfInfo.getEndPointCountInVrf(hostId, vrf);
+ VrfState hostVrfStateForPortVrf = hostRelatedInfoContainer
+ .getVrfStateOfHost(hostName)
+ .getVrfState(portVrfId);
+
+ PortInterfaces hostPortInterfaces = hostRelatedInfoContainer
+ .getPortInterfaceStateOfHost(hostName);
+
+ Preconditions.checkNotNull(hostVrfStateForPortVrf, "Vrf has not been initialized yet");
+
+ long routeId = hostVrfStateForPortVrf.getNextRouteId();
- builder.setId(routingId);
+ builder.setId(routeId);
builder.setDestinationPrefix(ipPrefix);
builder.setKey(new RouteKey(builder.getId()));
builder.setNextHopOptions(new SimpleNextHopBuilder()
Ipv4 ipv4Route = new Ipv4Builder().setRoute(routes).build();
- InstanceIdentifier<Ipv4> iid = VppIidFactory.
- getRoutingInstanceIid(new RoutingProtocolKey(hostVrfInfo.getProtocolName(hostId, vrf)))
+ InstanceIdentifier<Ipv4> iid = VppIidFactory
+ .getRoutingInstanceIid(new RoutingProtocolKey(hostVrfStateForPortVrf.getProtocolName()))
.child(StaticRoutes.class)
.augmentation(StaticRoutes1.class)
.child(Ipv4.class);
- if (GbpNetconfTransaction.netconfSyncedMerge(vppDataBroker, iid, ipv4Route, GbpNetconfTransaction.RETRY_COUNT)) {
- interfaceNameToStaticInfoMapper.addRouteForInterface(outgoingInterface, nextHopAddress, routingId);
- hostVrfInfo.addStaticRoute(hostId, vrf, nextHopAddress);
+ if (GbpNetconfTransaction
+ .netconfSyncedMerge(vppDataBroker, iid, ipv4Route,
+ GbpNetconfTransaction.RETRY_COUNT)) {
+ hostVrfStateForPortVrf.addNewPortIpInVrf(portSubnetUuid, nextHopAddress);
+ hostPortInterfaces.addRouteToPortInterface(outgoingInterface, portSubnetUuid,
+ nextHopAddress, routeId);
return true;
}
}
public synchronized boolean deleteSingleStaticRouteFromRoutingProtocol(DataBroker vppDataBroker,
- String hostId,
- long vrf,
- String outgoingInterface) {
- List<Long> allRoutingIdsForPort = interfaceNameToStaticInfoMapper.getRoutingIdsAssociatedWithInterface(outgoingInterface);
+ String hostName,
+ long vrfId,
+ String outgoingInterfaceName,
+ Long routeId) {
+ VrfState vrfState = hostRelatedInfoContainer.getVrfStateOfHost(hostName).getVrfState(vrfId);
+
+ Preconditions.checkNotNull(vrfState, "Vrf has not been initialized");
+
+ InstanceIdentifier<Route> iid = VppIidFactory
+ .getRoutingInstanceIid(new RoutingProtocolKey(vrfState.getProtocolName()))
+ .child(StaticRoutes.class)
+ .augmentation(StaticRoutes1.class)
+ .child(Ipv4.class)
+ .child(Route.class, new RouteKey(routeId));
+
+ if (!GbpNetconfTransaction.netconfSyncedDelete(vppDataBroker, iid, GbpNetconfTransaction.RETRY_COUNT)) {
+ LOG.warn("Route delete failed for interface {} from {}", outgoingInterfaceName, hostName);
+ return false;
+ }
+ return true;
+ }
+
+ public synchronized boolean deleteAllRoutesThroughInterface(DataBroker vppDataBroker,
+ String hostName,
+ String outgoingInterfaceName) {
+ PortRouteState portRouteState = hostRelatedInfoContainer
+ .getPortInterfaceStateOfHost(hostName)
+ .getPortRouteState(outgoingInterfaceName);
+
+ long vrfId = hostRelatedInfoContainer.getPortInterfaceStateOfHost(hostName)
+ .getInterfaceVrfId(outgoingInterfaceName);
+
+ List<Ipv4Address> ipThroughInterface = portRouteState.getAllIps();
boolean allOk = true;
- for (Long routingId : allRoutingIdsForPort) {
- InstanceIdentifier<Route> iid = VppIidFactory.
- getRoutingInstanceIid(new RoutingProtocolKey(hostVrfInfo.getProtocolName(hostId, vrf)))
- .child(StaticRoutes.class)
- .augmentation(StaticRoutes1.class)
- .child(Ipv4.class)
- .child(Route.class, new RouteKey(routingId));
- if (!GbpNetconfTransaction.netconfSyncedDelete(vppDataBroker, iid, GbpNetconfTransaction.RETRY_COUNT)) {
- LOG.warn("Route delete failed for interface {} from {}", outgoingInterface, hostId);
- allOk = false;
+ for (Ipv4Address ip : ipThroughInterface) {
+ long routeId = portRouteState.getRouteIdOfIp(ip);
+ String subnetUuidOfIp = portRouteState.getSubnetUuidOfIp(ip);
+ boolean ok = deleteSingleStaticRouteFromRoutingProtocol(vppDataBroker, hostName, vrfId,
+ outgoingInterfaceName, routeId);
+
+ if (ok) {
+ portRouteState.removeIp(ip);
+ hostRelatedInfoContainer
+ .getVrfStateOfHost(hostName)
+ .getVrfState(vrfId)
+ .removePortIpFromVrf(subnetUuidOfIp, ip);
}
}
- interfaceNameToStaticInfoMapper.clearStaticRoutesForInterface(outgoingInterface);
return allOk;
}
public static String getRoutingProtocolName(long vrf) {
- return ROUTING_PROTOCOL_NAME_PREFIX + vrf;
+ return Constants.ROUTING_PROTOCOL_NAME_PREFIX + vrf;
}
}
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
+/**
+ * Created by Shakib Ahmed on 7/14/17.
+ */
+public class EndpointHost {
+ DataBroker hostDataBroker;
+ String hostName;
+
+ public EndpointHost(DataBroker hostDataBroker, String hostName) {
+ this.hostDataBroker = hostDataBroker;
+ this.hostName = hostName;
+ }
+
+ public DataBroker getHostDataBroker() {
+ return hostDataBroker;
+ }
+
+ public String getHostName() {
+ return hostName;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container;
+
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.PortInterfaces;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.LispState;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.PhysicalInterfaces;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.VrfHolder;
+
+import java.util.HashMap;
+
+/**
+ * Created by Shakib Ahmed on 7/13/17.
+ */
+public class HostRelatedInfoContainer {
+ private HashMap<String, LispState> hostNameToLispStateMapper;
+ private HashMap<String, PhysicalInterfaces> hostNameToPhysicalInterfacesMapper;
+ private HashMap<String, PortInterfaces> hostNameToPortInterfacesMapper;
+ private HashMap<String, VrfHolder> hostNameToVrfHolderMapper;
+
+ private static final HostRelatedInfoContainer INSTANCE = new HostRelatedInfoContainer();
+
+ private HostRelatedInfoContainer() {
+ this.hostNameToLispStateMapper = new HashMap<>();
+ this.hostNameToPhysicalInterfacesMapper = new HashMap<>();
+ this.hostNameToPortInterfacesMapper = new HashMap<>();
+ this.hostNameToVrfHolderMapper = new HashMap<>();
+ }
+
+ public static HostRelatedInfoContainer getInstance() {
+ return INSTANCE;
+ }
+
+ public LispState getLispStateOfHost(String hostName) {
+ return hostNameToLispStateMapper.get(hostName);
+ }
+
+ public void setLispStateOfHost(String hostName, LispState lispState) {
+ hostNameToLispStateMapper.put(hostName, lispState);
+ }
+
+ public void deleteLispStateOfHost(String hostName) {
+ hostNameToLispStateMapper.remove(hostName);
+ }
+
+ public PhysicalInterfaces getPhysicalInterfaceState(String hostName) {
+ return hostNameToPhysicalInterfacesMapper.get(hostName);
+ }
+
+ public void setPhysicalInterfaceStateOfHost(String hostName, PhysicalInterfaces physicalInterfaces) {
+ hostNameToPhysicalInterfacesMapper.put(hostName, physicalInterfaces);
+ }
+
+ public void removePhysicalInterfaceStateOfHost(String hostName) {
+ hostNameToPhysicalInterfacesMapper.remove(hostName);
+ }
+
+ public PortInterfaces getPortInterfaceStateOfHost(String hostName) {
+ return hostNameToPortInterfacesMapper.computeIfAbsent(hostName, key -> new PortInterfaces());
+ }
+
+ public void setVirtualInterfaceStateOfHost(String hostName, PortInterfaces portInterfaces) {
+ hostNameToPortInterfacesMapper.put(hostName, portInterfaces);
+ }
+
+ public void removeVirtualInterfaceStateOfHost(String hostName) {
+ hostNameToPortInterfacesMapper.remove(hostName);
+ }
+
+ public VrfHolder getVrfStateOfHost(String hostName) {
+ return hostNameToVrfHolderMapper.computeIfAbsent(hostName, key -> new VrfHolder());
+ }
+
+ public void removeVrfStateOfHost(String hostName) {
+ hostNameToVrfHolderMapper.remove(hostName);
+ }
+}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
-package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp;
+package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states;
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.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.Eid;
* Created by Shakib Ahmed on 3/29/17.
*/
public class LispState {
- private String hostName;
private boolean lispEnabled;
private boolean gpeEnabled;
- private HashMap<String, String> locIntfToLocSetNameMapping;
+ private HashMap<String, String> interfaceNameToLocatorSetNameMapper;
private Set<IpAddress> mapServerIpAddressSet;
private Set<IpAddress> mapResolverIpAddressSet;
private Set<Long> vniSet;
- private boolean mapRegisteredEnabled;
- private HashMap<Eid, String> eidToMappingIdMapper;
- private int interfaceCount;
+ private Set<Eid> eidSet;
- public LispState(String hostName) {
- this.hostName = hostName;
+ public LispState() {
lispEnabled = false;
- locIntfToLocSetNameMapping = new HashMap<>();
+ interfaceNameToLocatorSetNameMapper = new HashMap<>();
mapServerIpAddressSet = new HashSet<>();
mapResolverIpAddressSet = new HashSet<>();
- mapRegisteredEnabled = false;
vniSet = new HashSet<>();
- eidToMappingIdMapper = new HashMap<>();
- interfaceCount = 1;
- }
-
- public String getHostName() {
- return hostName;
+ eidSet = new HashSet<>();
}
public boolean isLispEnabled() {
}
public String getLocIntfToLocSetNameMapping(String locatorIntf) {
- return locIntfToLocSetNameMapping.get(locatorIntf);
+ return interfaceNameToLocatorSetNameMapper.get(locatorIntf);
}
public void setLocIntfToLocSetNameMapping(String locIntfName, String locSetName) {
- locIntfToLocSetNameMapping.put(locIntfName, locSetName);
+ interfaceNameToLocatorSetNameMapper.put(locIntfName, locSetName);
}
public Set<Map.Entry<String, String>> getLocatorSetEntry() {
- return locIntfToLocSetNameMapping.entrySet();
+ return interfaceNameToLocatorSetNameMapper.entrySet();
}
public int getLocatorCount() {
- return locIntfToLocSetNameMapping.size();
+ return interfaceNameToLocatorSetNameMapper.size();
}
public boolean mapServerSetContains(IpAddress ip) {
mapResolverIpAddressSet.add(ip);
}
- public boolean vniSetContains(long vni) {
+ public boolean isVniConfigured(long vni) {
return vniSet.contains(vni);
}
vniSet.add(vni);
}
- public boolean isMapRegisteredEnabled() {
- return mapRegisteredEnabled;
- }
-
- public void setMapRegisteredEnabled(boolean mapRegisteredEnabled) {
- this.mapRegisteredEnabled = mapRegisteredEnabled;
- }
-
public boolean eidSetContains(Eid eid) {
- return eidToMappingIdMapper.containsKey(eid);
- }
-
- public void addInEidSet(Eid eid, String mappingId) {
- interfaceCount++;
- eidToMappingIdMapper.put(eid, mappingId);
+ return eidSet.contains(eid);
}
public int eidCount() {
- return eidToMappingIdMapper.size();
+ return eidSet.size();
}
- public void deleteEid(Eid eid) {
- eidToMappingIdMapper.remove(eid);
+ public void addEidInEidSet(Eid eid) {
+ eidSet.add(eid);
}
-
- public String getEidMapping(Eid eid) {
- return eidToMappingIdMapper.get(eid);
- }
-
- public int getInterfaceId() {
- return interfaceCount;
+ public void deleteEid(Eid eid) {
+ eidSet.remove(eid);
}
}
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+
+import java.util.HashMap;
+
+/**
+ * Created by Shakib Ahmed on 7/14/17.
+ */
+public class PhysicalInterfaces {
+
+ public enum PhysicalInterfaceType {
+ PUBLIC
+ }
+
+ private HashMap<PhysicalInterfaceType, IpAddress> physicalInterfaceTypeToIpMapper;
+ private HashMap<PhysicalInterfaceType, String> physicalInterfaceTypeToNameMapper;
+
+
+ public PhysicalInterfaces() {
+ physicalInterfaceTypeToIpMapper = new HashMap<>();
+ physicalInterfaceTypeToNameMapper = new HashMap<>();
+ }
+
+ public void addPhysicalInterfaceInfo(PhysicalInterfaceType physicalInterfaceType,
+ String interfaceName,
+ IpAddress interfaceIp) {
+ physicalInterfaceTypeToNameMapper.put(physicalInterfaceType, interfaceName);
+ physicalInterfaceTypeToIpMapper.put(physicalInterfaceType, interfaceIp);
+ }
+
+ public IpAddress getIp(PhysicalInterfaceType physicalInterfaceType) {
+ return physicalInterfaceTypeToIpMapper.get(physicalInterfaceType);
+ }
+
+ public String getName(PhysicalInterfaceType physicalInterfaceType) {
+ return physicalInterfaceTypeToNameMapper.get(physicalInterfaceType);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Created by Shakib Ahmed on 7/14/17.
+ */
+public class PortInterfaces {
+ private HashMap<String, PortRouteState> interfaceNameToPortRouteStateMapper;
+ private Set<String> metadataInterfaceSet;
+
+ public PortInterfaces() {
+ interfaceNameToPortRouteStateMapper = new HashMap<>();
+ metadataInterfaceSet = new HashSet<>();
+ }
+
+ public void initializeRoutingContextForInterface(String interfaceName, Long vrfId) {
+ interfaceNameToPortRouteStateMapper.put(interfaceName, new PortRouteState(vrfId));
+ }
+
+ public boolean isVrfConfiguredForInterface(String interfaceName) {
+ return interfaceNameToPortRouteStateMapper.containsKey(interfaceName);
+ }
+
+ public PortRouteState getPortRouteState(String interfaceName) {
+ return interfaceNameToPortRouteStateMapper.get(interfaceName);
+ }
+
+ public void addRouteToPortInterface(String interfaceName, String ipSubnetUuid, Ipv4Address ip, long routeId) {
+ interfaceNameToPortRouteStateMapper.get(interfaceName).addRouteInfo(ip, routeId, ipSubnetUuid);
+ }
+
+ public boolean isInterfaceConfiguredForMetadata(String interfaceName) {
+ return metadataInterfaceSet.contains(interfaceName);
+ }
+
+ public void addInterfaceInMetadataInterfaceSet(String interfaceName) {
+ metadataInterfaceSet.add(interfaceName);
+ }
+
+ public long getInterfaceVrfId(String interfaceName) {
+ return interfaceNameToPortRouteStateMapper.get(interfaceName).getVrfId();
+ }
+
+ public void removePortInterface(String interfaceName) {
+ metadataInterfaceSet.remove(interfaceName);
+ interfaceNameToPortRouteStateMapper.remove(interfaceName);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * Created by Shakib Ahmed on 7/17/17.
+ */
+public class PortRouteState {
+ private HashMap<Ipv4Address, String> ipToSubnetUuidMapper;
+ private HashMap<Ipv4Address, Long> ipToRouteIdMapper;
+ private Long vrfId;
+
+ public PortRouteState(long vrfId) {
+ ipToRouteIdMapper = new HashMap<>();
+ ipToSubnetUuidMapper = new HashMap<>();
+ this.vrfId = vrfId;
+ }
+
+ public long getVrfId() {
+ return this.vrfId;
+ }
+
+ public void addRouteInfo(Ipv4Address ip, Long routeId, String ipSubnetUuid) {
+ ipToRouteIdMapper.put(ip, routeId);
+ ipToSubnetUuidMapper.put(ip, ipSubnetUuid);
+ }
+
+ public long getRouteIdOfIp(Ipv4Address interfaceIp) {
+ return ipToRouteIdMapper.get(interfaceIp);
+ }
+
+ public String getSubnetUuidOfIp(Ipv4Address interfaceIp) {
+ return ipToSubnetUuidMapper.get(interfaceIp);
+ }
+
+ public void removeIp(Ipv4Address ip) {
+ ipToRouteIdMapper.remove(ip);
+ ipToSubnetUuidMapper.remove(ip);
+ }
+
+ public List<Ipv4Address> getAllIps() {
+ return new ArrayList<>(ipToRouteIdMapper.keySet());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+
+/**
+ * Created by Shakib Ahmed on 7/17/17.
+ */
+public class RouteState {
+ private HashMap<Ipv4Address, Long> ipToRouteIdMapper;
+
+ public RouteState() {
+ ipToRouteIdMapper = new HashMap<>();
+ }
+
+ public boolean ipExists(Ipv4Address ip) {
+ return ipToRouteIdMapper.containsKey(ip);
+ }
+
+ public void addIpToRouteIdInfo(Ipv4Address ip, Long routeId) {
+ ipToRouteIdMapper.put(ip, routeId);
+ }
+
+ public long getRouteId(Ipv4Address ip) {
+ return ipToRouteIdMapper.get(ip);
+ }
+
+ public void removeIp(Ipv4Address ip) {
+ ipToRouteIdMapper.remove(ip);
+ }
+
+ public boolean hasNoIpRoutes() {
+ return ipToRouteIdMapper.isEmpty();
+ }
+
+ public List<Ipv4Address> getAllIps() {
+ return new ArrayList<>(ipToRouteIdMapper.keySet());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states;
+
+import java.util.HashMap;
+
+/**
+ * Created by Shakib Ahmed on 7/17/17.
+ */
+public class SubnetHolder {
+ private HashMap<String, SubnetState> subnetUuidToSubnetStateMapper;
+
+ public SubnetHolder() {
+ subnetUuidToSubnetStateMapper = new HashMap<>();
+ }
+
+ public SubnetState getSubnetState(String subnetUuid) {
+ return subnetUuidToSubnetStateMapper.computeIfAbsent(subnetUuid,
+ key -> new SubnetState());
+ }
+
+ public void removeSubnetState(String subnetUuid) {
+ subnetUuidToSubnetStateMapper.remove(subnetUuid);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Created by Shakib Ahmed on 7/17/17.
+ */
+public class SubnetState {
+ private String gwInterfaceName;
+ private Set<Ipv4Address> ipsInSubnet;
+
+ public SubnetState() {
+ ipsInSubnet = new HashSet<>();
+ }
+
+ public boolean isGwConfigured() {
+ return gwInterfaceName != null && !gwInterfaceName.isEmpty();
+ }
+
+ public String getGwInterfaceName() {
+ return gwInterfaceName;
+ }
+
+ public void setGwInterfaceName(String gwInterfaceName) {
+ this.gwInterfaceName = gwInterfaceName;
+ }
+
+ public boolean hasIpsInSubnet() {
+ return !ipsInSubnet.isEmpty();
+ }
+
+ public void addNewIp(Ipv4Address portIp) {
+ ipsInSubnet.add(portIp);
+ }
+
+ public boolean isIpPresent(Ipv4Address portIp) {
+ return ipsInSubnet.contains(portIp);
+ }
+
+ public void removeIp(Ipv4Address portIp) {
+ ipsInSubnet.remove(portIp);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states;
+
+import java.util.HashMap;
+
+/**
+ * Created by Shakib Ahmed on 7/17/17.
+ */
+public class VrfHolder {
+ HashMap<Long, VrfState> vrfIdToVrfStateMapper;
+
+ public VrfHolder() {
+ vrfIdToVrfStateMapper = new HashMap<>();
+ }
+
+ public VrfState getVrfState(Long vrfId) {
+ return vrfIdToVrfStateMapper.get(vrfId);
+ }
+
+ public void initializeVrfState(Long vrfId, String routingProtocolName) {
+ vrfIdToVrfStateMapper.put(vrfId, new VrfState(routingProtocolName));
+ }
+
+ public boolean hasVrf(Long vrfId) {
+ return vrfIdToVrfStateMapper.containsKey(vrfId);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states;
+
+import org.apache.commons.lang3.mutable.MutableLong;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+
+/**
+ * Created by Shakib Ahmed on 7/17/17.
+ */
+public class VrfState {
+ private SubnetHolder subnetHolder;
+ private String protocolName;
+ private MutableLong nextRouteId;
+
+ public VrfState(String routingProtocolName) {
+ this.subnetHolder = new SubnetHolder();
+ this.protocolName = routingProtocolName;
+ this.nextRouteId = new MutableLong(1L);
+ }
+
+ public SubnetHolder getSubnetHolder() {
+ return subnetHolder;
+ }
+
+ public String getProtocolName() {
+ return protocolName;
+ }
+
+ public long getNextRouteId() {
+ return nextRouteId.getValue();
+ }
+
+ public void addNewPortIpInVrf(String portSubnetUuid, Ipv4Address portIp) {
+ subnetHolder.getSubnetState(portSubnetUuid).addNewIp(portIp);
+ nextRouteId.increment();
+ }
+
+ public void removePortIpFromVrf(String portSubnetUuid, Ipv4Address portIp) {
+ subnetHolder.getSubnetState(portSubnetUuid).removeIp(portIp);
+ }
+}
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.LispStateCommandExecutor;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.exception.LispConfigCommandFailedException;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.exception.LispHelperArgumentException;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers.LoopbackHostSpecificInfoMapper;
+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.SubnetState;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.VrfHolder;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers.NeutronTenantToVniMapper;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers.SubnetUuidToGbpSubnetMapper;
import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.util.ConfigManagerHelper;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.util.Constants;
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.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
-import java.util.List;
/**
* Created by Shakib Ahmed on 4/26/17.
private ConfigManagerHelper loopbackManagerHelper;
- private LoopbackHostSpecificInfoMapper subnetHostSpecificInfo;
- private NeutronTenantToVniMapper neutronTenantToVniMapper;
- private SubnetUuidToGbpSubnetMapper subnetUuidToGbpSubnetMapper;
-
- private static final String LOOP_NAME_PREFIX = "loop-";
- private static final String GPE_ENTRY_PREFIX = "gpe-entry-";
+ private HostRelatedInfoContainer hostRelatedInfoContainer = HostRelatedInfoContainer.getInstance();
+ private SubnetUuidToGbpSubnetMapper subnetUuidToGbpSubnetMapper = SubnetUuidToGbpSubnetMapper.getInstance();
+ private NeutronTenantToVniMapper neutronTenantToVniMapper = NeutronTenantToVniMapper.getInstance();
public LoopbackManager(@Nonnull MountedDataBrokerProvider mountedDataBrokerProvider) {
this.loopbackManagerHelper = new ConfigManagerHelper(mountedDataBrokerProvider);
- this.subnetHostSpecificInfo = new LoopbackHostSpecificInfoMapper();
- this.neutronTenantToVniMapper = NeutronTenantToVniMapper.getInstance();
- this.subnetUuidToGbpSubnetMapper = SubnetUuidToGbpSubnetMapper.getInstance();
}
public void createBviLoopbackIfNeeded(AddressEndpointWithLocation addressEp,
String bridgeDomainName) {
try {
- DataBroker vppDataBroker = loopbackManagerHelper.getPotentialExternalDataBroker(addressEp).get();
- String hostName = loopbackManagerHelper.getHostName(addressEp).get();
+ EndpointHost endpointHost = loopbackManagerHelper.getEndpointHostInformation(addressEp);
+ long vni = getVni(addressEp.getTenant().getValue());
+ long vrfId = vni;
String subnetUuid = loopbackManagerHelper.getSubnet(addressEp);
- if (subnetHostSpecificInfo.loopbackAlreadyExists(hostName, subnetUuid)) {
- subnetHostSpecificInfo.addNewPortInHostSubnet(hostName, subnetUuid);
+ VrfHolder hostVrfHolder = hostRelatedInfoContainer.getVrfStateOfHost(endpointHost.getHostName());
+
+ if (!hostVrfHolder.hasVrf(vrfId)) {
+ //dummy init for bridge domain case
+ hostVrfHolder.initializeVrfState(vrfId, Constants.DUMMY_PROTOCOL_BRIDGE_DOMAIN);
+ }
+
+ SubnetState subnetState = hostVrfHolder.getVrfState(vni)
+ .getSubnetHolder()
+ .getSubnetState(subnetUuid);
+
+ if (!subnetState.isGwConfigured()) {
return;
}
GbpSubnet gbpSubnetInfo = Preconditions.checkNotNull(getSubnetInfo(subnetUuid),
"Subnet UUID {} hasn't been created yet!", subnetUuid);
- String interfaceName = LOOP_NAME_PREFIX + subnetHostSpecificInfo.getLoopbackCount(hostName);
- long vni = getVni(addressEp.getTenant().getValue());
+ String gwInterfaceName = loopbackManagerHelper.getGatewayInterfaceName(Constants.GW_NAME_PREFIX, subnetUuid);
LoopbackCommand bviLoopbackCommand = LoopbackCommandWrapper
- .bviLoopbackPutCommand(interfaceName, vni, gbpSubnetInfo.getGatewayIp(), gbpSubnetInfo.getCidr(),
+ .bviLoopbackPutCommand(gwInterfaceName, vni, gbpSubnetInfo.getGatewayIp(), gbpSubnetInfo.getCidr(),
bridgeDomainName);
- createLoopbackInterface(hostName, subnetUuid, vppDataBroker, bviLoopbackCommand);
+ createLoopbackInterface(endpointHost.getHostDataBroker(), endpointHost.getHostName(),
+ subnetState, bviLoopbackCommand);
} catch (LispConfigCommandFailedException e) {
LOG.warn("LISP couldn't be configured: {}", e.getMessage());
}
try {
if (loopbackManagerHelper.isMetadataPort(addressEp)) {
- // if the address endpoint is a metadataport, no proxy arp range needed.
return;
}
DataBroker vppDataBroker = loopbackManagerHelper.getPotentialExternalDataBroker(addressEp).get();
String hostName = loopbackManagerHelper.getHostName(addressEp).get();
+ long vni = getVni(addressEp.getTenant().getValue());
+ long vrfId = vni;
String subnetUuid = loopbackManagerHelper.getSubnet(addressEp);
- if (subnetHostSpecificInfo.loopbackAlreadyExists(hostName, subnetUuid)) {
- subnetHostSpecificInfo.addNewPortInHostSubnet(hostName, subnetUuid);
- String loopbackInterfaceName = subnetHostSpecificInfo
- .getInterfaceNameForLoopbackInHost(hostName, subnetUuid);
- addUnnumberedInterface(addressEp, loopbackInterfaceName);
- return;
- }
-
- String interfaceName = LOOP_NAME_PREFIX + subnetHostSpecificInfo.getLoopbackCount(hostName);
- long vni = getVni(addressEp.getTenant().getValue());
- long vrf = vni;
+ SubnetState stateOfSubnetUuid = hostRelatedInfoContainer
+ .getVrfStateOfHost(hostName)
+ .getVrfState(vrfId).getSubnetHolder()
+ .getSubnetState(subnetUuid);
GbpSubnet gbpSubnetInfo = Preconditions.checkNotNull(getSubnetInfo(subnetUuid),
"Subnet UUID {} hasn't been created yet!", subnetUuid);
- LoopbackCommand simpleLoopbackCommand = LoopbackCommandWrapper
- .simpleLoopbackPutCommand(interfaceName, vrf, gbpSubnetInfo.getGatewayIp(),
- gbpSubnetInfo.getCidr());
+ if (!stateOfSubnetUuid.isGwConfigured()) {
+ String interfaceName = loopbackManagerHelper.getGatewayInterfaceName(Constants.GW_NAME_PREFIX,
+ subnetUuid);
+ 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, subnetUuid, vppDataBroker, simpleLoopbackCommand);
- addProxyArpRange(vppDataBroker, vrf, gbpSubnetInfo, hostName);
- addGpeEntry(vppDataBroker, gbpSubnetInfo, vni);
- addUnnumberedInterface(addressEp, interfaceName);
+ String gwInterfaceName = stateOfSubnetUuid.getGwInterfaceName();
+ addUnnumberedInterface(addressEp, gwInterfaceName);
} catch (LispConfigCommandFailedException e) {
LOG.warn("LISP couldn't be configured: {}", e.getMessage());
}
}
- private void createLoopbackInterface(String hostName, String subnetUuid, DataBroker vppDataBroker,
+ private void createLoopbackInterface(DataBroker vppDataBroker, String hostName,
+ SubnetState subnetState,
LoopbackCommand loopbackCommand) throws LispConfigCommandFailedException {
if (GbpNetconfTransaction.netconfSyncedWrite(vppDataBroker,
loopbackCommand,
GbpNetconfTransaction.RETRY_COUNT)) {
- subnetHostSpecificInfo.addLoopbackForHost(hostName, subnetUuid, loopbackCommand.getName(),
- loopbackCommand.getVrfId());
- subnetHostSpecificInfo.addNewPortInHostSubnet(hostName, subnetUuid);
+ subnetState.setGwInterfaceName(loopbackCommand.getName());
} else {
throw new LispConfigCommandFailedException("BVI could not be created for "
+ hostName + " and bridge domain " + loopbackCommand.getBridgeDomain());
}
}
- public void deleteLoopbackIfExists(String subnetUuid) {
-
- List<String> hostsWithSubnet = subnetHostSpecificInfo.getHostsWithSubnet(subnetUuid);
-
- hostsWithSubnet.forEach(host -> {
- DataBroker vppDataBroker = loopbackManagerHelper.getPotentialExternalDataBroker(host).get();
- String interfaceName = subnetHostSpecificInfo.getInterfaceNameForLoopbackInHost(host, subnetUuid);
-
- try {
- deleteSpecificLoopback(vppDataBroker, interfaceName);
- } catch (LispConfigCommandFailedException e) {
- e.printStackTrace();
- }
- });
+ public void handleEndpointDelete(AddressEndpointWithLocation addressEp) {
- subnetHostSpecificInfo.clearSubnet(subnetUuid);
- }
+ if (loopbackManagerHelper.isMetadataPort(addressEp)) {
+ return;
+ }
- public void handleEndpointDelete(AddressEndpointWithLocation addressEp) {
DataBroker vppDataBroker = loopbackManagerHelper.getPotentialExternalDataBroker(addressEp).get();
- String hostId = loopbackManagerHelper.getHostName(addressEp).get();
+ String hostName = loopbackManagerHelper.getHostName(addressEp).get();
String portSubnetUuid = loopbackManagerHelper.getSubnet(addressEp);
- String interfaceName = subnetHostSpecificInfo.getInterfaceNameForLoopbackInHost(hostId, portSubnetUuid);
- if (subnetHostSpecificInfo.deletePortFromHostSubnetAndTriggerLoopbackDelete(hostId, portSubnetUuid)) {
+ long vrfId = getVni(addressEp.getTenant().getValue());
+ SubnetState subnetStateForSubnetUuid = hostRelatedInfoContainer
+ .getVrfStateOfHost(hostName)
+ .getVrfState(vrfId)
+ .getSubnetHolder()
+ .getSubnetState(portSubnetUuid);
+
+ if (!subnetStateForSubnetUuid.hasIpsInSubnet()) {
+ String gwInterfaceName = subnetStateForSubnetUuid.getGwInterfaceName();
GbpSubnet gbpSubnetInfo = Preconditions.checkNotNull(subnetUuidToGbpSubnetMapper.getSubnetInfo(portSubnetUuid),
"Invalid port!");
long vni = getVni(addressEp.getTenant().getValue());
try {
- deleteSpecificLoopback(vppDataBroker, interfaceName);
- deleteProxyArpRange(vppDataBroker, vni, gbpSubnetInfo, hostId);
- deleteGpeEntry(vppDataBroker, GPE_ENTRY_PREFIX + gbpSubnetInfo.getId() + "_1");
- deleteGpeEntry(vppDataBroker, GPE_ENTRY_PREFIX + gbpSubnetInfo.getId() + "_2");
+ 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");
+ hostRelatedInfoContainer.getVrfStateOfHost(hostName)
+ .getVrfState(vrfId)
+ .getSubnetHolder()
+ .removeSubnetState(portSubnetUuid);
} catch (LispConfigCommandFailedException e) {
LOG.warn("Loopback not deleted properly: {}", e.getMessage());
}
}
private void addProxyArpRange(DataBroker vppDataBroker,
+ String hostName,
long vrf,
- GbpSubnet gbpSubnetInfo,
- String hostName) throws LispConfigCommandFailedException {
+ GbpSubnet gbpSubnetInfo) throws LispConfigCommandFailedException {
Ipv4Prefix subnetPrefix = gbpSubnetInfo.getCidr().getIpv4Prefix();
Preconditions.checkNotNull(subnetPrefix, "Subnet CIDR found to be null for "
}
private void deleteProxyArpRange(DataBroker vppDataBroker,
+ String hostName,
long vrf,
- GbpSubnet gbpSubnetInfo,
- String hostName) throws LispConfigCommandFailedException {
+ GbpSubnet gbpSubnetInfo) throws LispConfigCommandFailedException {
Ipv4Prefix subnetPrefix = gbpSubnetInfo.getCidr().getIpv4Prefix();
Preconditions.checkNotNull(subnetPrefix, "Subnet CIDR found to be null for "
RemoteEid firstREid = LispUtil.toRemoteEid(LispUtil.toLispIpv4Prefix(delegatingSubnets.getLeft()),
vni,
Ipv4PrefixAfi.class);
- putGpeEntry(vppDataBroker, GPE_ENTRY_PREFIX + gbpSubnetInfo.getId() + "_1", firstREid, vni, vni);
+ putGpeEntry(vppDataBroker, Constants.GPE_ENTRY_PREFIX + gbpSubnetInfo.getId() + "_1", firstREid, vni, vni);
if (delegatingSubnets.getLeft().equals(delegatingSubnets.getRight())) {
return;
vni,
Ipv4PrefixAfi.class);
- putGpeEntry(vppDataBroker, GPE_ENTRY_PREFIX + gbpSubnetInfo.getId() + "_2", secondREid, vni, vni);
+ putGpeEntry(vppDataBroker, Constants.GPE_ENTRY_PREFIX + gbpSubnetInfo.getId() + "_2", secondREid, vni, vni);
} catch (LispHelperArgumentException e) {
e.printStackTrace();
}
+++ /dev/null
-/*
- * Copyright (c) 2017 Cisco Systems. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers;
-
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.InterfaceInfo;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
-
-import java.util.HashMap;
-
-/**
- * Created by Shakib Ahmed on 6/23/17.
- */
-public class HostIdToInterfaceInfoMapper {
-
- public enum InterfaceType {
- PUBLIC
- }
-
- HashMap<String, HashMap<InterfaceType, InterfaceInfo>> hostIdToInterfaceInfoMapper;
-
- private HostIdToInterfaceInfoMapper() {
- hostIdToInterfaceInfoMapper = new HashMap<>();
- }
-
- private static final HostIdToInterfaceInfoMapper INSTANCE = new HostIdToInterfaceInfoMapper();
-
- public static HostIdToInterfaceInfoMapper getInstance() {
- return INSTANCE;
- }
-
- public void addInterfaceInfo(String hostId,
- InterfaceType interfaceType,
- String interfaceName,
- IpAddress interfaceIp) {
- HashMap<InterfaceType, InterfaceInfo> typeToInterfaceInfoMapper =
- hostIdToInterfaceInfoMapper.computeIfAbsent(hostId, id -> new HashMap<>());
-
- typeToInterfaceInfoMapper.put(interfaceType, new InterfaceInfo(interfaceName, interfaceIp));
- }
-
- public InterfaceInfo getInterfaceInfo(String hostId, InterfaceType interfaceType) {
-
- if (!hostIdToInterfaceInfoMapper.containsKey(hostId)) {
- return null;
- }
-
- return hostIdToInterfaceInfoMapper.get(hostId).get(interfaceType);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Cisco Systems. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers;
-
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.SetMultimap;
-
-
-/**
- * Created by Shakib Ahmed on 7/10/17.
- */
-public class HostIdToMetadataInterfaceMapper {
- private SetMultimap<String, String> hostIdToMetadataInterfaceNameMapper;
-
- private static final HostIdToMetadataInterfaceMapper INSTANCE = new HostIdToMetadataInterfaceMapper();
-
- private HostIdToMetadataInterfaceMapper() {
- hostIdToMetadataInterfaceNameMapper = HashMultimap.create();
- }
-
- public static HostIdToMetadataInterfaceMapper getInstance() {
- return INSTANCE;
- }
-
- public boolean isMetadataInterfaceConfigured(String hostId, String metadataInterfaceName) {
- return hostIdToMetadataInterfaceNameMapper.get(hostId).contains(metadataInterfaceName);
- }
-
- public void addMetadataInterfaceInHost(String hostId, String metadataInterfaceName) {
- hostIdToMetadataInterfaceNameMapper.put(hostId, metadataInterfaceName);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Cisco Systems. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers;
-
-
-import com.google.common.base.Preconditions;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.flat.overlay.RoutingInfo;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-
-import java.util.HashMap;
-
-/**
- * Created by Shakib Ahmed on 5/4/17.
- */
-public class HostVrfRoutingInformationMapper {
- HashMap<String, HashMap<Long, RoutingInfo> > mapper;
-
- private static final HostVrfRoutingInformationMapper INSTANCE = new HostVrfRoutingInformationMapper();
-
- private HostVrfRoutingInformationMapper() {
- mapper = new HashMap<>();
- }
-
- public static HostVrfRoutingInformationMapper getInstance() {
- return INSTANCE;
- }
-
- public void addRoutingVrfToHost(String hostId, long vrf, RoutingInfo routingInfo) {
- HashMap<Long, RoutingInfo> routingInfoMapper = mapper.get(hostId);
-
- if (routingInfoMapper == null) {
- routingInfoMapper = new HashMap<>();
- mapper.put(hostId, routingInfoMapper);
- }
-
- routingInfoMapper.put(vrf, routingInfo);
- }
-
- public boolean vrfExists(String hostId, long vrf) {
- return mapper.containsKey(hostId) && mapper.get(hostId).containsKey(vrf);
- }
-
- public String getProtocolName(String hostId, long vrf) {
- Preconditions.checkArgument(vrfExists(hostId, vrf));
-
- return mapper.get(hostId).get(vrf).getProtocolName();
- }
-
- public void addStaticRoute(String hostId, long vrf, Ipv4Address ip) {
- HashMap<Long, RoutingInfo> routingInfoMapper = mapper.get(hostId);
-
- Preconditions.checkNotNull(routingInfoMapper, "Routing protocol not created, can't add route entry");
-
- RoutingInfo routingInfo = routingInfoMapper.get(vrf);
-
- Preconditions.checkNotNull(routingInfoMapper, "VRF was not created for this host");
-
- routingInfo.addIpInVrf(ip);
- }
-
- public Long getEndPointCountInVrf(String hostId, long vrf) {
- int count = 0;
-
- if (vrfExists(hostId, vrf)) {
- count = mapper.get(hostId).get(vrf).getCount();
- }
- return (long) (count + 1);
- }
-
- public boolean ipAlreadyExistsInHostVrf(String hostId, long vrf, Ipv4Address ip) {
- HashMap<Long, RoutingInfo> routingInfoMapper = mapper.get(hostId);
-
- Preconditions.checkNotNull(routingInfoMapper, "Routing protocol not created, can't add route entry");
-
- RoutingInfo routingInfo = routingInfoMapper.get(vrf);
-
- return routingInfo.ipAlreadyExistsinVrf(ip);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Cisco Systems. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers;
-
-import com.google.common.base.Preconditions;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-/**
- * Created by Shakib Ahmed on 5/26/17.
- */
-public class InterfaceNameToStaticInfoMapper {
- HashMap<String, StaticRouteInfoMapper> interfaceNameToStaticRouteMapper;
-
- private static final InterfaceNameToStaticInfoMapper INSTANCE = new InterfaceNameToStaticInfoMapper();
-
- private InterfaceNameToStaticInfoMapper() {
- interfaceNameToStaticRouteMapper = new HashMap<>();
- }
-
- public static InterfaceNameToStaticInfoMapper getInstance() {
- return INSTANCE;
- }
-
- public boolean routeAlreadyExists(String interfaceName, Ipv4Address ip) {
- StaticRouteInfoMapper staticRouteInfoMapper = interfaceNameToStaticRouteMapper.get(interfaceName);
-
- if (staticRouteInfoMapper == null) {
- return false;
- }
-
- return staticRouteInfoMapper.routeWithIpExists(ip);
- }
-
- public void addRouteForInterface(String interfaceName, Ipv4Address ip, Long routeId) {
- StaticRouteInfoMapper staticRouteInfoMapper = interfaceNameToStaticRouteMapper.get(interfaceName);
-
- if (staticRouteInfoMapper == null) {
- staticRouteInfoMapper = new StaticRouteInfoMapper();
- interfaceNameToStaticRouteMapper.put(interfaceName, staticRouteInfoMapper);
- }
-
- staticRouteInfoMapper.addIpRouteForInterface(ip, routeId);
- }
-
- public List<Long> getRoutingIdsAssociatedWithInterface(String interfaceName) {
- StaticRouteInfoMapper staticRouteInfoMapper = interfaceNameToStaticRouteMapper.get(interfaceName);
-
- return staticRouteInfoMapper == null ? new ArrayList<>() : staticRouteInfoMapper.getAllRoutingIds();
- }
-
- public void clearStaticRoutesForInterface(String interfaceName) {
- interfaceNameToStaticRouteMapper.remove(interfaceName);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Cisco Systems. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers;
-
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Multimap;
-import org.apache.commons.lang3.mutable.MutableInt;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.loopback.SubnetHostInfo;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * Created by Shakib Ahmed on 4/26/17.
- */
-public class LoopbackHostSpecificInfoMapper {
- private HashMap<String, HashMap<String, SubnetHostInfo>> hostIdToSubnetMapper;
- private Multimap<String, String> subnetUuidToHostIdListMapper;
- private HashMap<String, MutableInt> hostIdToLoopbackCountMapper;
-
- public LoopbackHostSpecificInfoMapper() {
- hostIdToSubnetMapper = new HashMap<>();
- subnetUuidToHostIdListMapper = ArrayListMultimap.create();
- hostIdToLoopbackCountMapper = new HashMap<>();
- }
-
- private HashMap<String, SubnetHostInfo> getSubnetsOfHost(String hostName) {
- return hostIdToSubnetMapper.get(hostName);
- }
-
- public boolean loopbackAlreadyExists(String hostName, String subnetUuid) {
- return hostIdToSubnetMapper.containsKey(hostName) &&
- hostIdToSubnetMapper.get(hostName).containsKey(subnetUuid);
- }
-
- public void addLoopbackForHost(String hostName, String subnetUuid, String interfaceName, long vrf) {
- putSubnetInfoOfAHost(hostName, subnetUuid, interfaceName, vrf);
- subnetUuidToHostIdListMapper.put(subnetUuid, hostName);
- }
-
- private void putSubnetInfoOfAHost(String hostId, String subnetUuid, String interfaceName, long vrf) {
- HashMap<String, SubnetHostInfo> subnetsOfAHost = getSubnetsOfHost(hostId);
- MutableInt loopbackCount = getMutableIntAfterInitIfNecessary(hostId);
-
- loopbackCount.add(1);
-
- if (subnetsOfAHost == null) {
- subnetsOfAHost = new HashMap<>();
- hostIdToSubnetMapper.put(hostId, subnetsOfAHost);
- }
-
- SubnetHostInfo subnetHostInfo = new SubnetHostInfo(interfaceName);
- subnetsOfAHost.put(subnetUuid, subnetHostInfo);
- }
-
- private MutableInt getMutableIntAfterInitIfNecessary(String hostId) {
- MutableInt loopbackCount = hostIdToLoopbackCountMapper.get(hostId);
-
- if (loopbackCount == null) {
- loopbackCount = new MutableInt();
- loopbackCount.setValue(0);
- hostIdToLoopbackCountMapper.put(hostId, loopbackCount);
- }
- return loopbackCount;
- }
-
- public int getLoopbackCount(String hostName) {
- MutableInt loopbackCount = getMutableIntAfterInitIfNecessary(hostName);
- return loopbackCount.getValue();
- }
-
- public void clearSubnet(String subnetUuid) {
- subnetUuidToHostIdListMapper.get(subnetUuid).forEach(hostId -> {
- deleteParticularSubnetFromHost(hostId, subnetUuid);
- });
- subnetUuidToHostIdListMapper.get(subnetUuid).clear();
- }
-
- private void deleteParticularSubnetFromHost(String hostId, String subnetUuid) {
- hostIdToSubnetMapper.get(hostId).remove(subnetUuid);
- }
-
- private void deleteHostFromSubnetMap(String subnetUuid, String hostId) {
- subnetUuidToHostIdListMapper.get(subnetUuid).remove(hostId);
- }
-
- public List<String> getHostsWithSubnet(String subnetUuid) {
- return subnetUuidToHostIdListMapper.get(subnetUuid).stream().collect(Collectors.toList());
- }
-
- public String getInterfaceNameForLoopbackInHost(String hostId, String subnetUuid) {
- if (hostIdToSubnetMapper.get(hostId) != null) {
- return hostIdToSubnetMapper.get(hostId).get(subnetUuid).getInterfaceName();
- } else {
- return null;
- }
- }
-
- public int getPortCount(String hostId, String subnetUuid) {
- if (hostIdToSubnetMapper.containsKey(hostId)) {
- if (hostIdToSubnetMapper.get(hostId).containsKey(subnetUuid)) {
- return hostIdToSubnetMapper.get(hostId).get(subnetUuid).getPortCount();
- } else {
- return 0;
- }
- } else {
- return 0;
- }
- }
-
- public void addNewPortInHostSubnet(String hostId, String subnetUuid) {
- getSubnetsOfHost(hostId).get(subnetUuid).incrementPortCount();
- }
-
- public boolean deletePortFromHostSubnetAndTriggerLoopbackDelete(String hostId, String subnetUuid) {
- if (getSubnetsOfHost(hostId).containsKey(subnetUuid)) {
- int count = getSubnetsOfHost(hostId).get(subnetUuid).decrementAndGetPortCount();
-
- if (count == 0) {
- deleteParticularSubnetFromHost(hostId, subnetUuid);
- }
-
- return count == 0;
- } else {
- return false;
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Cisco Systems. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * Created by Shakib Ahmed on 5/26/17.
- */
-public class StaticRouteInfoMapper {
- HashMap<Ipv4Address, Long> interfaceIpToRouteIdMapper;
-
- public StaticRouteInfoMapper() {
- interfaceIpToRouteIdMapper = new HashMap<>();
- }
-
- public void addIpRouteForInterface(Ipv4Address ip, Long routingId) {
- interfaceIpToRouteIdMapper.put(ip, routingId);
- }
-
- public boolean routeWithIpExists(Ipv4Address ip) {
- return interfaceIpToRouteIdMapper.containsKey(ip);
- }
-
- public Long getRouteIdForIp(Ipv4Address ip) {
- return interfaceIpToRouteIdMapper.get(ip);
- }
-
- public List<Long> getAllRoutingIds() {
- return interfaceIpToRouteIdMapper.entrySet()
- .stream()
- .map(ipv4AddressLongEntry -> ipv4AddressLongEntry.getValue())
- .collect(Collectors.toList());
- }
-}
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.iface.VppPathMapper;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.LispState;
+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.mappers.HostIdToInterfaceInfoMapper;
+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.LispUtil;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
public class ConfigManagerHelper {
private static final Logger LOG = LoggerFactory.getLogger(ConfigManagerHelper.class);
- private static final String TENANT_INTERFACE = "tenant-interface";
private MountedDataBrokerProvider mountedDataBrokerProvider;
public ConfigManagerHelper(MountedDataBrokerProvider mountedDataBrokerProvider) {
this.mountedDataBrokerProvider = mountedDataBrokerProvider;
}
+ public EndpointHost getEndpointHostInformation(AddressEndpointWithLocation addressEpWithLoc) {
+ DataBroker endpointHostDataBroker = getPotentialExternalDataBroker(addressEpWithLoc).get();
+ String hostName = getHostName(addressEpWithLoc).get();
+ return new EndpointHost(endpointHostDataBroker, hostName);
+ }
+
public Optional<DataBroker> getPotentialExternalDataBroker(AddressEndpointWithLocation addressEpWithLoc) {
ExternalLocationCase externalLocationCase = resolveAndValidateLocation(addressEpWithLoc);
InstanceIdentifier<?> vppNodeIid = externalLocationCase.getExternalNodeMountPoint();
String interfacePath = externalLocationCase.getExternalNodeConnector();
- Optional<DataBroker> potentialVppDataProvider = mountedDataBrokerProvider.getDataBrokerForMountPoint(vppNodeIid);
+ Optional<DataBroker>
+ potentialVppDataProvider = mountedDataBrokerProvider.getDataBrokerForMountPoint(vppNodeIid);
Preconditions.checkArgument(potentialVppDataProvider.isPresent(),
"Cannot resolve data broker for interface path: {}", interfacePath);
Preconditions.checkNotNull(hostName, "Hostname is null!");
Preconditions.checkNotNull(vppDataBroker, "Vpp DataBroker is null!");
- String publicInterfaceName = HostIdToInterfaceInfoMapper.getInstance()
- .getInterfaceInfo(hostName, HostIdToInterfaceInfoMapper.InterfaceType.PUBLIC).getInterfaceName();
+ 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),
for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.
interfaces.Interface intf : hostInterfaceFromOpDS) {
- if (TENANT_INTERFACE.equals(intf.getDescription())
+ if (Constants.TENANT_INTERFACE.equals(intf.getDescription())
&& ipAddressPresent(intf)
&& intf.getType().equals(EthernetCsmacd.class)) {
return Futures.immediateFuture(intf.getName());
return LispStateManager.DEFAULT_LOCATOR_SET_NAME_PREFIX + (locatorSetCount + 1);
}
- public String constructMappingName(int presentMappingCount) {
- return LispStateManager.DEFAULT_MAPPINGRECORD_NAME_PREFIX + (presentMappingCount + 1);
+ public String constructEidMappingName(AddressEndpointWithLocation addressEp) {
+ String interfaceName = getInterfaceName(addressEp).get();
+ String ipAddress = getInterfaceIp(addressEp).getValue();
+ return LispStateManager.DEFAULT_MAPPINGRECORD_NAME_PREFIX + interfaceName + "_" + ipAddress;
}
public String getSubnet(AddressEndpointWithLocation addressEp) {
"in address endpoint: " + addressEp);
}
- public boolean isMetadataPort(AddressEndpointWithLocation addedEp) {
+ public boolean hasRelativeLocations(AddressEndpointWithLocation addedEp) {
return addedEp.getRelativeLocations() != null && addedEp.getRelativeLocations().getExternalLocation() != null;
}
+ public boolean isMetadataPort(AddressEndpointWithLocation addressEp) {
+ return hasRelativeLocations(addressEp) || IpAddressUtil.isMetadataIp(getInterfaceIp(addressEp));
+ }
+
+ public String getGatewayInterfaceName(String gwNamePrefix, String subnetUuid) {
+ return gwNamePrefix + subnetUuid;
+ }
+
public Routing getRouting(long vrf) {
return new RoutingBuilder().setIpv4VrfId(vrf).build();
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.util;
+
+
+/**
+ * Created by Shakib Ahmed on 7/20/17.
+ */
+public class Constants {
+ public static final String METADATA_IP = "169.254.169.254";
+ public static final String METADATA_SUBNET_UUID = "dummy-metadata-subet";
+ public static final String ROUTING_PROTOCOL_NAME_PREFIX = "static-routing-";
+ public static final String DEFAULT_ROUTING_DESCRIPTION = "Static route added from GBP for flat L3 overlay";
+ public static final String GW_NAME_PREFIX = "loop-";
+ public static final String GPE_ENTRY_PREFIX = "gpe-entry-";
+ public static final String DUMMY_PROTOCOL_BRIDGE_DOMAIN = "bridge-domain-dummy-protocol";
+ public static final String TENANT_INTERFACE = "tenant-interface";
+}
public class IpAddressUtil {
private static final Logger LOG = LoggerFactory.getLogger(IpAddressUtil.class);
+ public static boolean isMetadataIp(Ipv4Address ipv4Address) {
+ return ipv4Address.getValue().equals(Constants.METADATA_IP);
+ }
+
public static Pair<Ipv4Address, Ipv4Address> getStartAndEndIp(Ipv4Prefix ipv4Prefix) {
SubnetUtils subnetUtils = new SubnetUtils(ipv4Prefix.getValue());
SubnetUtils.SubnetInfo prefixSubnetInfo = subnetUtils.getInfo();
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers.HostIdToInterfaceInfoMapper;
+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.VppIidFactory;
import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppRendererProcessingException;
private final DataBroker dataBroker;
private final List<String> requiredCapabilities;
private final MountPointService mountService;
+ private final HostRelatedInfoContainer hostRelatedInfoContainer = HostRelatedInfoContainer.getInstance();
public VppNodeManager(@Nonnull final DataBroker dataBroker,
@Nonnull final BindingAwareBroker.ProviderContext session, @Nullable String physicalInterfaces) {
phIface.setInterfaceName(iface.getName());
phIface.setType(iface.getType());
phIface.setAddress(resolveIpAddress(iface.getAugmentation(Interface1.class)));
+ PhysicalInterfaces physicalInterfaces = hostRelatedInfoContainer
+ .getPhysicalInterfaceState(nodeId.getValue());
+ if (physicalInterfaces == null) {
+ physicalInterfaces = new PhysicalInterfaces();
+ hostRelatedInfoContainer.setPhysicalInterfaceStateOfHost(nodeId.getValue(), physicalInterfaces);
+ }
+
if (extInterfaces.get(nodeId) != null
&& extInterfaces.get(nodeId).getInterfaceName().equals(phIface.getInterfaceName())) {
phIface.setExternal(true);
extInterfaces.put(nodeId, new PhysicalInterfaceKey(iface.getName()));
- HostIdToInterfaceInfoMapper.getInstance()
- .addInterfaceInfo(nodeId.getValue(), HostIdToInterfaceInfoMapper.InterfaceType.PUBLIC,
+ physicalInterfaces
+ .addPhysicalInterfaceInfo(PhysicalInterfaces.PhysicalInterfaceType.PUBLIC,
phIface.getInterfaceName(), phIface.getAddress().get(0));
LOG.info("Interface {} is marked as public interface based on bundle configuration.",
iface.getName());
if (PUBLIC_INTERFACE.equals(iface.getDescription())) {
phIface.setExternal(true);
extInterfaces.put(nodeId, new PhysicalInterfaceKey(iface.getName()));
- HostIdToInterfaceInfoMapper.getInstance()
- .addInterfaceInfo(nodeId.getValue(), HostIdToInterfaceInfoMapper.InterfaceType.PUBLIC,
+ physicalInterfaces
+ .addPhysicalInterfaceInfo(PhysicalInterfaces.PhysicalInterfaceType.PUBLIC,
phIface.getInterfaceName(), phIface.getAddress().get(0));
LOG.info("Interface {} is marked as public interface based on HC configuration.",
iface.getName());
AddressEndpointWithLocation rEp = policyCtx.getAddrEpByKey().get(KeyFactory.addressEndpointKey(rEpKey));
if (ConfigUtil.getInstance().isLispOverlayEnabled()) {
- lispStateManager.configureEndPoint(rEp);
+ lispStateManager.processCreateEndPoint(rEp);
if (ConfigUtil.getInstance().isL3FlatEnabled()) {
flatOverlayManager.configureEndpointForFlatOverlay(rEp);
loopbackManager.createSimpleLoopbackIfNeeded(rEp);
public void removeForwardingForEndpoint(RendererEndpointKey rEpKey, PolicyContext policyCtx) {
AddressEndpointWithLocation rEp = policyCtx.getAddrEpByKey().get(KeyFactory.addressEndpointKey(rEpKey));
ExternalLocationCase rEpLoc = resolveAndValidateLocation(rEp);
+
+ if (ConfigUtil.getInstance().isLispOverlayEnabled()) {
+ lispStateManager.processDeleteEndpoint(rEp);
+ if (ConfigUtil.getInstance().isL3FlatEnabled()) {
+ flatOverlayManager.handleEndpointDeleteForFlatOverlay(rEp);
+ }
+ loopbackManager.handleEndpointDelete(rEp);
+ }
+
if (rEpLoc == null || Strings.isNullOrEmpty(rEpLoc.getExternalNodeConnector())) {
// nothing was created for endpoint therefore nothing is removed
return;
}
if (!Strings.isNullOrEmpty(rEpLoc.getExternalNode())) {
try {
- if (ConfigUtil.getInstance().isLispOverlayEnabled()) {
- lispStateManager.deleteLispConfigurationForEndpoint(rEp);
- loopbackManager.handleEndpointDelete(rEp);
-
- if (ConfigUtil.getInstance().isL3FlatEnabled()) {
- flatOverlayManager.handleEndpointDeleteForFlatOverlay(rEp);
- }
-
- }
ifaceManager.deleteBridgeDomainFromInterface(rEp).get();
LOG.debug("bridge-domain was deleted from interface for endpoint {}", rEp);
} catch (InterruptedException | ExecutionException e) {
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
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.test.CustomDataBrokerTest;
import org.opendaylight.groupbasedpolicy.util.IidFactory;
private final static String SOCKET = "socket1";
private InterfaceManager manager;
+ private FlatOverlayManager flatOverlayManager;
private MountedDataBrokerProvider mountedDataProviderMock;
private DataBroker mountPointDataBroker;
private DataBroker dataBroker;
@Before
public void init() throws Exception {
mountedDataProviderMock = Mockito.mock(MountedDataBrokerProvider.class);
+ flatOverlayManager = Mockito.mock(FlatOverlayManager.class);
mountPointDataBroker = getDataBroker();
setup(); // initialize new data broker for ODL data store
dataBroker = getDataBroker();
Mockito.when(mountedDataProviderMock.getDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
.thenReturn(Optional.of(mountPointDataBroker));
- manager = new InterfaceManager(mountedDataProviderMock, dataBroker);
+ manager = new InterfaceManager(mountedDataProviderMock, dataBroker, flatOverlayManager);
}
@Test
dataBroker = getDataBroker();
Mockito.when(mountedDataProviderMock.getDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
.thenReturn(Optional.of(mountPointDataBroker));
- ifaceManager = new InterfaceManager(mountedDataProviderMock, dataBroker);
+ lispStateManager = new LispStateManager(mountedDataProviderMock);
+ loopbackManager = new LoopbackManager(mountedDataProviderMock);
+ flatOverlayManager = new FlatOverlayManager(dataBroker, mountedDataProviderMock);
+ ifaceManager = new InterfaceManager(mountedDataProviderMock, dataBroker, flatOverlayManager);
aclManager = new AclManager(mountedDataProviderMock);
natManager = new NatManager(dataBroker, mountedDataProviderMock);
routingManager = new RoutingManager(dataBroker, mountedDataProviderMock);
bdManager = new BridgeDomainManagerImpl(mountPointDataBroker);
- lispStateManager = new LispStateManager(mountedDataProviderMock);
- loopbackManager = new LoopbackManager(mountedDataProviderMock);
- flatOverlayManager = new FlatOverlayManager(dataBroker, mountedDataProviderMock);
dhcpRelayHandler = new DhcpRelayHandler(dataBroker, mountedDataProviderMock);
fwManager = new ForwardingManager(ifaceManager, aclManager, natManager, routingManager, bdManager,
lispStateManager, loopbackManager, flatOverlayManager, dhcpRelayHandler, dataBroker);