use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap 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.neutronvpn.rev150602.subnetmaps.Subnetmap 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.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap 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.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.
the class ExternalNetworkGroupInstaller method removeExtNetGroupEntries.
public void removeExtNetGroupEntries(Subnetmap subnetMap) {
if (subnetMap == null) {
return;
}
String subnetName = subnetMap.getId().getValue();
Uuid networkId = subnetMap.getNetworkId();
if (networkId == null) {
LOG.error("removeExtNetGroupEntries : No external network associated subnet id {}", subnetName);
return;
}
Collection<String> extInterfaces = elanService.getExternalElanInterfaces(networkId.getValue());
if (extInterfaces == null || extInterfaces.isEmpty()) {
LOG.debug("removeExtNetGroupEntries : No external ELAN interfaces attached to network {} subnet {}", networkId, subnetName);
return;
}
long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(subnetName), idManager);
for (String extInterface : extInterfaces) {
GroupEntity groupEntity = buildEmptyExtNetGroupEntity(subnetName, groupId, extInterface);
if (groupEntity != null) {
LOG.info("removeExtNetGroupEntries : Remove ext-net Group: id {}, subnet id {}", groupId, subnetName);
NatServiceCounters.remove_external_network_group.inc();
mdsalManager.syncRemoveGroup(groupEntity);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.
the class ExternalNetworkGroupInstaller method installExtNetGroupEntries.
private void installExtNetGroupEntries(Subnetmap subnetMap, String macAddress) {
String subnetName = subnetMap.getId().getValue();
Uuid networkId = subnetMap.getNetworkId();
if (networkId == null) {
LOG.error("installExtNetGroupEntries : No network associated subnet id {}", subnetName);
return;
}
Collection<String> extInterfaces = elanService.getExternalElanInterfaces(networkId.getValue());
if (extInterfaces == null || extInterfaces.isEmpty()) {
LOG.trace("installExtNetGroupEntries : No external ELAN interfaces attached to network:{},subnet {}", networkId, subnetName);
return;
}
long groupId = NatUtil.createGroupId(NatUtil.getGroupIdKey(subnetName), idManager);
LOG.info("installExtNetGroupEntries : Installing ext-net group {} entry for subnet {} with macAddress {} " + "(extInterfaces: {})", groupId, subnetName, macAddress, Arrays.toString(extInterfaces.toArray()));
for (String extInterface : extInterfaces) {
BigInteger dpId = NatUtil.getDpnForInterface(interfaceManager, extInterface);
if (BigInteger.ZERO.equals(dpId)) {
LOG.info("installExtNetGroupEntries: No DPN for interface {}. NAT ext-net flow will not be installed " + "for subnet {}", extInterface, subnetName);
return;
}
installExtNetGroupEntry(groupId, subnetName, extInterface, macAddress, dpId);
}
}
Aggregations