public synchronized void deleteSubnetRouteFibEntryFromDS(String rd, String prefix, String vpnName){ fibManager.removeFibEntry(dataBroker, rd, prefix, null); List<VpnInstance> vpnsToImportRoute = getVpnsImportingMyRoute(vpnName); for (VpnInstance vpnInstance : vpnsToImportRoute) { String importingRd = vpnInstance.getIpv4Family().getRouteDistinguisher(); LOG.info("Deleting imported subnet route rd {} prefix {} from vpn {}", rd, prefix, vpnInstance.getVpnInstanceName()); fibManager.removeFibEntry(dataBroker, importingRd, prefix, null); } }
if (!Objects.equals(_description, other.getDescription())) { return false; if (!Objects.equals(_ipv4Family, other.getIpv4Family())) { return false; if (!Objects.equals(_ipv6Family, other.getIpv6Family())) { return false; if (!Objects.equals(_key, other.getKey())) { return false; if (!Objects.equals(_vpnInstanceName, other.getVpnInstanceName())) { return false; if (!e.getValue().equals(other.getAugmentation(e.getKey()))) { return false;
public VpnInstanceBuilder(VpnInstance base) { if (base.getKey() == null) { this._key = new VpnInstanceKey( base.getVpnInstanceName() ); this._vpnInstanceName = base.getVpnInstanceName(); } else { this._key = base.getKey(); this._vpnInstanceName = _key.getVpnInstanceName(); } this._description = base.getDescription(); this._ipv4Family = base.getIpv4Family(); this._ipv6Family = base.getIpv6Family(); if (base instanceof VpnInstanceImpl) { VpnInstanceImpl impl = (VpnInstanceImpl) base; if (!impl.augmentation.isEmpty()) { this.augmentation = new HashMap<>(impl.augmentation); } } else if (base instanceof AugmentationHolder) { @SuppressWarnings("unchecked") AugmentationHolder<org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance> casted =(AugmentationHolder<org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance>) base; if (!casted.augmentations().isEmpty()) { this.augmentation = new HashMap<>(casted.augmentations()); } } }
@Override public String apply(VpnInstance vpnInstance) { //return vpnInstance.getVpnInstanceName(); return vpnInstance.getIpv4Family().getRouteDistinguisher(); } };
@Override public String apply(VpnInstance vpnInstance) { return vpnInstance.getVpnInstanceName(); } };
private List<String> getExportRts(VpnInstance vpnInstance) { List<String> exportRts = new ArrayList<>(); VpnAfConfig vpnConfig = vpnInstance.getIpv4Family(); VpnTargets targets = vpnConfig.getVpnTargets(); List<VpnTarget> vpnTargets = targets.getVpnTarget(); for (VpnTarget target : vpnTargets) { if (target.getVrfRTType().equals(VpnTarget.VrfRTType.ExportExtcommunity)) { String rtValue = target.getVrfRTValue(); exportRts.add(rtValue); } } return exportRts; }
@Override public boolean apply(VpnInstance input) { return !input.getVpnInstanceName().equals(vpnName); } };
@Override protected void add(final InstanceIdentifier<VpnInstance> identifier, final VpnInstance value) { LOG.trace("Add VPN event key: {}, value: {}", identifier, value); final VpnAfConfig config = value.getIpv4Family(); final String rd = config.getRouteDistinguisher(); final String vpnName = value.getVpnInstanceName(); DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance(); dataStoreCoordinator.enqueueJob("VPN-" + vpnName, new AddVpnInstanceWorker(idManager, vpnInterfaceManager, dataBroker, value)); }
private String getRouteDistinguisher(String vpnName) { InstanceIdentifier<VpnInstance> id = InstanceIdentifier.builder(VpnInstances.class) .child(VpnInstance.class, new VpnInstanceKey(vpnName)).build(); Optional<VpnInstance> vpnInstance = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id); String rd = ""; if(vpnInstance.isPresent()) { VpnInstance instance = vpnInstance.get(); VpnAfConfig config = instance.getIpv4Family(); rd = config.getRouteDistinguisher(); } return rd; }
@Override public boolean apply(VpnInstance input) { return !input.getVpnInstanceName().equals(vpnName); } };
@Override public List<ListenableFuture<Void>> call() throws Exception { // If another renderer(for eg : CSS) needs to be supported, check can be performed here // to call the respective helpers. final VpnAfConfig config = vpnInstance.getIpv4Family(); final String rd = config.getRouteDistinguisher(); WriteTransaction writeConfigTxn = broker.newWriteOnlyTransaction(); WriteTransaction writeOperTxn = broker.newWriteOnlyTransaction(); addVpnInstance(vpnInstance, writeConfigTxn, writeOperTxn); CheckedFuture<Void, TransactionCommitFailedException> checkFutures = writeOperTxn.submit(); try { checkFutures.get(); } catch (InterruptedException | ExecutionException e) { LOG.error("Error creating vpn {} ", vpnInstance.getVpnInstanceName()); throw new RuntimeException(e.getMessage()); } List<ListenableFuture<Void>> futures = new ArrayList<>(); futures.add(writeConfigTxn.submit()); ListenableFuture<List<Void>> listenableFuture = Futures.allAsList(futures); if (rd != null) { Futures.addCallback(listenableFuture, new AddBgpVrfWorker(config , vpnInstance.getVpnInstanceName())); } return futures; } }
private String getRouteDistinguisher(String vpnName) { InstanceIdentifier<VpnInstance> id = InstanceIdentifier.builder(VpnInstances.class) .child(VpnInstance.class, new VpnInstanceKey(vpnName)).build(); Optional<VpnInstance> vpnInstance = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id); String rd = null; if(vpnInstance.isPresent()) { VpnInstance instance = vpnInstance.get(); VpnAfConfig config = instance.getIpv4Family(); rd = config.getRouteDistinguisher(); } return rd; }
private List<String> getRts(VpnInstance vpnInstance, VpnTarget.VrfRTType rtType) { String name = vpnInstance.getVpnInstanceName(); List<String> rts = new ArrayList<>(); VpnAfConfig vpnConfig = vpnInstance.getIpv4Family(); if (vpnConfig == null) { LOG.trace("vpn config is not available for {}", name); return rts; } VpnTargets targets = vpnConfig.getVpnTargets(); if (targets == null) { LOG.trace("vpn targets not available for {}", name); return rts; } List<VpnTarget> vpnTargets = targets.getVpnTarget(); if (vpnTargets == null) { LOG.trace("vpnTarget values not available for {}", name); return rts; } for (VpnTarget target : vpnTargets) { //TODO: Check for RT type is Both if(target.getVrfRTType().equals(rtType) || target.getVrfRTType().equals(VpnTarget.VrfRTType.Both)) { String rtValue = target.getVrfRTValue(); rts.add(rtValue); } } return rts; }
private String getRouteDistinguisher(String vpnName) { InstanceIdentifier<VpnInstance> id = InstanceIdentifier.builder(VpnInstances.class) .child(VpnInstance.class, new VpnInstanceKey(vpnName)).build(); Optional<VpnInstance> vpnInstance = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, id); String rd = ""; if(vpnInstance.isPresent()) { VpnInstance instance = vpnInstance.get(); VpnAfConfig config = instance.getIpv4Family(); rd = config.getRouteDistinguisher(); } return rd; }
void handleVpnsExportingRoutes(String vpnName, String vpnRd) { List<VpnInstance> vpnsToExportRoute = getVpnsExportingMyRoute(vpnName); for (VpnInstance vpn : vpnsToExportRoute) { String rd = vpn.getIpv4Family().getRouteDistinguisher(); List<VrfEntry> vrfEntries = VpnUtil.getAllVrfEntries(dataBroker, vpn.getIpv4Family().getRouteDistinguisher()); WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction(); if (vrfEntries != null) { for (String nh : nextHops) { if (route != null) { LOG.info("Importing subnet route fib entry rd {} prefix {} nexthop {} label {} to vpn {}", vpnRd, prefix, nh, label, vpn.getVpnInstanceName()); importSubnetRouteForNewVpn(rd, prefix, nh, (int)label, route, writeConfigTxn); } else { LOG.info("Importing fib entry rd {} prefix {} nexthop {} label {} to vpn {}", vpnRd, prefix, nh, label, vpn.getVpnInstanceName()); fibManager.addOrUpdateFibEntry(dataBroker, vpnRd, prefix, Arrays.asList(nh), (int)label, RouteOrigin.SELF_IMPORTED, writeConfigTxn); LOG.error("Exception occurred while importing route with prefix {} label {} nexthop {} from vpn {} to vpn {}", vrfEntry.getDestPrefix(), vrfEntry.getLabel(), vrfEntry.getNextHopAddressList(), vpn.getVpnInstanceName(), vpnName); LOG.info("No vrf entries to import from vpn {} with rd {}", vpn.getVpnInstanceName(), vpn.getIpv4Family().getRouteDistinguisher());
/** * Get RouterDistinguisher by VpnName * * @param vpnName Name of the VPN Instance * @return the Route-Distinguisher */ private String getRouteDistinguisher(String vpnName) { InstanceIdentifier<VpnInstance> id = InstanceIdentifier.builder(VpnInstances.class) .child(VpnInstance.class, new VpnInstanceKey(vpnName)).build(); Optional<VpnInstance> vpnInstance = MDSALDataStoreUtils.read(broker, LogicalDatastoreType.CONFIGURATION, id); String rd = ""; if (vpnInstance.isPresent()) { VpnInstance instance = vpnInstance.get(); VpnAfConfig config = instance.getIpv4Family(); rd = config.getRouteDistinguisher(); } return rd; }
@Override protected void remove(InstanceIdentifier<VpnInstance> identifier, VpnInstance del) { LOG.trace("Remove VPN event key: {}, value: {}", identifier, del); final String vpnName = del.getVpnInstanceName(); final String rd = del.getIpv4Family().getRouteDistinguisher(); final long vpnId = VpnUtil.getVpnId(dataBroker, vpnName); Optional<VpnInstanceOpDataEntry> vpnOpValue = null; //TODO(vpnteam): Entire code would need refactoring to listen only on the parent object - VPNInstance try { if ((rd != null) && (!rd.isEmpty())) { vpnOpValue = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getVpnInstanceOpDataIdentifier(rd)); } else { vpnOpValue = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getVpnInstanceOpDataIdentifier(vpnName)); } } catch (Exception e) { LOG.error("Exception when attempting to retrieve VpnInstanceOpDataEntry for VPN {}. ", vpnName, e); return; } if (vpnOpValue == null || !vpnOpValue.isPresent()) { LOG.error("Unable to retrieve VpnInstanceOpDataEntry for VPN {}. ", vpnName); return; } DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance(); dataStoreCoordinator.enqueueJob("VPN-" + vpnName, new DeleteVpnInstanceWorker(idManager, dataBroker, del)); }
/** * Get VPN Route Distinguisher from VPN Instance Configuration * * @param broker dataBroker service reference * @param vpnName Name of the VPN * @return the route-distinguisher of the VPN */ public static String getVpnRdFromVpnInstanceConfig(DataBroker broker, String vpnName) { InstanceIdentifier<VpnInstance> id = InstanceIdentifier.builder(VpnInstances.class) .child(VpnInstance.class, new VpnInstanceKey(vpnName)).build(); Optional<VpnInstance> vpnInstance = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, id); String rd = null; if (vpnInstance.isPresent()) { VpnInstance instance = vpnInstance.get(); VpnAfConfig config = instance.getIpv4Family(); rd = config.getRouteDistinguisher(); } return rd; }
VpnInstance value) { LOG.trace("VPN Instance key: {}, value: {}", identifier, value); VpnAfConfig config = value.getIpv4Family(); String rd = config.getRouteDistinguisher(); long vpnId = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, value.getVpnInstanceName()); LOG.trace("VPN instance to ID generated."); org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance vpnInstanceToVpnId = VpnUtil.getVpnInstanceToVpnId(value.getVpnInstanceName(), vpnId, (rd != null) ? rd : value.getVpnInstanceName()); VpnUtil.getVpnInstanceToVpnIdIdentifier(value.getVpnInstanceName()), vpnInstanceToVpnId, DEFAULT_CALLBACK); VpnUtil.getVpnInstanceOpDataIdentifier(value.getVpnInstanceName()), VpnUtil.getVpnInstanceOpDataBuilder(value.getVpnInstanceName(), vpnId), DEFAULT_CALLBACK); List<VpnInterface> vpnInterfaces = optionalVpnInterfaces.get().getVpnInterface(); for(VpnInterface vpnInterface : vpnInterfaces) { if(vpnInterface.getVpnInstanceName().equals(value.getVpnInstanceName())) { LOG.debug("VpnInterface {} will be added from VPN {}", vpnInterface.getName(), value.getVpnInstanceName()); vpnInterfaceManager.add( VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getName()), vpnInterface);
String vpnRd = vpn.getIpv4Family().getRouteDistinguisher(); if (vpnRd != null) { LOG.debug("Exporting route with rd {} prefix {} nexthop {} label {} to VPN {}", vpnRd, nextHop.getIpAddress(), nextHopIp, label, vpn);