use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.multipart.reply.multipart.reply.body.multipart.reply.port.desc.Ports in project netvirt by opendaylight.
the class AclInterfaceListener method update.
@Override
public void update(InstanceIdentifier<Interface> key, Interface portBefore, Interface portAfter) {
if (portBefore.getAugmentation(ParentRefs.class) == null && portAfter.getAugmentation(ParentRefs.class) != null) {
LOG.trace("Ignoring event for update in ParentRefs for {} ", portAfter.getName());
return;
}
LOG.trace("Received AclInterface update event, portBefore={}, portAfter={}", portBefore, portAfter);
InterfaceAcl aclInPortAfter = portAfter.getAugmentation(InterfaceAcl.class);
InterfaceAcl aclInPortBefore = portBefore.getAugmentation(InterfaceAcl.class);
String interfaceId = portAfter.getName();
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState = AclServiceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceId);
AclInterface aclInterfaceBefore = aclInterfaceCache.get(interfaceId);
if (aclInterfaceBefore == null || isPortSecurityEnabledNow(aclInPortBefore, aclInPortAfter)) {
// Updating cache now as it might have not updated when
// port-security-enable=false
aclInterfaceBefore = addOrUpdateAclInterfaceCache(interfaceId, aclInPortBefore, true, interfaceState);
}
if (aclInPortAfter != null && aclInPortAfter.isPortSecurityEnabled() || aclInPortBefore != null && aclInPortBefore.isPortSecurityEnabled()) {
boolean isSgChanged = isSecurityGroupsChanged(aclInPortBefore.getSecurityGroups(), aclInPortAfter.getSecurityGroups());
AclInterface aclInterfaceAfter = addOrUpdateAclInterfaceCache(interfaceId, aclInPortAfter, isSgChanged, interfaceState);
if (aclClusterUtil.isEntityOwner()) {
// Handle bind/unbind service irrespective of interface state (up/down)
boolean isPortSecurityEnable = aclInterfaceAfter.isPortSecurityEnabled();
boolean isPortSecurityEnableBefore = aclInterfaceBefore.isPortSecurityEnabled();
// if port security enable is changed and is disabled, unbind ACL service
if (isPortSecurityEnableBefore != isPortSecurityEnable && !isPortSecurityEnable) {
LOG.debug("Notify unbind ACL service for interface={}, isPortSecurityEnable={}", interfaceId, isPortSecurityEnable);
aclServiceManager.notify(aclInterfaceAfter, null, Action.UNBIND);
}
if (interfaceState != null && interfaceState.getOperStatus().equals(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Up)) {
// if port security enable is changed and is enabled, bind ACL service
if (isPortSecurityEnableBefore != isPortSecurityEnable && isPortSecurityEnable) {
LOG.debug("Notify bind ACL service for interface={}, isPortSecurityEnable={}", interfaceId, isPortSecurityEnable);
aclServiceManager.notify(aclInterfaceAfter, null, Action.BIND);
}
LOG.debug("On update event, notify ACL service manager to update ACL for interface: {}", interfaceId);
// handle add for AclPortsLookup before processing update
try {
Futures.allAsList(aclServiceUtils.addAclPortsLookupForInterfaceUpdate(aclInterfaceBefore, aclInterfaceAfter)).get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error adding ACL ports for interface update", e);
}
aclServiceManager.notify(aclInterfaceAfter, aclInterfaceBefore, AclServiceManager.Action.UPDATE);
// handle delete for AclPortsLookup after processing update
try {
Futures.allAsList(aclServiceUtils.deleteAclPortsLookupForInterfaceUpdate(aclInterfaceBefore, aclInterfaceAfter)).get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error deleting ACL ports for interface update", e);
}
}
}
updateCacheWithAclChange(aclInterfaceBefore, aclInterfaceAfter);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.multipart.reply.multipart.reply.body.multipart.reply.port.desc.Ports 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.flow.types.port.rev130925.multipart.reply.multipart.reply.body.multipart.reply.port.desc.Ports in project netvirt by opendaylight.
the class NeutronvpnManager method updateVpnInternetForSubnet.
protected void updateVpnInternetForSubnet(Subnetmap sm, Uuid vpn, boolean isBeingAssociated) {
LOG.debug("updateVpnInternetForSubnet: {} subnet {} with BGPVPN Internet {} ", isBeingAssociated ? "associating" : "dissociating", sm.getSubnetIp(), vpn.getValue());
Uuid internalVpnId = sm.getVpnId();
if (internalVpnId == null) {
LOG.error("updateVpnInternetForSubnet: can not find Internal or BGPVPN Id for subnet {}, bailing out", sm.getId().getValue());
return;
}
if (isBeingAssociated) {
updateSubnetNode(sm.getId(), null, sm.getVpnId(), vpn);
} else {
updateSubnetNode(sm.getId(), null, sm.getVpnId(), null);
}
jobCoordinator.enqueueJob("VPN-" + vpn.getValue(), () -> singletonList(managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(wrtConfigTxn -> {
if (isBeingAssociated) {
updateVpnInterface(vpn, null, neutronvpnUtils.getNeutronPort(sm.getRouterInterfacePortId()), true, true, wrtConfigTxn);
} else {
removeVpnFromVpnInterface(vpn, neutronvpnUtils.getNeutronPort(sm.getRouterInterfacePortId()), wrtConfigTxn, sm);
}
})));
// Check for ports on this subnet and update association of
// corresponding vpn-interfaces to internet vpn
List<Uuid> portList = sm.getPortList();
if (portList != null) {
for (Uuid port : portList) {
LOG.debug("Updating vpn-interface for port {} isBeingAssociated {}", port.getValue(), isBeingAssociated);
jobCoordinator.enqueueJob("PORT-" + port.getValue(), () -> {
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
List<ListenableFuture<Void>> futures = new ArrayList<>();
if (isBeingAssociated) {
updateVpnInterface(vpn, null, neutronvpnUtils.getNeutronPort(port), isBeingAssociated, false, wrtConfigTxn);
} else {
removeVpnFromVpnInterface(vpn, neutronvpnUtils.getNeutronPort(port), wrtConfigTxn, sm);
}
futures.add(wrtConfigTxn.submit());
return futures;
});
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.multipart.reply.multipart.reply.body.multipart.reply.port.desc.Ports in project netvirt by opendaylight.
the class NeutronvpnManager method removeSubnetFromVpn.
protected void removeSubnetFromVpn(final Uuid vpnId, Uuid subnet, Uuid internetVpnId) {
Preconditions.checkArgument(vpnId != null || internetVpnId != null, "removeSubnetFromVpn: at least one VPN must be not null");
LOG.debug("Removing subnet {} from vpn {}/{}", subnet.getValue(), vpnId, internetVpnId);
Subnetmap sn = neutronvpnUtils.getSubnetmap(subnet);
if (sn == null) {
LOG.error("removeSubnetFromVpn: Subnetmap for subnet {} not found", subnet.getValue());
return;
}
VpnMap vpnMap = null;
VpnInstance vpnInstance = null;
if (vpnId != null) {
vpnMap = neutronvpnUtils.getVpnMap(vpnId);
if (vpnMap == null) {
LOG.error("No vpnMap for vpnId {}, cannot remove subnet {} from VPN", vpnId.getValue(), subnet.getValue());
return;
}
vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
}
if (internetVpnId == null) {
internetVpnId = sn.getInternetVpnId();
}
if (internetVpnId != null) {
vpnMap = neutronvpnUtils.getVpnMap(internetVpnId);
if (vpnMap == null) {
LOG.error("No vpnMap for vpnId {}, cannot remove subnet {}" + " from Internet VPN", internetVpnId.getValue(), subnet.getValue());
return;
}
}
if (vpnInstance != null && isVpnOfTypeL2(vpnInstance)) {
neutronEvpnUtils.updateElanAndVpn(vpnInstance, sn.getNetworkId().getValue(), NeutronEvpnUtils.Operation.DELETE);
}
boolean subnetVpnAssociation = false;
if (vpnId != null && sn.getVpnId() != null && sn.getVpnId().getValue().equals(vpnId.getValue())) {
subnetVpnAssociation = true;
} else if (internetVpnId != null && sn.getInternetVpnId() != null && sn.getInternetVpnId().getValue().matches(internetVpnId.getValue())) {
subnetVpnAssociation = true;
}
if (subnetVpnAssociation == false) {
LOG.error("Removing subnet : Subnetmap is not in VPN {}/{}, owns {} and {}", vpnId, internetVpnId, sn.getVpnId(), sn.getInternetVpnId());
return;
}
// Check if there are ports on this subnet; remove corresponding vpn-interfaces
List<Uuid> portList = sn.getPortList();
final Uuid internetId = internetVpnId;
if (portList != null) {
for (final Uuid portId : portList) {
LOG.debug("withdrawing subnet IP {} from vpn-interface {}", sn.getSubnetIp(), portId.getValue());
final Port port = neutronvpnUtils.getNeutronPort(portId);
jobCoordinator.enqueueJob("PORT-" + portId.getValue(), () -> {
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
List<ListenableFuture<Void>> futures = new ArrayList<>();
if (port != null) {
withdrawPortIpFromVpnIface(vpnId, internetId, port, sn, wrtConfigTxn);
} else {
LOG.warn("Cannot proceed with withdrawPortIpFromVpnIface for port {} in subnet {} since " + "port is absent in Neutron config DS", portId.getValue(), subnet.getValue());
}
futures.add(wrtConfigTxn.submit());
return futures;
});
}
}
// update subnet-vpn association
removeFromSubnetNode(subnet, null, null, vpnId, null);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.multipart.reply.multipart.reply.body.multipart.reply.port.desc.Ports in project netvirt by opendaylight.
the class NeutronvpnManager method createSubnetmapNode.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void createSubnetmapNode(Uuid subnetId, String subnetIp, Uuid tenantId, Uuid networkId, NetworkAttributes.NetworkType networkType, long segmentationId) {
try {
InstanceIdentifier<Subnetmap> subnetMapIdentifier = NeutronvpnUtils.buildSubnetMapIdentifier(subnetId);
synchronized (subnetId.getValue().intern()) {
LOG.info("createSubnetmapNode: subnet ID {}", subnetId.toString());
Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier);
if (sn.isPresent()) {
LOG.error("createSubnetmapNode: Subnetmap node for subnet ID {} already exists, returning", subnetId.getValue());
return;
}
SubnetmapBuilder subnetmapBuilder = new SubnetmapBuilder().setKey(new SubnetmapKey(subnetId)).setId(subnetId).setSubnetIp(subnetIp).setTenantId(tenantId).setNetworkId(networkId).setNetworkType(networkType).setSegmentationId(segmentationId);
LOG.debug("createSubnetmapNode: Adding a new subnet node in Subnetmaps DS for subnet {}", subnetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier, subnetmapBuilder.build());
}
} catch (TransactionCommitFailedException | ReadFailedException e) {
LOG.error("createSubnetmapNode: Creating subnetmap node failed for subnet {}", subnetId.getValue());
}
// check if there are ports to update for already created Subnetmap node
LOG.debug("createSubnetmapNode: Update created Subnetmap for subnet {} with ports", subnetId.getValue());
for (Map.Entry<Uuid, Uuid> entry : unprocessedPortsMap.entrySet()) {
if (entry.getValue().getValue().equals(subnetId.getValue())) {
updateSubnetmapNodeWithPorts(subnetId, entry.getKey(), null);
unprocessedPortsMap.remove(entry.getKey());
}
}
}
Aggregations