use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.
the class SubnetRouteInterfaceStateChangeListener method getSubnetId.
@Nonnull
protected List<Uuid> getSubnetId(Interface intrf) {
List<Uuid> listSubnetIds = new ArrayList<>();
if (!NeutronUtils.isUuid(intrf.getName())) {
LOG.debug("SubnetRouteInterfaceListener: Interface {} doesn't have valid uuid pattern", intrf.getName());
return listSubnetIds;
}
PortOpDataEntry portOpEntry = subOpDpnManager.getPortOpDataEntry(intrf.getName());
if (portOpEntry != null) {
List<Uuid> subnet = portOpEntry.getSubnetIds();
if (subnet != null) {
return subnet;
}
return listSubnetIds;
}
LOG.trace("SubnetRouteInterfaceListener : Received Port {} event for {} that is not part of subnetRoute", intrf.getOperStatus(), intrf.getName());
Port port = neutronVpnManager.getNeutronPort(intrf.getName());
if (port == null) {
return listSubnetIds;
}
List<FixedIps> portIps = port.getFixedIps();
if (port.getFixedIps() != null) {
for (FixedIps portIp : portIps) {
listSubnetIds.add(portIp.getSubnetId());
}
}
return listSubnetIds;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.
the class SubnetRouteInterfaceStateChangeListener method update.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
try {
String interfaceName = update.getName();
if (L2vlan.class.equals(update.getType())) {
LOG.trace("{} update: Operation Interface update event - Old: {}, New: {}", LOGGING_PREFIX, original, update);
List<Uuid> subnetIdList = getSubnetId(update);
if (subnetIdList.isEmpty()) {
LOG.error("SubnetRouteInterfaceListener update: Port {} doesn't exist in configDS", update.getName());
return;
}
for (Uuid subnetId : subnetIdList) {
jobCoordinator.enqueueJob("SUBNETROUTE-" + subnetId, () -> {
List<ListenableFuture<Void>> futures = new ArrayList<>();
BigInteger dpnId = BigInteger.ZERO;
try {
dpnId = InterfaceUtils.getDpIdFromInterface(update);
} catch (Exception e) {
LOG.error("{} remove: Unable to retrieve dpnId for interface {} in subnet {}. " + "Fetching from vpn interface itself", LOGGING_PREFIX, update.getName(), subnetId, e);
}
InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
Optional<VpnInterface> cfgVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
if (!cfgVpnInterface.isPresent()) {
return futures;
}
boolean interfaceChangeEligible = false;
for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().getVpnInstanceNames()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, idOper);
if (optVpnInterface.isPresent()) {
BigInteger dpnIdLocal = dpnId;
if (dpnIdLocal.equals(BigInteger.ZERO)) {
dpnIdLocal = optVpnInterface.get().getDpnId();
}
if (!dpnIdLocal.equals(BigInteger.ZERO)) {
interfaceChangeEligible = true;
break;
}
}
}
if (interfaceChangeEligible) {
if (update.getOperStatus().equals(Interface.OperStatus.Up)) {
LOG.info("{} update: Received port UP event for interface {} in subnet {}", LOGGING_PREFIX, update.getName(), subnetId);
vpnSubnetRouteHandler.onInterfaceUp(dpnId, update.getName(), subnetId);
} else if (update.getOperStatus().equals(Interface.OperStatus.Down) || update.getOperStatus().equals(Interface.OperStatus.Unknown)) {
/*
* If the interface went down voluntarily (or) if the interface is not
* reachable from control-path involuntarily, trigger subnetRoute election
*/
LOG.info("{} update: Received port {} event for interface {} in subnet {} ", LOGGING_PREFIX, update.getOperStatus().equals(Interface.OperStatus.Unknown) ? "UNKNOWN" : "DOWN", update.getName(), subnetId);
vpnSubnetRouteHandler.onInterfaceDown(dpnId, update.getName(), subnetId);
}
}
return futures;
});
}
}
LOG.info("{} update: Processed Interface {} update event", LOGGING_PREFIX, update.getName());
} catch (Exception e) {
LOG.error("{} update: Exception observed in handling deletion of VPNInterface {}", LOGGING_PREFIX, update.getName(), e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet 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.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.
the class SubnetRoutePacketInHandler method handlePacketToInternalNetwork.
private void handlePacketToInternalNetwork(byte[] dstIp, String dstIpStr, int destinationAddress, long elanTag) throws UnknownHostException {
SubnetOpDataEntry targetSubnetForPacketOut = getTargetSubnetForPacketOut(dataBroker, elanTag, destinationAddress);
if (targetSubnetForPacketOut == null) {
LOG.debug("Couldn't find matching subnet for elan tag {} and destination ip {}", elanTag, dstIpStr);
VpnManagerCounters.subnet_route_packet_failed.inc();
return;
}
Optional<Subnetmap> subnetMap = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnUtil.buildSubnetmapIdentifier(targetSubnetForPacketOut.getSubnetId()));
if (!subnetMap.isPresent()) {
LOG.debug("Couldn't find subnet map for subnet {}", targetSubnetForPacketOut.getSubnetId());
VpnManagerCounters.subnet_route_packet_failed.inc();
return;
}
String sourceIp = subnetMap.get().getRouterInterfaceFixedIp();
if (sourceIp == null) {
LOG.debug("Subnet map {} doesn't have a router interface ip defined", subnetMap.get().getId());
VpnManagerCounters.subnet_route_packet_failed.inc();
return;
}
String sourceMac = subnetMap.get().getRouterIntfMacAddress();
if (sourceMac == null) {
LOG.debug("Subnet map {} doesn't have a router interface mac address defined", subnetMap.get().getId());
VpnManagerCounters.subnet_route_packet_failed.inc();
return;
}
transmitArpPacket(targetSubnetForPacketOut.getNhDpnId(), sourceIp, sourceMac, dstIp, elanTag);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.
the class SubnetRoutePacketInHandler method handleBgpVpnSubnetRoute.
private void handleBgpVpnSubnetRoute(IPv4 ipv4, byte[] srcMac, byte[] dstIp, String dstIpStr, String srcIpStr, long elanTag) throws UnknownHostException {
LOG.info("{} handleBgpVpnSubnetRoute: Processing IPv4 Packet received with Source IP {} and Target IP {}" + " and elan Tag {}", LOGGING_PREFIX, srcIpStr, dstIpStr, elanTag);
SubnetOpDataEntry targetSubnetForPacketOut = getTargetSubnetForPacketOut(dataBroker, elanTag, ipv4.getDestinationAddress());
if (targetSubnetForPacketOut != null) {
// Handle subnet routes ip requests
transmitArpPacket(targetSubnetForPacketOut.getNhDpnId(), srcIpStr, NWUtil.toStringMacAddress(srcMac), dstIp, elanTag);
} else {
VpnManagerCounters.subnet_route_packet_failed.inc();
LOG.debug("{} handleBgpVpnSubnetRoute: Could not find target subnet for packet out {}", LOGGING_PREFIX, dstIpStr);
}
}
Aggregations