use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network in project netvirt by opendaylight.
the class SubnetRoutePacketInHandler method getTargetSubnetForPacketOut.
// return only the first VPN subnetopdataentry
private static SubnetOpDataEntry getTargetSubnetForPacketOut(DataBroker broker, long elanTag, int ipAddress) {
ElanTagName elanInfo = VpnUtil.getElanInfoByElanTag(broker, elanTag);
if (elanInfo == null) {
LOG.error("{} getTargetDpnForPacketOut: Unable to retrieve ElanInfo for elanTag {}", LOGGING_PREFIX, elanTag);
return null;
}
Optional<NetworkMap> optionalNetworkMap = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, VpnUtil.buildNetworkMapIdentifier(new Uuid(elanInfo.getName())));
if (!optionalNetworkMap.isPresent()) {
LOG.debug("{} getTargetDpnForPacketOut: No network map found for elan info {}", LOGGING_PREFIX, elanInfo.getName());
return null;
}
List<Uuid> subnetList = optionalNetworkMap.get().getSubnetIdList();
LOG.debug("{} getTargetDpnForPacketOut: Obtained subnetList as {} for network {}", LOGGING_PREFIX, subnetList, elanInfo.getName());
for (Uuid subnetId : subnetList) {
String vpnName = null;
Subnetmap sn = VpnUtil.getSubnetmapFromItsUuid(broker, subnetId);
if (sn != null && sn.getVpnId() != null) {
vpnName = sn.getVpnId().getValue();
}
if (vpnName == null) {
continue;
}
Optional<SubnetOpDataEntry> optionalSubs;
optionalSubs = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, VpnUtil.buildSubnetOpDataEntryInstanceIdentifier(subnetId));
if (!optionalSubs.isPresent()) {
continue;
}
SubnetOpDataEntry subOpEntry = optionalSubs.get();
if (subOpEntry.getNhDpnId() != null) {
LOG.trace("{} getTargetDpnForPacketOut: Viewing Subnet {}", LOGGING_PREFIX, subnetId.getValue());
boolean match = NWUtil.isIpInSubnet(ipAddress, subOpEntry.getSubnetCidr());
LOG.trace("{} getTargetDpnForPacketOut: Viewing Subnet {} matching {}", LOGGING_PREFIX, subnetId.getValue(), match);
if (match) {
return subOpEntry;
}
}
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network in project netvirt by opendaylight.
the class SubnetmapChangeListener method update.
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void update(InstanceIdentifier<Subnetmap> identifier, Subnetmap subnetmapOriginal, Subnetmap subnetmapUpdate) {
LOG.debug("SubnetMapChangeListener update method - key {}, original {}, update {}", identifier, subnetmapOriginal, subnetmapUpdate);
Uuid subnetId = subnetmapUpdate.getId();
Network network = VpnUtil.getNeutronNetwork(dataBroker, subnetmapUpdate.getNetworkId());
if (network == null) {
LOG.error("SubnetMapChangeListener:update: network was not found for subnetId {}", subnetId.getValue());
return;
}
if (VpnUtil.getIsExternal(network)) {
LOG.debug("SubnetMapChangeListener:update: provider subnetwork {} is handling in " + "ExternalSubnetVpnInstanceListener", subnetId.getValue());
return;
}
String elanInstanceName = subnetmapUpdate.getNetworkId().getValue();
long elanTag = getElanTag(elanInstanceName);
if (elanTag == 0L) {
LOG.error("SubnetMapChangeListener:update: unable to fetch elantag from ElanInstance {} for subnetId {}", elanInstanceName, subnetId);
return;
}
// update on BGPVPN or InternalVPN change
Uuid vpnIdOld = subnetmapOriginal.getVpnId();
Uuid vpnIdNew = subnetmapUpdate.getVpnId();
if (!Objects.equals(vpnIdOld, vpnIdNew)) {
LOG.info("SubnetMapChangeListener:update: update subnetOpDataEntry for subnet {} imported in VPN", subnetmapUpdate.getId().getValue());
updateSubnetmapOpDataEntry(subnetmapOriginal.getVpnId(), subnetmapUpdate.getVpnId(), subnetmapUpdate, subnetmapOriginal, elanTag);
}
// update on Internet VPN Id change
Uuid inetVpnIdOld = subnetmapOriginal.getInternetVpnId();
Uuid inetVpnIdNew = subnetmapUpdate.getInternetVpnId();
if (!Objects.equals(inetVpnIdOld, inetVpnIdNew)) {
LOG.info("SubnetMapChangeListener:update: update subnetOpDataEntry for subnet {} imported in InternetVPN", subnetmapUpdate.getId().getValue());
updateSubnetmapOpDataEntry(inetVpnIdOld, inetVpnIdNew, subnetmapUpdate, subnetmapOriginal, elanTag);
}
// update on PortList change
List<Uuid> oldPortList;
List<Uuid> newPortList;
newPortList = subnetmapUpdate.getPortList() != null ? subnetmapUpdate.getPortList() : new ArrayList<>();
oldPortList = subnetmapOriginal.getPortList() != null ? subnetmapOriginal.getPortList() : new ArrayList<>();
if (newPortList.size() == oldPortList.size()) {
return;
}
LOG.info("SubnetMapChangeListener:update: update port list for subnet {}", subnetmapUpdate.getId().getValue());
if (newPortList.size() > oldPortList.size()) {
for (Uuid portId : newPortList) {
if (!oldPortList.contains(portId)) {
vpnSubnetRouteHandler.onPortAddedToSubnet(subnetmapUpdate, portId);
return;
}
}
} else {
for (Uuid portId : oldPortList) {
if (!newPortList.contains(portId)) {
vpnSubnetRouteHandler.onPortRemovedFromSubnet(subnetmapUpdate, portId);
return;
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network in project netvirt by opendaylight.
the class NatUtil method getNetworkVpnIdFromRouterId.
public static Long getNetworkVpnIdFromRouterId(DataBroker broker, long routerId) {
// Get the external network ID from the ExternalRouter model
Uuid networkId = NatUtil.getNetworkIdFromRouterId(broker, routerId);
if (networkId == null) {
LOG.error("getNetworkVpnIdFromRouterId : networkId is null");
return NatConstants.INVALID_ID;
}
// Get the VPN ID from the ExternalNetworks model
Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(broker, networkId);
if (vpnUuid == null) {
LOG.error("getNetworkVpnIdFromRouterId : vpnUuid is null");
return NatConstants.INVALID_ID;
}
Long vpnId = NatUtil.getVpnId(broker, vpnUuid.getValue());
return vpnId;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network in project netvirt by opendaylight.
the class NatUtil method checkForRoutersWithSameExtNetAndNaptSwitch.
public static boolean checkForRoutersWithSameExtNetAndNaptSwitch(DataBroker broker, Uuid networkId, String routerName, BigInteger dpnId) {
InstanceIdentifier<Networks> id = buildNetworkIdentifier(networkId);
Optional<Networks> networkData = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, id);
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)) {
BigInteger swtichDpnId = NatUtil.getPrimaryNaptfromRouterName(broker, sharedRouterName);
if (swtichDpnId == null) {
continue;
} else if (swtichDpnId.equals(dpnId)) {
LOG.debug("checkForRoutersWithSameExtNetAndNaptSwitch: external-network {} is " + "associated with other active router {} on NAPT switch {}", networkId, sharedRouterName, swtichDpnId);
return true;
}
}
}
}
}
return false;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network in project netvirt by opendaylight.
the class RouterDpnChangeListener method remove.
@Override
protected void remove(InstanceIdentifier<DpnVpninterfacesList> identifier, DpnVpninterfacesList dpnInfo) {
LOG.trace("remove : key: {}, value: {}", dpnInfo.getKey(), dpnInfo);
final String routerUuid = identifier.firstKeyOf(RouterDpnList.class).getRouterId();
Long routerId = NatUtil.getVpnId(dataBroker, routerUuid);
if (routerId == NatConstants.INVALID_ID) {
LOG.error("REMOVE: Invalid routId returned for routerName {}", routerUuid);
return;
}
BigInteger dpnId = dpnInfo.getDpnId();
// check router is associated to external network
InstanceIdentifier<Routers> id = NatUtil.buildRouterIdentifier(routerUuid);
Optional<Routers> routerData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (routerData.isPresent()) {
Routers router = routerData.get();
Uuid networkId = router.getNetworkId();
if (networkId != null) {
if (natMode == NatMode.Conntrack) {
BigInteger naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, router.getRouterName());
if (naptSwitch == null || naptSwitch.equals(BigInteger.ZERO)) {
LOG.warn("remove : NAPT switch is not selected.");
return;
}
// If it is for NAPT switch skip as the flows would be already programmed.
if (naptSwitch.equals(dpnId)) {
LOG.debug("Skipping the notification recived for NAPT switch {}", routerUuid);
return;
}
natServiceManager.notify(router, naptSwitch, dpnId, SnatServiceManager.Action.SNAT_ROUTER_DISBL);
} else {
coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + dpnInfo.getKey(), () -> {
WriteTransaction removeFlowInvTx = dataBroker.newWriteOnlyTransaction();
LOG.debug("remove : Router {} is associated with ext nw {}", routerUuid, networkId);
Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerUuid);
Long vpnId;
List<ListenableFuture<Void>> futures = new ArrayList<>();
if (vpnName == null) {
LOG.debug("remove : Internal vpn associated to router {}", routerUuid);
vpnId = routerId;
if (vpnId == NatConstants.INVALID_ID) {
LOG.error("remove : Invalid vpnId returned for routerName {}", routerUuid);
removeFlowInvTx.cancel();
return futures;
}
LOG.debug("remove : Retrieved vpnId {} for router {}", vpnId, routerUuid);
// Remove default entry in FIB
LOG.debug("remove : Removing default route in FIB on dpn {} for vpn {} ...", dpnId, vpnName);
snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId, removeFlowInvTx);
} else {
LOG.debug("remove : External vpn associated to router {}", routerUuid);
vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
if (vpnId == NatConstants.INVALID_ID) {
LOG.error("remove : Invalid vpnId returned for routerName {}", routerUuid);
removeFlowInvTx.cancel();
return futures;
}
LOG.debug("remove : Retrieved vpnId {} for router {}", vpnId, routerUuid);
// Remove default entry in FIB
LOG.debug("remove : Removing default route in FIB on dpn {} for vpn {} ...", dpnId, vpnName);
snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId, routerId, removeFlowInvTx);
}
if (router.isEnableSnat()) {
LOG.info("remove : SNAT enabled for router {}", routerUuid);
removeSNATFromDPN(dpnId, routerUuid, routerId, vpnId, networkId, removeFlowInvTx);
} else {
LOG.info("remove : SNAT is not enabled for router {} to handle removeDPN event {}", routerUuid, dpnId);
}
futures.add(NatUtil.waitForTransactionToComplete(removeFlowInvTx));
return futures;
}, NatConstants.NAT_DJC_MAX_RETRIES);
}
// end of controller based SNAT
}
}
}
Aggregations