- //TODO: Add VRF to BGP
- //public void addVrf(String rd, Collection<String> importRts, Collection<String> exportRts)
- VpnAfConfig config = value.getIpv4Family();
- String rd = config.getRouteDistinguisher();
- List<String> importRts = Arrays.asList(config.getImportRoutePolicy().split(","));
- List<String> exportRts = Arrays.asList(config.getExportRoutePolicy().split(","));
- try {
- bgpManager.addVrf(rd, importRts, exportRts);
- } catch(Exception e) {
- LOG.error("Exception when adding VRF to BGP", e);
+
+ if(rd == null) {
+ syncWrite(LogicalDatastoreType.OPERATIONAL,
+ VpnUtil.getVpnInstanceOpDataIdentifier(value.getVpnInstanceName()),
+ VpnUtil.getVpnInstanceOpDataBuilder(value.getVpnInstanceName(), vpnId), DEFAULT_CALLBACK);
+
+ } else {
+ syncWrite(LogicalDatastoreType.OPERATIONAL,
+ VpnUtil.getVpnInstanceOpDataIdentifier(rd),
+ VpnUtil.getVpnInstanceOpDataBuilder(rd, vpnId), DEFAULT_CALLBACK);
+
+ List<VpnTarget> vpnTargetList = config.getVpnTargets().getVpnTarget();
+
+ List<String> ertList = new ArrayList<String>();
+ List<String> irtList = new ArrayList<String>();
+
+ for (VpnTarget vpnTarget : vpnTargetList) {
+ if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ExportExtcommunity) {
+ ertList.add(vpnTarget.getVrfRTValue());
+ }
+ if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ImportExtcommunity) {
+ irtList.add(vpnTarget.getVrfRTValue());
+ }
+ if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.Both) {
+ ertList.add(vpnTarget.getVrfRTValue());
+ irtList.add(vpnTarget.getVrfRTValue());
+ }
+ }
+
+ try {
+ bgpManager.addVrf(rd, irtList, ertList);
+ } catch(Exception e) {
+ LOG.error("Exception when adding VRF to BGP", e);
+ }
+ }
+ //Try to add up vpn Interfaces if already in Operational Datastore
+ LOG.trace("Trying to add the vpn interfaces -1.");
+ InstanceIdentifier<VpnInterfaces> vpnInterfacesId = InstanceIdentifier.builder(VpnInterfaces.class).build();
+ Optional<VpnInterfaces> optionalVpnInterfaces = read(LogicalDatastoreType.CONFIGURATION, vpnInterfacesId);
+
+ if(optionalVpnInterfaces.isPresent()) {
+ 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);
+
+ }
+ }