use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class NeutronvpnManager method createVpn.
/**
* Performs the creation of a Neutron L3VPN, associating the new VPN to the
* specified Neutron Networks and Routers.
*
* @param vpnId Uuid of the VPN tp be created
* @param name Representative name of the new VPN
* @param tenantId Uuid of the Tenant under which the VPN is going to be created
* @param rdList Route-distinguisher for the VPN
* @param irtList A list of Import Route Targets
* @param ertList A list of Export Route Targets
* @param routerIdsList ist of neutron router Id to associate with created VPN
* @param networkList UUID of the neutron network the VPN may be associated to
* @param isL2Vpn True if VPN Instance is of type L2, false if L3
* @param l3vni L3VNI for the VPN Instance using VxLAN as the underlay
* @throws Exception if association of L3VPN failed
*/
public void createVpn(Uuid vpnId, String name, Uuid tenantId, List<String> rdList, List<String> irtList, List<String> ertList, @Nullable List<Uuid> routerIdsList, @Nullable List<Uuid> networkList, boolean isL2Vpn, long l3vni) throws Exception {
IpVersionChoice ipVersChoices = IpVersionChoice.UNDEFINED;
if (routerIdsList != null && !routerIdsList.isEmpty()) {
for (Uuid routerId : routerIdsList) {
IpVersionChoice vers = neutronvpnUtils.getIpVersionChoicesFromRouterUuid(routerId);
ipVersChoices = ipVersChoices.addVersion(vers);
}
}
updateVpnInstanceNode(vpnId, rdList, irtList, ertList, isL2Vpn, l3vni, ipVersChoices);
// Please note that router and networks will be filled into VPNMaps
// by subsequent calls here to associateRouterToVpn and
// associateNetworksToVpn
updateVpnMaps(vpnId, name, null, tenantId, null);
LOG.debug("Created L3VPN with ID {}, name {}, tenantID {}, RDList {}, iRTList {}, eRTList{}, routerIdsList {}, " + "networkList {}", vpnId.getValue(), name, tenantId, rdList, irtList, ertList, routerIdsList, networkList);
if (routerIdsList != null && !routerIdsList.isEmpty()) {
for (Uuid routerId : routerIdsList) {
associateRouterToVpn(vpnId, routerId);
}
}
if (networkList != null) {
List<String> failStrings = associateNetworksToVpn(vpnId, networkList);
if (!failStrings.isEmpty()) {
LOG.error("VPN {} association to networks failed for networks: {}. ", vpnId.getValue(), failStrings);
throw new Exception(failStrings.toString());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnForSubnet.
@Nullable
private Subnetmap updateVpnForSubnet(Uuid oldVpnId, Uuid newVpnId, Uuid subnet, boolean isBeingAssociated) {
LOG.debug("Moving subnet {} from oldVpn {} to newVpn {} ", subnet.getValue(), oldVpnId.getValue(), newVpnId.getValue());
Uuid networkUuid = neutronvpnUtils.getSubnetmap(subnet).getNetworkId();
Network network = neutronvpnUtils.getNeutronNetwork(networkUuid);
boolean netIsExternal = NeutronvpnUtils.getIsExternal(network);
Uuid vpnExtUuid = netIsExternal ? neutronvpnUtils.getInternetvpnUuidBoundToSubnetRouter(subnet) : null;
Subnetmap sn = updateSubnetNode(subnet, null, newVpnId, vpnExtUuid);
if (sn == null) {
LOG.error("Updating subnet {} with newVpn {} failed", subnet.getValue(), newVpnId.getValue());
return sn;
}
/* vpnExtUuid will contain the value only on if the subnet is V6 and it is already been
* associated with internet BGP-VPN.
*/
if (vpnExtUuid != null) {
/* Update V6 Internet default route match with new VPN metadata.
* isBeingAssociated = true means oldVpnId is same as routerId
* isBeingAssociated = false means newVpnId is same as routerId
*/
if (isBeingAssociated) {
neutronvpnUtils.updateVpnInstanceWithFallback(oldVpnId, vpnExtUuid, true);
} else {
neutronvpnUtils.updateVpnInstanceWithFallback(newVpnId, vpnExtUuid, true);
}
}
// Update Router Interface first synchronously.
// CAUTION: Please DONOT make the router interface VPN Movement as an asynchronous commit again !
ListenableFuture<?> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> updateVpnInterface(newVpnId, oldVpnId, neutronvpnUtils.getNeutronPort(sn.getRouterInterfacePortId()), isBeingAssociated, true, tx, false));
Futures.addCallback(future, new FutureCallback<Object>() {
@Override
public void onSuccess(Object result) {
// Check for ports on this subnet and update association of
// corresponding vpn-interfaces to external vpn
List<Uuid> portList = sn.getPortList();
if (portList != null) {
for (Uuid port : portList) {
LOG.debug("Updating vpn-interface for port {} isBeingAssociated {}", port.getValue(), isBeingAssociated);
jobCoordinator.enqueueJob("PORT-" + port.getValue(), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> updateVpnInterface(newVpnId, oldVpnId, neutronvpnUtils.getNeutronPort(port), isBeingAssociated, false, tx, false))));
}
}
}
@Override
public void onFailure(Throwable throwable) {
LOG.error("Failed to update router interface {} in subnet {} from oldVpnId {} to newVpnId {}, " + "returning", sn.getRouterInterfacePortId().getValue(), subnet.getValue(), oldVpnId, newVpnId, throwable);
}
}, MoreExecutors.directExecutor());
return sn;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class NeutronvpnManager method addInterVpnRoutes.
/**
* Creates the corresponding static routes in the specified VPN. These static routes must be point to an
* InterVpnLink endpoint and the specified VPN must be the other end of the InterVpnLink. Otherwise the
* route will be ignored.
*
* @param vpnName the VPN identifier
* @param interVpnLinkRoutes The list of static routes
* @param nexthopsXinterVpnLinks A Map with the correspondence nextHop-InterVpnLink
*/
public void addInterVpnRoutes(Uuid vpnName, List<Routes> interVpnLinkRoutes, HashMap<String, InterVpnLink> nexthopsXinterVpnLinks) {
for (Routes route : interVpnLinkRoutes) {
String nexthop = route.getNexthop().stringValue();
String destination = route.getDestination().stringValue();
InterVpnLink interVpnLink = nexthopsXinterVpnLinks.get(nexthop);
if (isNexthopTheOtherVpnLinkEndpoint(nexthop, vpnName.getValue(), interVpnLink)) {
AddStaticRouteInput rpcInput = new AddStaticRouteInputBuilder().setDestination(destination).setNexthop(nexthop).setVpnInstanceName(vpnName.getValue()).build();
Future<RpcResult<AddStaticRouteOutput>> labelOuputFtr = vpnRpcService.addStaticRoute(rpcInput);
RpcResult<AddStaticRouteOutput> rpcResult;
try {
rpcResult = labelOuputFtr.get();
if (rpcResult.isSuccessful()) {
LOG.debug("Label generated for destination {} is: {}", destination, rpcResult.getResult().getLabel());
} else {
LOG.error("RPC call to add a static Route to {} with nexthop {} returned with errors {}", destination, nexthop, rpcResult.getErrors());
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error happened while invoking addStaticRoute RPC for nexthop {} with destination {} " + "for VPN {}", nexthop, destination, vpnName.getValue(), e);
}
} else {
// Any other case is a fault.
LOG.warn("route with destination {} and nexthop {} does not apply to any InterVpnLink", route.getDestination().stringValue(), nexthop);
continue;
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class NeutronvpnManager method associateExtNetworkToVpn.
private boolean associateExtNetworkToVpn(@NonNull Uuid vpnId, @NonNull Network extNet, VpnInstance.BgpvpnType bgpVpnType) {
if (!addExternalNetworkToVpn(extNet, vpnId)) {
return false;
}
if (!bgpVpnType.equals(VpnInstance.BgpvpnType.InternetBGPVPN)) {
LOG.info("associateExtNetworkToVpn: External network {} is associated to VPN {}." + "Hence set vpnInstance type to {} from {} ", extNet.key().getUuid().getValue(), vpnId.getValue(), VpnInstance.BgpvpnType.InternetBGPVPN.getName(), VpnInstance.BgpvpnType.BGPVPN.getName());
neutronvpnUtils.updateVpnInstanceWithBgpVpnType(VpnInstance.BgpvpnType.InternetBGPVPN, vpnId);
}
// Update VpnMap with ext-nw is needed first before processing V6 internet default fallback flows
List<Uuid> extNwList = Collections.singletonList(extNet.key().getUuid());
updateVpnMaps(vpnId, null, null, null, extNwList);
IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
for (Uuid snId : neutronvpnUtils.getPrivateSubnetsToExport(extNet, vpnId)) {
Subnetmap sm = neutronvpnUtils.getSubnetmap(snId);
if (sm == null) {
LOG.error("associateExtNetworkToVpn: can not find subnet with Id {} in ConfigDS", snId.getValue());
continue;
}
IpVersionChoice ipVers = NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp());
if (ipVers.isIpVersionChosen(IpVersionChoice.IPV4)) {
continue;
}
if (ipVers.isIpVersionChosen(IpVersionChoice.IPV6)) {
updateVpnInternetForSubnet(sm, vpnId, true);
}
if (!ipVersion.isIpVersionChosen(ipVers)) {
ipVersion = ipVersion.addVersion(ipVers);
}
}
if (ipVersion != IpVersionChoice.UNDEFINED) {
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), IpVersionChoice.IPV6, true);
LOG.info("associateExtNetworkToVpn: add IPv6 Internet default route in VPN {}", vpnId.getValue());
neutronvpnUtils.updateVpnInstanceWithFallback(/*routerId*/
null, vpnId, true);
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route in project netvirt by opendaylight.
the class NeutronRouterChangeListener method update.
@Override
public void update(InstanceIdentifier<Router> identifier, Router original, Router update) {
LOG.trace("Updating Router : key: {}, original value={}, update value={}", identifier, original, update);
if (Objects.equals(original, update)) {
return;
}
neutronvpnUtils.addToRouterCache(update);
Uuid routerId = update.getUuid();
neutronvpnUtils.addToRouterCache(update);
Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
// internal vpn always present in case external vpn not found
if (vpnId == null) {
vpnId = routerId;
}
List<Routes> oldRoutes = new ArrayList<>(original.nonnullRoutes().values());
List<Routes> newRoutes = new ArrayList<>(update.nonnullRoutes().values());
if (!oldRoutes.equals(newRoutes)) {
Iterator<Routes> iterator = newRoutes.iterator();
while (iterator.hasNext()) {
Routes route = iterator.next();
if (oldRoutes.remove(route)) {
iterator.remove();
}
}
LOG.debug("Updating Router : AddRoutes {}, DeleteRoutes {}", newRoutes, oldRoutes);
if (!oldRoutes.isEmpty()) {
handleChangedRoutes(vpnId, oldRoutes, NwConstants.DEL_FLOW);
}
// A better fix/design need to be thought to avoid race condition
try {
// sleep for 2sec
Thread.sleep(2000);
} catch (java.lang.InterruptedException e) {
LOG.error("Exception while sleeping", e);
}
if (!newRoutes.isEmpty()) {
handleChangedRoutes(vpnId, newRoutes, NwConstants.ADD_FLOW);
}
}
jobCoordinator.enqueueJob(update.getUuid().toString(), () -> {
nvpnNatManager.handleExternalNetworkForRouter(original, update);
return Collections.emptyList();
});
gwMacResolver.sendArpRequestsToExtGateways(update);
}
Aggregations