use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.
the class NeutronSubnetGwMacResolver method sendArpRequestsToExtGatewayTask.
private void sendArpRequestsToExtGatewayTask(Router router) {
LOG.trace("Send ARP requests to external GW for router {}", router);
Port extPort = getRouterExtGatewayPort(router);
if (extPort == null) {
LOG.trace("External GW port for router {} is missing", router.getUuid().getValue());
return;
}
String extInterface = getExternalInterface(router);
if (extInterface == null) {
LOG.trace("No external interface defined for router {}", router.getUuid().getValue());
return;
}
List<FixedIps> fixedIps = extPort.getFixedIps();
if (fixedIps == null || fixedIps.isEmpty()) {
LOG.trace("External GW port {} for router {} has no fixed IPs", extPort.getUuid().getValue(), router.getUuid().getValue());
return;
}
MacAddress macAddress = extPort.getMacAddress();
if (macAddress == null) {
LOG.trace("External GW port {} for router {} has no mac address", extPort.getUuid().getValue(), router.getUuid().getValue());
return;
}
for (FixedIps fixIp : fixedIps) {
Uuid subnetId = fixIp.getSubnetId();
IpAddress srcIpAddress = fixIp.getIpAddress();
IpAddress dstIpAddress = getExternalGwIpAddress(subnetId);
sendArpRequest(srcIpAddress, dstIpAddress, macAddress, extInterface);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.
the class NeutronvpnManager method getFixedIPsForNeutronPort.
/**
* It handles the invocations to the neutronvpn:getFixedIPsForNeutronPort RPC method.
*/
@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<GetFixedIPsForNeutronPortOutput>> getFixedIPsForNeutronPort(GetFixedIPsForNeutronPortInput input) {
GetFixedIPsForNeutronPortOutputBuilder opBuilder = new GetFixedIPsForNeutronPortOutputBuilder();
SettableFuture<RpcResult<GetFixedIPsForNeutronPortOutput>> result = SettableFuture.create();
Uuid portId = input.getPortId();
StringBuilder returnMsg = new StringBuilder();
try {
List<String> fixedIPList = new ArrayList<>();
Port port = neutronvpnUtils.getNeutronPort(portId);
if (port != null) {
List<FixedIps> fixedIPs = port.getFixedIps();
for (FixedIps ip : fixedIPs) {
fixedIPList.add(String.valueOf(ip.getIpAddress().getValue()));
}
} else {
returnMsg.append("neutron port: ").append(portId.getValue()).append(" not found");
}
if (returnMsg.length() != 0) {
result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>failed().withWarning(ErrorType.PROTOCOL, "invalid-value", formatAndLog(LOG::error, "Retrieval of FixedIPList for neutron port failed due to {}", returnMsg)).build());
} else {
opBuilder.setFixedIPs(fixedIPList);
result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>success().withResult(opBuilder.build()).build());
result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>success().build());
}
} catch (Exception ex) {
result.set(RpcResultBuilder.<GetFixedIPsForNeutronPortOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::error, "Retrieval of FixedIPList for neutron port {} failed due to {}", portId.getValue(), ex.getMessage(), ex)).build());
}
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps 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 ReadFailedException if there was a problem reading from the data store
*/
public List<String> showNeutronPortsCLI() throws ReadFailedException {
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, CONFIGURATION, portidentifier);
if (ports.isPresent() && ports.get().getPort() != null) {
for (Port port : ports.get().getPort()) {
List<FixedIps> fixedIPs = port.getFixedIps();
if (fixedIPs != null && !fixedIPs.isEmpty()) {
List<String> ipList = new ArrayList<>();
for (FixedIps fixedIp : fixedIPs) {
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.FixedIps in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInterface.
protected void updateVpnInterface(Uuid vpnId, Uuid oldVpnId, Port port, boolean isBeingAssociated, boolean isSubnetIp, WriteTransaction writeConfigTxn) {
if (vpnId == null || port == null) {
return;
}
boolean isLockAcquired = false;
String infName = port.getUuid().getValue();
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
try {
isLockAcquired = interfaceLock.tryLock(infName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
List<VpnInstanceNames> listVpn = new ArrayList<>(optionalVpnInterface.get().getVpnInstanceNames());
if (oldVpnId != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(oldVpnId.getValue(), listVpn)) {
VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(oldVpnId.getValue(), listVpn);
}
if (vpnId.getValue() != null && !VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), listVpn)) {
listVpn.add(vpnInstance);
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(listVpn);
LOG.debug("Updating vpn interface {}", infName);
if (!isBeingAssociated) {
Adjacencies adjs = vpnIfBuilder.getAugmentation(Adjacencies.class);
List<Adjacency> adjacencyList = adjs != null ? adjs.getAdjacency() : new ArrayList<>();
Iterator<Adjacency> adjacencyIter = adjacencyList.iterator();
while (adjacencyIter.hasNext()) {
Adjacency adjacency = adjacencyIter.next();
String mipToQuery = adjacency.getIpAddress().split("/")[0];
InstanceIdentifier<LearntVpnVipToPort> id = NeutronvpnUtils.buildLearntVpnVipToPortIdentifier(oldVpnId.getValue(), mipToQuery);
Optional<LearntVpnVipToPort> optionalVpnVipToPort = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (optionalVpnVipToPort.isPresent()) {
LOG.trace("Removing adjacencies from vpninterface {} upon dissociation of router {} " + "from VPN {}", infName, vpnId, oldVpnId);
adjacencyIter.remove();
neutronvpnUtils.removeLearntVpnVipToPort(oldVpnId.getValue(), mipToQuery);
LOG.trace("Entry for fixedIP {} for port {} on VPN {} removed from VpnPortFixedIPToPortData", mipToQuery, infName, vpnId.getValue());
}
}
Adjacencies adjacencies = new AdjacenciesBuilder().setAdjacency(adjacencyList).build();
vpnIfBuilder.addAugmentation(Adjacencies.class, adjacencies);
}
List<FixedIps> ips = port.getFixedIps();
for (FixedIps ip : ips) {
String ipValue = String.valueOf(ip.getIpAddress().getValue());
if (oldVpnId != null) {
neutronvpnUtils.removeVpnPortFixedIpToPort(oldVpnId.getValue(), ipValue, writeConfigTxn);
}
neutronvpnUtils.createVpnPortFixedIpToPort(vpnId.getValue(), ipValue, infName, port.getMacAddress().getValue(), isSubnetIp, writeConfigTxn);
}
writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
} else {
LOG.error("VPN Interface {} not found", infName);
}
} catch (ReadFailedException ex) {
LOG.error("Updation of vpninterface {} failed", infName, ex);
} finally {
if (isLockAcquired) {
interfaceLock.unlock(infName);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.
the class NeutronvpnNatManager method addExternalFixedIpToExternalIpsList.
private void addExternalFixedIpToExternalIpsList(List<ExternalIps> externalIps, ExternalFixedIps fixedIps) {
Uuid subnetId = fixedIps.getSubnetId();
String ip = fixedIps.getIpAddress().getIpv4Address().getValue();
ExternalIpsBuilder externalIpsBuilder = new ExternalIpsBuilder();
externalIpsBuilder.setKey(new ExternalIpsKey(ip, subnetId));
externalIpsBuilder.setIpAddress(ip);
externalIpsBuilder.setSubnetId(subnetId);
externalIps.add(externalIpsBuilder.build());
}
Aggregations