+ } catch (Exception e) {
+ LOG.error("updatePrefixesForDPN {} in vpn {} failed", dpnId, vpnInstance.getVpnInstanceName(), e);
+ }
+ }
+ }
+ }
+
+ InstanceIdentifier<DpnVpninterfacesList> getRouterDpnId(String routerName, BigInteger dpnId) {
+ return InstanceIdentifier.builder(NeutronRouterDpns.class)
+ .child(RouterDpnList.class, new RouterDpnListKey(routerName))
+ .child(DpnVpninterfacesList.class, new DpnVpninterfacesListKey(dpnId)).build();
+ }
+
+ InstanceIdentifier<RouterDpnList> getRouterId(String routerName) {
+ return InstanceIdentifier.builder(NeutronRouterDpns.class)
+ .child(RouterDpnList.class, new RouterDpnListKey(routerName)).build();
+ }
+
+ protected void addToNeutronRouterDpnsMap(String routerName, String vpnInterfaceName) {
+ BigInteger dpId = InterfaceUtils.getDpnForInterface(interfaceManager, vpnInterfaceName);
+ if(dpId.equals(BigInteger.ZERO)) {
+ LOG.warn("Could not retrieve dp id for interface {} to handle router {} association model", vpnInterfaceName, routerName);
+ return;
+ }
+ InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
+
+ Optional<DpnVpninterfacesList> optionalRouterDpnList = VpnUtil.read(broker, LogicalDatastoreType
+ .CONFIGURATION, routerDpnListIdentifier);
+ RouterInterfaces routerInterface = new RouterInterfacesBuilder().setKey(new RouterInterfacesKey(vpnInterfaceName)).setInterface(vpnInterfaceName).build();
+ if (optionalRouterDpnList.isPresent()) {
+ MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, routerDpnListIdentifier.child(
+ RouterInterfaces.class, new RouterInterfacesKey(vpnInterfaceName)), routerInterface);
+ } else {
+ MDSALUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION,
+ getRouterId(routerName),
+ new RouterDpnListBuilder().setRouterId(routerName).build());
+ //VpnToDpnListBuilder vpnToDpnList = new VpnToDpnListBuilder().setDpnId(dpnId);
+ DpnVpninterfacesListBuilder dpnVpnList = new DpnVpninterfacesListBuilder().setDpnId(dpId);
+ List<RouterInterfaces> routerInterfaces = new ArrayList<>();
+ routerInterfaces.add(routerInterface);
+ MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, routerDpnListIdentifier,
+ dpnVpnList.setRouterInterfaces(routerInterfaces).build());
+ }
+ }
+
+ protected void removeFromNeutronRouterDpnsMap(String routerName, String vpnInterfaceName) {
+ BigInteger dpId = InterfaceUtils.getDpnForInterface(interfaceManager, vpnInterfaceName);
+ if(dpId.equals(BigInteger.ZERO)) {
+ LOG.warn("Could not retrieve dp id for interface {} to handle router {} dissociation model", vpnInterfaceName, routerName);
+ return;
+ }
+ InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
+ Optional<DpnVpninterfacesList> optionalRouterDpnList = VpnUtil.read(broker, LogicalDatastoreType
+ .CONFIGURATION, routerDpnListIdentifier);
+ if (optionalRouterDpnList.isPresent()) {
+ List<RouterInterfaces> routerInterfaces = optionalRouterDpnList.get().getRouterInterfaces();
+ RouterInterfaces routerInterface = new RouterInterfacesBuilder().setKey(new RouterInterfacesKey(vpnInterfaceName)).setInterface(vpnInterfaceName).build();
+
+ if (routerInterfaces != null && routerInterfaces.remove(routerInterface)) {
+ if (routerInterfaces.isEmpty()) {
+ MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, routerDpnListIdentifier);
+ } else {
+ MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, routerDpnListIdentifier.child(
+ RouterInterfaces.class,
+ new RouterInterfacesKey(vpnInterfaceName)));
+ }
+ }
+ }
+ }
+
+ protected void removeFromNeutronRouterDpnsMap(String routerName, String vpnInterfaceName,BigInteger dpId) {
+ if(dpId.equals(BigInteger.ZERO)) {
+ LOG.warn("Could not retrieve dp id for interface {} to handle router {} dissociation model", vpnInterfaceName, routerName);
+ return;
+ }
+ InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
+ Optional<DpnVpninterfacesList> optionalRouterDpnList = VpnUtil.read(broker, LogicalDatastoreType
+ .CONFIGURATION, routerDpnListIdentifier);
+ if (optionalRouterDpnList.isPresent()) {
+ List<RouterInterfaces> routerInterfaces = optionalRouterDpnList.get().getRouterInterfaces();
+ RouterInterfaces routerInterface = new RouterInterfacesBuilder().setKey(new RouterInterfacesKey(vpnInterfaceName)).setInterface(vpnInterfaceName).build();
+
+ if (routerInterfaces != null && routerInterfaces.remove(routerInterface)) {
+ if (routerInterfaces.isEmpty()) {
+ MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, routerDpnListIdentifier);
+ } else {
+ MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, routerDpnListIdentifier.child(
+ RouterInterfaces.class,
+ new RouterInterfacesKey(vpnInterfaceName)));