use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.DpnRouters in project netvirt by opendaylight.
the class NatUtil method removeFromDpnRoutersMap.
static void removeFromDpnRoutersMap(DataBroker broker, String routerName, String vpnInterfaceName, BigInteger curDpnId, OdlInterfaceRpcService ifaceMgrRpcService, WriteTransaction writeOperTxn) {
/*
1) Get the DpnRoutersList for the DPN.
2) Get the RoutersList identifier for the DPN and router.
3) Get the VPN interfaces for the router (routerList) through which it is connected to the DPN.
4) If the removed VPN interface is the only interface through which the router is connected to the DPN,
then remove RouterList.
*/
LOG.debug("removeFromDpnRoutersMap() : Removing the DPN {} and router {} for the Interface {}" + " in the ODL-L3VPN : DPNRouters map", curDpnId, routerName, vpnInterfaceName);
// Get the dpn-routers-list instance for the current DPN.
InstanceIdentifier<DpnRoutersList> dpnRoutersListIdentifier = getDpnRoutersId(curDpnId);
Optional<DpnRoutersList> dpnRoutersListData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.OPERATIONAL, dpnRoutersListIdentifier);
if (dpnRoutersListData == null || !dpnRoutersListData.isPresent()) {
LOG.error("removeFromDpnRoutersMap : dpn-routers-list is not present for DPN {} " + "in the ODL-L3VPN:dpn-routers model", curDpnId);
return;
}
// Get the routers-list instance for the router on the current DPN only
InstanceIdentifier<RoutersList> routersListIdentifier = getRoutersList(curDpnId, routerName);
Optional<RoutersList> routersListData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
if (routersListData == null || !routersListData.isPresent()) {
LOG.error("removeFromDpnRoutersMap : routers-list is not present for the DPN {} " + "in the ODL-L3VPN:dpn-routers model", curDpnId);
return;
}
LOG.debug("removeFromDpnRoutersMap : Get the interfaces for the router {} " + "from the NeutronVPN - router-interfaces-map", routerName);
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces> routerInterfacesId = getRoutersInterfacesIdentifier(routerName);
Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.RouterInterfaces> routerInterfacesData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, routerInterfacesId);
if (routerInterfacesData == null || !routerInterfacesData.isPresent()) {
LOG.debug("removeFromDpnRoutersMap : Unable to get the routers list for the DPN {}. Possibly all subnets " + "removed from router {} OR Router {} has been deleted. Hence DPN router model WILL be cleared ", curDpnId, routerName, routerName);
writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
return;
}
// Get the VM interfaces for the router on the current DPN only.
List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces> vmInterfaces = routerInterfacesData.get().getInterfaces();
if (vmInterfaces == null) {
LOG.debug("removeFromDpnRoutersMap : VM interfaces are not present for the router {} in the " + "NeutronVPN - router-interfaces-map", routerName);
return;
}
// then remove RouterList.
for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.router.interfaces.map.router.interfaces.Interfaces vmInterface : vmInterfaces) {
String vmInterfaceName = vmInterface.getInterfaceId();
BigInteger vmDpnId = getDpnForInterface(ifaceMgrRpcService, vmInterfaceName);
if (vmDpnId.equals(BigInteger.ZERO) || !vmDpnId.equals(curDpnId)) {
LOG.debug("removeFromDpnRoutersMap : DPN ID {} for the removed interface {} is not the same as that of " + "the DPN ID {} for the checked interface {}", curDpnId, vpnInterfaceName, vmDpnId, vmInterfaceName);
continue;
}
if (!vmInterfaceName.equalsIgnoreCase(vpnInterfaceName)) {
LOG.info("removeFromDpnRoutersMap : Router {} is present in the DPN {} through the other interface {} " + "Hence DPN router model WOULD NOT be cleared", routerName, curDpnId, vmInterfaceName);
return;
}
}
LOG.debug("removeFromDpnRoutersMap : Router {} is present in the DPN {} only through the interface {} " + "Hence DPN router model WILL be cleared. Possibly last VM for the router " + "deleted in the DPN", routerName, curDpnId, vpnInterfaceName);
writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routersListIdentifier);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.DpnRouters in project netvirt by opendaylight.
the class NatUtil method addToDpnRoutersMap.
public static void addToDpnRoutersMap(DataBroker broker, String routerName, String interfaceName, BigInteger dpId, WriteTransaction writeOperTxn) {
if (dpId.equals(BigInteger.ZERO)) {
LOG.error("addToDpnRoutersMap : Could not retrieve dp id for interface {} to handle router {} " + "association model", interfaceName, routerName);
return;
}
LOG.debug("addToDpnRoutersMap : Adding the DPN {} and router {} for the Interface {} in the ODL-L3VPN : " + "DPNRouters map", dpId, routerName, interfaceName);
InstanceIdentifier<DpnRoutersList> dpnRoutersListIdentifier = getDpnRoutersId(dpId);
Optional<DpnRoutersList> optionalDpnRoutersList = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.OPERATIONAL, dpnRoutersListIdentifier);
if (optionalDpnRoutersList.isPresent()) {
RoutersList routersList = new RoutersListBuilder().setKey(new RoutersListKey(routerName)).setRouter(routerName).build();
List<RoutersList> routersListFromDs = optionalDpnRoutersList.get().getRoutersList();
if (!routersListFromDs.contains(routersList)) {
LOG.debug("addToDpnRoutersMap : Router {} not present for the DPN {}" + " in the ODL-L3VPN : DPNRouters map", routerName, dpId);
writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, dpnRoutersListIdentifier.child(RoutersList.class, new RoutersListKey(routerName)), routersList, true);
} else {
LOG.debug("addToDpnRoutersMap : Router {} already mapped to the DPN {} in the ODL-L3VPN : " + "DPNRouters map", routerName, dpId);
}
} else {
LOG.debug("addToDpnRoutersMap : Building new DPNRoutersList for the Router {} present in the DPN {} " + "ODL-L3VPN : DPNRouters map", routerName, dpId);
DpnRoutersListBuilder dpnRoutersListBuilder = new DpnRoutersListBuilder();
dpnRoutersListBuilder.setDpnId(dpId);
RoutersListBuilder routersListBuilder = new RoutersListBuilder();
routersListBuilder.setRouter(routerName);
dpnRoutersListBuilder.setRoutersList(Collections.singletonList(routersListBuilder.build()));
writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, getDpnRoutersId(dpId), dpnRoutersListBuilder.build(), true);
}
}
Aggregations