use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState in project netvirt by opendaylight.
the class InterVpnLinkTestCatalog method build.
static InterVpnLinkDataComposite build(String ivpnLinkName, String vpn1Name, String vpn1IpAddr, String vpn2Name, String vpn2IpAddr, boolean bgpFlag, boolean staticFlag, boolean connectedFlag, List<BigInteger> vpn1Dpns, long vpn1LportTag, List<BigInteger> vpn2Dpns, long vpn2LportTag, InterVpnLinkState.State state, Optional<String> errMsg) {
FirstEndpoint firstEndpoint = new FirstEndpointBuilder().setVpnUuid(new Uuid(vpn1Name)).setIpAddress(new Ipv4Address(vpn1IpAddr)).build();
SecondEndpoint secondEndpoint = new SecondEndpointBuilder().setVpnUuid(new Uuid(vpn2Name)).setIpAddress(new Ipv4Address(vpn2IpAddr)).build();
InterVpnLink ivpnLinkCfg = new InterVpnLinkBuilder().setName(ivpnLinkName).setFirstEndpoint(firstEndpoint).setSecondEndpoint(secondEndpoint).setBgpRoutesLeaking(bgpFlag).setStaticRoutesLeaking(staticFlag).setConnectedRoutesLeaking(connectedFlag).build();
FirstEndpointState firstEndpointState = new FirstEndpointStateBuilder().setVpnUuid(new Uuid(vpn1Name)).setLportTag(vpn1LportTag).setDpId(vpn1Dpns).build();
SecondEndpointState secondEndpointState = new SecondEndpointStateBuilder().setVpnUuid(new Uuid(vpn2Name)).setLportTag(vpn2LportTag).setDpId(vpn2Dpns).build();
InterVpnLinkState ivpnLinkState = new InterVpnLinkStateBuilder().setInterVpnLinkName(ivpnLinkName).setState(state).setErrorDescription(errMsg.or("")).setFirstEndpointState(firstEndpointState).setSecondEndpointState(secondEndpointState).build();
return new InterVpnLinkDataComposite(ivpnLinkCfg, ivpnLinkState);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState in project netvirt by opendaylight.
the class InterVpnLinkUtil method updateInterVpnLinkState.
/**
* Updates inter-VPN link state.
*
* @param broker dataBroker service reference
* @param vpnLinkName The name of the InterVpnLink
* @param state Sets the state of the InterVpnLink to Active or Error
* @param newFirstEndpointState Updates the lportTag and/or DPNs of the 1st endpoint of the InterVpnLink
* @param newSecondEndpointState Updates the lportTag and/or DPNs of the 2nd endpoint of the InterVpnLink
* @param interVpnLinkCache the InterVpnLinkCache
*/
public static void updateInterVpnLinkState(DataBroker broker, String vpnLinkName, InterVpnLinkState.State state, FirstEndpointState newFirstEndpointState, SecondEndpointState newSecondEndpointState, InterVpnLinkCache interVpnLinkCache) {
Optional<InterVpnLinkState> optOldVpnLinkState = getInterVpnLinkState(broker, vpnLinkName);
if (optOldVpnLinkState.isPresent()) {
InterVpnLinkState newVpnLinkState = new InterVpnLinkStateBuilder(optOldVpnLinkState.get()).setState(state).setFirstEndpointState(newFirstEndpointState).setSecondEndpointState(newSecondEndpointState).build();
VpnUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION, InterVpnLinkUtil.getInterVpnLinkStateIid(vpnLinkName), newVpnLinkState);
interVpnLinkCache.addInterVpnLinkStateToCaches(newVpnLinkState);
} else {
InterVpnLinkState newIVpnLinkState = new InterVpnLinkStateBuilder().setKey(new InterVpnLinkStateKey(vpnLinkName)).setInterVpnLinkName(vpnLinkName).setFirstEndpointState(newFirstEndpointState).setSecondEndpointState(newSecondEndpointState).setState(InterVpnLinkState.State.Active).build();
VpnUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, InterVpnLinkUtil.getInterVpnLinkStateIid(vpnLinkName), newIVpnLinkState);
interVpnLinkCache.addInterVpnLinkStateToCaches(newIVpnLinkState);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState in project netvirt by opendaylight.
the class InterVpnLinkListener method remove.
@Override
protected void remove(InstanceIdentifier<InterVpnLink> identifier, InterVpnLink del) {
LOG.debug("Reacting to InterVpnLink {} removal", del.getName());
// Remove learnt routes
// Remove entries in the LPortDispatcher table
// Remove the corresponding entries in InterVpnLinkState
// For each endpoint, remove all routes that have been learnt by intervpnLink
String vpn1Uuid = del.getFirstEndpoint().getVpnUuid().getValue();
String rd1 = VpnUtil.getVpnRd(dataBroker, vpn1Uuid);
LOG.debug("Removing leaked routes in VPN {} rd={}", vpn1Uuid, rd1);
VpnUtil.removeVrfEntriesByOrigin(dataBroker, rd1, RouteOrigin.INTERVPN);
List<VrfEntry> vrfEntriesSecondEndpoint = VpnUtil.findVrfEntriesByNexthop(dataBroker, rd1, del.getSecondEndpoint().getIpAddress().getValue());
String vpn2Uuid = del.getSecondEndpoint().getVpnUuid().getValue();
String rd2 = VpnUtil.getVpnRd(dataBroker, vpn2Uuid);
LOG.debug("Removing leaked routes in VPN {} rd={}", vpn2Uuid, rd2);
VpnUtil.removeVrfEntriesByOrigin(dataBroker, rd2, RouteOrigin.INTERVPN);
List<VrfEntry> vrfEntriesFirstEndpoint = VpnUtil.findVrfEntriesByNexthop(dataBroker, rd2, del.getFirstEndpoint().getIpAddress().getValue());
Optional<InterVpnLinkState> optIVpnLinkState = InterVpnLinkUtil.getInterVpnLinkState(dataBroker, del.getName());
if (optIVpnLinkState.isPresent()) {
InterVpnLinkState interVpnLinkState = optIVpnLinkState.get();
boolean isVpnFirstEndPoint = true;
if (interVpnLinkState.getFirstEndpointState() != null) {
Long firstEndpointLportTag = interVpnLinkState.getFirstEndpointState().getLportTag();
removeVpnLinkEndpointFlows(del, vpn2Uuid, rd1, interVpnLinkState.getSecondEndpointState().getDpId(), firstEndpointLportTag.intValue(), del.getFirstEndpoint().getIpAddress().getValue(), vrfEntriesSecondEndpoint, isVpnFirstEndPoint);
} else {
LOG.info("Could not get first endpoint state attributes for InterVpnLink {}", del.getName());
}
isVpnFirstEndPoint = false;
if (interVpnLinkState.getSecondEndpointState() != null) {
Long secondEndpointLportTag = interVpnLinkState.getSecondEndpointState().getLportTag();
removeVpnLinkEndpointFlows(del, vpn1Uuid, rd2, interVpnLinkState.getFirstEndpointState().getDpId(), secondEndpointLportTag.intValue(), del.getSecondEndpoint().getIpAddress().getValue(), vrfEntriesFirstEndpoint, isVpnFirstEndPoint);
} else {
LOG.info("Could not get second endpoint state attributes for InterVpnLink {}", del.getName());
}
}
VpnUtil.removeVrfEntries(dataBroker, rd1, vrfEntriesSecondEndpoint);
VpnUtil.removeVrfEntries(dataBroker, rd2, vrfEntriesFirstEndpoint);
VpnUtil.withdrawRoutes(bgpManager, rd1, vrfEntriesSecondEndpoint);
VpnUtil.withdrawRoutes(bgpManager, rd2, vrfEntriesFirstEndpoint);
// Release idManager with LPortTag associated to endpoints
LOG.debug("Releasing InterVpnLink {} endpoints LportTags", del.getName());
InterVpnLinkKey key = del.getKey();
Uuid firstEndpointVpnUuid = del.getFirstEndpoint().getVpnUuid();
Uuid secondEndpointVpnUuid = del.getSecondEndpoint().getVpnUuid();
releaseVpnLinkLPortTag(key.getName() + firstEndpointVpnUuid.getValue());
releaseVpnLinkLPortTag(key.getName() + secondEndpointVpnUuid.getValue());
// Routes with nextHop pointing to an end-point of the inter-vpn-link are populated into FIB table.
// The action in that case is a nx_resubmit to LPortDispatcher table. This is done in FibManager.
// At this point. we need to check if is there any entry in FIB table pointing to LPortDispatcher table.
// Remove it in that case.
// Removing the InterVpnLinkState
InstanceIdentifier<InterVpnLinkState> interVpnLinkStateIid = InterVpnLinkUtil.getInterVpnLinkStateIid(del.getName());
VpnUtil.delete(dataBroker, LogicalDatastoreType.CONFIGURATION, interVpnLinkStateIid);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState in project netvirt by opendaylight.
the class InterVpnLinkUtil method leakRoute.
/**
* Leaks a route from one VPN to another. By default, the origin for this leaked route is INTERVPN.
*
* @param broker dataBroker service reference
* @param bgpManager Used to advertise routes to the BGP Router
* @param interVpnLink Reference to the object that holds the info about the link between the 2 VPNs
* @param srcVpnUuid UUID of the VPN that has the route that is going to be leaked to the other VPN
* @param dstVpnUuid UUID of the VPN that is going to receive the route
* @param prefix Prefix of the route
* @param label Label of the route in the original VPN
*/
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public static void leakRoute(DataBroker broker, IBgpManager bgpManager, InterVpnLink interVpnLink, String srcVpnUuid, String dstVpnUuid, String prefix, Long label) {
Preconditions.checkNotNull(interVpnLink);
// The source VPN must participate in the InterVpnLink
Preconditions.checkArgument(interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(srcVpnUuid) || interVpnLink.getSecondEndpoint().getVpnUuid().getValue().equals(srcVpnUuid), "The source VPN {} does not participate in the interVpnLink {}", srcVpnUuid, interVpnLink.getName());
// The destination VPN must participate in the InterVpnLink
Preconditions.checkArgument(interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(dstVpnUuid) || interVpnLink.getSecondEndpoint().getVpnUuid().getValue().equals(dstVpnUuid), "The destination VPN {} does not participate in the interVpnLink {}", dstVpnUuid, interVpnLink.getName());
boolean destinationIs1stEndpoint = interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(dstVpnUuid);
String endpointIp = destinationIs1stEndpoint ? interVpnLink.getSecondEndpoint().getIpAddress().getValue() : interVpnLink.getFirstEndpoint().getIpAddress().getValue();
VrfEntry newVrfEntry = FibHelper.getVrfEntryBuilder(prefix, label, endpointIp, RouteOrigin.INTERVPN, null).build();
String dstVpnRd = VpnUtil.getVpnRd(broker, dstVpnUuid);
InstanceIdentifier<VrfEntry> newVrfEntryIid = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(dstVpnRd)).child(VrfEntry.class, new VrfEntryKey(newVrfEntry.getDestPrefix())).build();
VpnUtil.asyncWrite(broker, LogicalDatastoreType.CONFIGURATION, newVrfEntryIid, newVrfEntry);
// Finally, route is advertised it to the DC-GW. But while in the FibEntries the nexthop is the other
// endpoint's IP, in the DC-GW the nexthop for those prefixes are the IPs of those DPNs where the target
// VPN has been instantiated
Optional<InterVpnLinkState> optVpnLinkState = getInterVpnLinkState(broker, interVpnLink.getName());
if (optVpnLinkState.isPresent()) {
InterVpnLinkState vpnLinkState = optVpnLinkState.get();
List<BigInteger> dpnIdList = destinationIs1stEndpoint ? vpnLinkState.getFirstEndpointState().getDpId() : vpnLinkState.getSecondEndpointState().getDpId();
List<String> nexthops = new ArrayList<>();
for (BigInteger dpnId : dpnIdList) {
nexthops.add(InterfaceUtils.getEndpointIpAddressForDPN(broker, dpnId));
}
try {
LOG.debug("Advertising route in VPN={} [prefix={} label={} nexthops={}] to DC-GW", dstVpnRd, newVrfEntry.getDestPrefix(), label.intValue(), nexthops);
bgpManager.advertisePrefix(dstVpnRd, null, /*macAddress*/
newVrfEntry.getDestPrefix(), nexthops, VrfEntry.EncapType.Mplsgre, label.intValue(), 0, /*l3vni*/
0, /*l2vni*/
null);
} catch (Exception ex) {
LOG.error("Could not advertise prefix {} with label {} to VPN rd={}", newVrfEntry.getDestPrefix(), label.intValue(), dstVpnRd, ex);
}
} else {
LOG.warn("Error when advertising leaked routes: Could not find State for InterVpnLink={}", interVpnLink.getName());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState in project netvirt by opendaylight.
the class NeutronRouterChangeListener method handleChangedRoutes.
private void handleChangedRoutes(Uuid vpnName, List<Routes> routes, int addedOrRemoved) {
// Some routes may point to an InterVpnLink's endpoint, lets treat them differently
List<Routes> interVpnLinkRoutes = new ArrayList<>();
List<Routes> otherRoutes = new ArrayList<>();
HashMap<String, InterVpnLink> nexthopsXinterVpnLinks = new HashMap<>();
for (Routes route : routes) {
String nextHop = String.valueOf(route.getNexthop().getValue());
// Nexthop is another VPN?
Optional<InterVpnLink> interVpnLink = neutronvpnUtils.getInterVpnLinkByEndpointIp(nextHop);
if (interVpnLink.isPresent()) {
Optional<InterVpnLinkState> interVpnLinkState = neutronvpnUtils.getInterVpnLinkState(interVpnLink.get().getName());
if (interVpnLinkState.isPresent() && interVpnLinkState.get().getState() == InterVpnLinkState.State.Active) {
interVpnLinkRoutes.add(route);
nexthopsXinterVpnLinks.put(nextHop, interVpnLink.get());
} else {
LOG.error("Failed installing route to {}. Reason: InterVPNLink {} is not Active", String.valueOf(route.getDestination().getValue()), interVpnLink.get().getName());
}
} else {
otherRoutes.add(route);
}
}
if (addedOrRemoved == NwConstants.ADD_FLOW) {
nvpnManager.addInterVpnRoutes(vpnName, interVpnLinkRoutes, nexthopsXinterVpnLinks);
nvpnManager.updateVpnInterfaceWithExtraRouteAdjacency(vpnName, otherRoutes);
} else {
nvpnManager.removeAdjacencyforExtraRoute(vpnName, otherRoutes);
nvpnManager.removeInterVpnRoutes(vpnName, interVpnLinkRoutes, nexthopsXinterVpnLinks);
}
}
Aggregations