use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey in project netvirt by opendaylight.
the class NeutronPortChangeListener method handleNeutronPortUpdated.
private void handleNeutronPortUpdated(final Port portoriginal, final Port portupdate) {
final Map<FixedIpsKey, FixedIps> portoriginalIpsMap = portoriginal.nonnullFixedIps();
final Map<FixedIpsKey, FixedIps> portupdateIpsMap = portupdate.nonnullFixedIps();
if (portoriginalIpsMap == null || portoriginalIpsMap.isEmpty()) {
handleNeutronPortCreated(portupdate);
return;
}
if (portupdateIpsMap == null || portupdateIpsMap.isEmpty()) {
LOG.info("Ignoring portUpdate (fixed_ip removal) for port {} as this case is handled " + "during subnet deletion event.", portupdate.getUuid().getValue());
return;
}
if (NeutronConstants.IS_ODL_DHCP_PORT.test(portupdate)) {
return;
}
jobCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
final List<Uuid> originalSnMapsIds = portoriginalIpsMap.values().stream().map(FixedIps::getSubnetId).collect(Collectors.toList());
final List<Uuid> updateSnMapsIds = portupdateIpsMap.values().stream().map(FixedIps::getSubnetId).collect(Collectors.toList());
Set<Uuid> originalRouterIds = new HashSet<>();
Set<Uuid> oldVpnIds = new HashSet<>();
for (Uuid snId : originalSnMapsIds) {
if (!updateSnMapsIds.remove(snId)) {
// snId was present in originalSnMapsIds, but not in updateSnMapsIds
Subnetmap subnetMapOld = nvpnManager.removePortsFromSubnetmapNode(snId, portoriginal.getUuid(), null);
if (subnetMapOld != null && subnetMapOld.getVpnId() != null) {
oldVpnIds.add(subnetMapOld.getVpnId());
}
if (subnetMapOld != null && subnetMapOld.getInternetVpnId() != null) {
oldVpnIds.add(subnetMapOld.getInternetVpnId());
}
if (subnetMapOld != null && subnetMapOld.getRouterId() != null) {
originalRouterIds.add(subnetMapOld.getRouterId());
}
}
}
Set<Uuid> newVpnIds = new HashSet<>();
Set<Uuid> newRouterIds = new HashSet<>();
for (Uuid snId : updateSnMapsIds) {
Subnetmap subnetMapNew = nvpnManager.updateSubnetmapNodeWithPorts(snId, portupdate.getUuid(), null);
if (subnetMapNew != null) {
if (subnetMapNew.getVpnId() != null) {
newVpnIds.add(subnetMapNew.getVpnId());
}
if (subnetMapNew.getInternetVpnId() != null) {
newVpnIds.add(subnetMapNew.getInternetVpnId());
}
if (subnetMapNew.getRouterId() != null) {
newRouterIds.add(subnetMapNew.getRouterId());
}
}
}
if (!oldVpnIds.isEmpty()) {
LOG.info("removing VPN Interface for port {}", portoriginal.getUuid().getValue());
if (!originalRouterIds.isEmpty()) {
for (Uuid routerId : originalRouterIds) {
nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, portoriginal.getUuid().getValue());
}
}
nvpnManager.deleteVpnInterface(portoriginal.getUuid().getValue(), null, /* vpn-id */
confTx);
}
if (!newVpnIds.isEmpty()) {
LOG.info("Adding VPN Interface for port {}", portupdate.getUuid().getValue());
nvpnManager.createVpnInterface(newVpnIds, portupdate, confTx);
if (!newRouterIds.isEmpty()) {
for (Uuid routerId : newRouterIds) {
nvpnManager.addToNeutronRouterInterfacesMap(routerId, portupdate.getUuid().getValue());
}
}
}
})));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey in project netvirt by opendaylight.
the class NeutronvpnManager method showNeutronPortsCLI.
/**
* Implementation of the "vpnservice:neutron-ports-show" Karaf CLI command.
*
* @return a List of String to be printed on screen
* @throws ExecutionException or InterruptedException if there was a problem reading from the data store
*/
public List<String> showNeutronPortsCLI() throws ExecutionException, InterruptedException {
List<String> result = new ArrayList<>();
result.add(String.format(" %-36s %-19s %-13s %-20s ", "Port ID", "Mac Address", "Prefix Length", "IP Address"));
result.add("-------------------------------------------------------------------------------------------");
InstanceIdentifier<Ports> portidentifier = InstanceIdentifier.create(Neutron.class).child(Ports.class);
Optional<Ports> ports = syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, portidentifier);
if (ports.isPresent() && ports.get().getPort() != null) {
for (Port port : ports.get().nonnullPort().values()) {
Map<FixedIpsKey, FixedIps> keyFixedIpsMap = port.getFixedIps();
if (keyFixedIpsMap != null && !keyFixedIpsMap.isEmpty()) {
List<String> ipList = new ArrayList<>();
for (FixedIps fixedIp : keyFixedIpsMap.values()) {
IpAddress ipAddress = fixedIp.getIpAddress();
if (ipAddress.getIpv4Address() != null) {
ipList.add(ipAddress.getIpv4Address().getValue());
} else {
ipList.add(ipAddress.getIpv6Address().getValue());
}
}
result.add(String.format(" %-36s %-19s %-13s %-20s ", port.getUuid().getValue(), port.getMacAddress().getValue(), neutronvpnUtils.getIPPrefixFromPort(port), ipList.toString()));
} else {
result.add(String.format(" %-36s %-19s %-13s %-20s ", port.getUuid().getValue(), port.getMacAddress().getValue(), "Not Assigned", "Not Assigned"));
}
}
}
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey in project netvirt by opendaylight.
the class NeutronvpnUtils method buildStaticMacEntry.
public static List<StaticMacEntries> buildStaticMacEntry(Port port) {
PhysAddress physAddress = new PhysAddress(port.getMacAddress().getValue());
Map<FixedIpsKey, FixedIps> keyFixedIpsMap = port.nonnullFixedIps();
IpAddress ipAddress = null;
if (isNotEmpty(keyFixedIpsMap.values())) {
ipAddress = new ArrayList<FixedIps>(port.nonnullFixedIps().values()).get(0).getIpAddress();
}
StaticMacEntriesBuilder staticMacEntriesBuilder = new StaticMacEntriesBuilder();
List<StaticMacEntries> staticMacEntries = new ArrayList<>();
if (ipAddress != null) {
staticMacEntries.add(staticMacEntriesBuilder.setMacAddress(physAddress).setIpPrefix(ipAddress).build());
} else {
staticMacEntries.add(staticMacEntriesBuilder.setMacAddress(physAddress).build());
}
return staticMacEntries;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey in project netvirt by opendaylight.
the class NeutronvpnUtils method getSubnetInfo.
@Nullable
protected List<SubnetInfo> getSubnetInfo(Port port) {
Map<FixedIpsKey, FixedIps> keyFixedIpsMap = port.getFixedIps();
if (keyFixedIpsMap == null) {
LOG.error("Failed to get Fixed IPs for the port {}", port.getName());
return null;
}
List<SubnetInfo> subnetInfoList = new ArrayList<>();
for (FixedIps portFixedIp : keyFixedIpsMap.values()) {
Uuid subnetId = portFixedIp.getSubnetId();
Subnet subnet = getNeutronSubnet(subnetId);
if (subnet != null) {
Class<? extends IpVersionBase> ipVersion = NeutronSecurityGroupConstants.IP_VERSION_MAP.get(subnet.getIpVersion());
Class<? extends Dhcpv6Base> raMode = subnet.getIpv6RaMode() == null ? null : NeutronSecurityGroupConstants.RA_MODE_MAP.get(subnet.getIpv6RaMode());
SubnetInfo subnetInfo = new SubnetInfoBuilder().withKey(new SubnetInfoKey(subnetId)).setIpVersion(ipVersion).setIpPrefix(new IpPrefixOrAddress(subnet.getCidr())).setIpv6RaMode(raMode).setGatewayIp(subnet.getGatewayIp()).build();
subnetInfoList.add(subnetInfo);
}
}
return subnetInfoList;
}
Aggregations