use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class NatUtil method removeSnatEntriesForPort.
public static void removeSnatEntriesForPort(DataBroker dataBroker, NaptManager naptManager, IMdsalApiManager mdsalManager, NeutronvpnService neutronVpnService, String interfaceName, String routerName) {
Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("removeSnatEntriesForPort: routerId not found for routername {}", routerName);
return;
}
Uint64 naptSwitch = getPrimaryNaptfromRouterName(dataBroker, routerName);
if (naptSwitch == null || naptSwitch.equals(Uint64.ZERO)) {
LOG.error("removeSnatEntriesForPort: NaptSwitch is not elected for router {}" + "with Id {}", routerName, routerId);
return;
}
// getInternalIp for port
List<String> fixedIps = getFixedIpsForPort(neutronVpnService, interfaceName);
if (fixedIps == null) {
LOG.error("removeSnatEntriesForPort: Internal Ips not found for InterfaceName {} in router {} with id {}", interfaceName, routerName, routerId);
return;
}
List<ProtocolTypes> protocolTypesList = getPortocolList();
for (String internalIp : fixedIps) {
LOG.debug("removeSnatEntriesForPort: Internal Ip retrieved for interface {} is {} in router with Id {}", interfaceName, internalIp, routerId);
for (ProtocolTypes protocol : protocolTypesList) {
List<Uint16> portList = NatUtil.getInternalIpPortListInfo(dataBroker, routerId, internalIp, protocol);
if (portList != null) {
for (Uint16 portnum : portList) {
// build and remove the flow in outbound table
removeNatFlow(mdsalManager, naptSwitch, NwConstants.OUTBOUND_NAPT_TABLE, routerId, internalIp, portnum.toJava(), protocol.getName());
// build and remove the flow in inboundtable
removeNatFlow(mdsalManager, naptSwitch, NwConstants.INBOUND_NAPT_TABLE, routerId, internalIp, portnum.toJava(), protocol.getName());
// Get the external IP address and the port from the model
NAPTEntryEvent.Protocol proto = protocol.toString().equals(ProtocolTypes.TCP.toString()) ? NAPTEntryEvent.Protocol.TCP : NAPTEntryEvent.Protocol.UDP;
IpPortExternal ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId, internalIp, String.valueOf(portnum.toJava()), proto);
if (ipPortExternal == null) {
LOG.error("removeSnatEntriesForPort: Mapping for internalIp {} " + "with port {} is not found in " + "router with Id {}", internalIp, portnum, routerId);
return;
}
String externalIpAddress = ipPortExternal.getIpAddress();
String internalIpPort = internalIp + ":" + portnum.toJava();
// delete the entry from IntExtIpPortMap DS
naptManager.removeFromIpPortMapDS(routerId, internalIpPort, proto);
naptManager.removePortFromPool(internalIpPort, externalIpAddress);
}
} else {
LOG.debug("removeSnatEntriesForPort: No {} session for interface {} with internalIP {} " + "in router with id {}", protocol, interfaceName, internalIp, routerId);
}
}
// delete the entry from SnatIntIpPortMap DS
LOG.debug("removeSnatEntriesForPort: Removing InternalIp :{} of router {} from snatint-ip-port-map", internalIp, routerId);
naptManager.removeFromSnatIpPortDS(routerId, internalIp);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class NatUtil method addToNeutronRouterDpnsMap.
public static void addToNeutronRouterDpnsMap(String routerName, String interfaceName, Uint64 dpId, TypedReadWriteTransaction<Operational> operTx) throws ExecutionException, InterruptedException {
if (dpId.equals(Uint64.ZERO)) {
LOG.warn("addToNeutronRouterDpnsMap : Could not retrieve dp id for interface {} " + "to handle router {} association model", interfaceName, routerName);
return;
}
LOG.debug("addToNeutronRouterDpnsMap : Adding the Router {} and DPN {} for the Interface {} in the " + "ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
InstanceIdentifier<DpnVpninterfacesList> dpnVpnInterfacesListIdentifier = getRouterDpnId(routerName, dpId);
Optional<DpnVpninterfacesList> optionalDpnVpninterfacesList = operTx.read(dpnVpnInterfacesListIdentifier).get();
org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces routerInterface = new RouterInterfacesBuilder().withKey(new RouterInterfacesKey(interfaceName)).setInterface(interfaceName).build();
if (optionalDpnVpninterfacesList.isPresent()) {
LOG.debug("addToNeutronRouterDpnsMap : RouterDpnList already present for the Router {} and DPN {} for the " + "Interface {} in the ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
operTx.mergeParentStructureMerge(dpnVpnInterfacesListIdentifier.child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class, new RouterInterfacesKey(interfaceName)), routerInterface);
} else {
LOG.debug("addToNeutronRouterDpnsMap : Building new RouterDpnList for the Router {} and DPN {} for the " + "Interface {} in the ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
RouterDpnListBuilder routerDpnListBuilder = new RouterDpnListBuilder();
routerDpnListBuilder.setRouterId(routerName);
DpnVpninterfacesListBuilder dpnVpnList = new DpnVpninterfacesListBuilder().setDpnId(dpId);
List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces> routerInterfaces = new ArrayList<>();
routerInterfaces.add(routerInterface);
dpnVpnList.setRouterInterfaces(routerInterfaces);
routerDpnListBuilder.setDpnVpninterfacesList(Collections.singletonList(dpnVpnList.build()));
operTx.mergeParentStructureMerge(getRouterId(routerName), routerDpnListBuilder.build());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class NatUtil method handleSNATForDPN.
@SuppressWarnings("checkstyle:IllegalCatch")
public static void handleSNATForDPN(DataBroker dataBroker, IMdsalApiManager mdsalManager, IdManagerService idManager, NaptSwitchHA naptSwitchHA, Uint64 dpnId, Routers extRouters, Uint32 routerId, Uint32 routerVpnId, TypedReadWriteTransaction<Configuration> confTx, ProviderTypes extNwProvType, UpgradeState upgradeState) {
// Check if primary and secondary switch are selected, If not select the role
// Install select group to NAPT switch
// Install default miss entry to NAPT switch
Uint64 naptSwitch;
String routerName = extRouters.getRouterName();
Boolean upgradeInProgress = false;
if (upgradeState != null) {
upgradeInProgress = upgradeState.isUpgradeInProgress();
}
Uint64 naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
if (naptId == null || naptId.equals(Uint64.ZERO) || !NatUtil.getSwitchStatus(dataBroker, naptId) && upgradeInProgress == false) {
LOG.debug("handleSNATForDPN : NaptSwitch is down or not selected for router {},naptId {}", routerName, naptId);
naptSwitch = dpnId;
boolean naptstatus = naptSwitchHA.updateNaptSwitch(routerName, naptSwitch);
if (!naptstatus) {
LOG.error("handleSNATForDPN : Failed to update newNaptSwitch {} for routername {}", naptSwitch, routerName);
return;
}
LOG.debug("handleSNATForDPN : Switch {} is elected as NaptSwitch for router {}", dpnId, routerName);
String externalVpnName = null;
NatUtil.createRouterIdsConfigDS(dataBroker, routerId, routerName);
naptSwitchHA.subnetRegisterMapping(extRouters, routerId);
Uuid extNwUuid = extRouters.getNetworkId();
externalVpnName = NatUtil.getAssociatedVPN(dataBroker, extNwUuid);
if (externalVpnName != null) {
naptSwitchHA.installSnatFlows(routerName, routerId, naptSwitch, routerVpnId, extNwUuid, externalVpnName, confTx);
}
// Install miss entry (table 26) pointing to table 46
FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName, routerVpnId, NatConstants.ADD_FLOW);
if (flowEntity == null) {
LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {}", routerName, dpnId);
return;
}
LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {}", dpnId, routerName);
mdsalManager.addFlow(confTx, flowEntity);
// Removing primary flows from old napt switch
if (naptId != null && !naptId.equals(Uint64.ZERO)) {
LOG.debug("handleSNATForDPN : Removing primary flows from old napt switch {} for router {}", naptId, routerName);
try {
naptSwitchHA.removeSnatFlowsInOldNaptSwitch(extRouters, routerId, naptId, null, externalVpnName, confTx);
} catch (Exception e) {
LOG.error("Exception while removing SnatFlows form OldNaptSwitch {}", naptId, e);
}
}
naptSwitchHA.updateNaptSwitchBucketStatus(routerName, routerId, naptSwitch);
} else if (naptId.equals(dpnId)) {
LOG.error("handleSNATForDPN : NaptSwitch {} gone down during cluster reboot came alive", naptId);
} else {
naptSwitch = naptId;
LOG.debug("handleSNATForDPN : Napt switch with Id {} is already elected for router {}", naptId, routerName);
// installing group
List<BucketInfo> bucketInfo = naptSwitchHA.handleGroupInNeighborSwitches(dpnId, routerName, routerId, naptSwitch);
naptSwitchHA.installSnatGroupEntry(dpnId, bucketInfo, routerName);
// Install miss entry (table 26) pointing to group
Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(routerName));
if (groupId != NatConstants.INVALID_ID) {
FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId.longValue(), routerVpnId, NatConstants.ADD_FLOW);
if (flowEntity == null) {
LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {}" + " groupId {}", routerName, dpnId, groupId);
return;
}
LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {} group {}", dpnId, routerName, groupId);
mdsalManager.addFlow(confTx, flowEntity);
} else {
LOG.error("handleSNATForDPN: Unable to get groupId for router:{}", routerName);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class NatUtil method getRouterIdfromVpnInstance.
@Nullable
public static String getRouterIdfromVpnInstance(DataBroker broker, String vpnName, String ipAddress) {
// returns only router, attached to IPv4 networks
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class, new VpnMapKey(new Uuid(vpnName))).build();
Optional<VpnMap> optionalVpnMap = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
if (!optionalVpnMap.isPresent()) {
LOG.error("getRouterIdfromVpnInstance : Router not found for vpn : {}", vpnName);
return null;
}
List<Uuid> routerIdsList = NeutronUtils.getVpnMapRouterIdsListUuid(new ArrayList<>(optionalVpnMap.get().nonnullRouterIds().values()));
if (routerIdsList != null && !routerIdsList.isEmpty()) {
for (Uuid routerUuid : routerIdsList) {
InstanceIdentifier<Routers> id = buildRouterIdentifier(routerUuid.getValue());
Optional<Routers> routerData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, id);
if (routerData.isPresent()) {
List<Uuid> subnetIdsList = routerData.get().getSubnetIds();
for (Uuid subnetUuid : subnetIdsList) {
String subnetIp = getSubnetIp(broker, subnetUuid);
SubnetUtils subnet = new SubnetUtils(subnetIp);
if (subnet.getInfo().isInRange(ipAddress)) {
return routerUuid.getValue();
}
}
}
}
}
LOG.info("getRouterIdfromVpnInstance : Router not found for vpn : {}", vpnName);
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.routers.Router in project netvirt by opendaylight.
the class NatUtil method checkForRoutersWithSameExtNetAndNaptSwitch.
public static boolean checkForRoutersWithSameExtNetAndNaptSwitch(DataBroker broker, Uuid networkId, String routerName, Uint64 dpnId) {
InstanceIdentifier<Networks> id = buildNetworkIdentifier(networkId);
Optional<Networks> networkData = null;
try {
networkData = SingleTransactionDataBroker.syncReadOptional(broker, LogicalDatastoreType.CONFIGURATION, id);
} catch (ExecutionException | InterruptedException e) {
LOG.error("checkForRoutersWithSameExtNetAndNaptSwitch: Exception while reading Networks DS for the " + "network {} router {} dpnId {}", networkId.getValue(), routerName, dpnId, e);
return false;
}
if (networkData != null && networkData.isPresent()) {
List<Uuid> routerUuidList = networkData.get().getRouterIds();
if (routerUuidList != null && !routerUuidList.isEmpty()) {
for (Uuid routerUuid : routerUuidList) {
String sharedRouterName = routerUuid.getValue();
if (!routerName.equals(sharedRouterName)) {
Uint64 switchDpnId = NatUtil.getPrimaryNaptfromRouterName(broker, sharedRouterName);
if (switchDpnId != null && switchDpnId.equals(dpnId)) {
LOG.debug("checkForRoutersWithSameExtNetAndNaptSwitch: external-network {} is " + "associated with other active router {} on NAPT switch {}", networkId, sharedRouterName, switchDpnId);
return true;
}
}
}
}
}
return false;
}
Aggregations