use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo in project netvirt by opendaylight.
the class AclInterfaceListener method addOrUpdateAclInterfaceCache.
private AclInterface addOrUpdateAclInterfaceCache(String interfaceId, InterfaceAcl aclInPort, boolean isSgChanged, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.@Nullable Interface interfaceState) {
AclInterface aclInterface = aclInterfaceCache.addOrUpdate(interfaceId, (prevAclInterface, builder) -> {
List<Uuid> sgs = new ArrayList<>();
if (aclInPort != null) {
sgs = aclInPort.getSecurityGroups();
builder.portSecurityEnabled(aclInPort.isPortSecurityEnabled()).interfaceType(aclInPort.getInterfaceType()).securityGroups(sgs).allowedAddressPairs(new ArrayList<AllowedAddressPairs>(aclInPort.nonnullAllowedAddressPairs().values())).subnetInfo(new ArrayList<SubnetInfo>(aclInPort.nonnullSubnetInfo().values()));
}
if ((prevAclInterface == null || prevAclInterface.getLPortTag() == null) && interfaceState != null) {
builder.dpId(AclServiceUtils.getDpIdFromIterfaceState(interfaceState)).lPortTag(interfaceState.getIfIndex()).isMarkedForDelete(false);
}
if (prevAclInterface == null || prevAclInterface.getElanId() == null) {
builder.elanId(AclServiceUtils.getElanIdFromInterface(interfaceId, dataBroker));
}
if (prevAclInterface == null || isSgChanged) {
builder.ingressRemoteAclTags(aclServiceUtils.getRemoteAclTags(sgs, DirectionIngress.class)).egressRemoteAclTags(aclServiceUtils.getRemoteAclTags(sgs, DirectionEgress.class));
}
});
// Clone and return the ACL interface object
return AclInterface.builder(aclInterface).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo in project netvirt by opendaylight.
the class VirtualPort method getIpv6Addresses.
@Override
public List<Ipv6Address> getIpv6Addresses() {
List<Ipv6Address> ipv6AddrList = snetInfo.values().stream().flatMap(subnetInfo -> Stream.of(subnetInfo.getIpAddr().getIpv6Address())).collect(Collectors.toList());
if (deviceOwner.equalsIgnoreCase(Ipv6ServiceConstants.NETWORK_ROUTER_INTERFACE)) {
Ipv6Address llAddr = Ipv6Util.getIpv6LinkLocalAddressFromMac(new MacAddress(macAddress));
ipv6AddrList.add(llAddr);
}
return ipv6AddrList;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo in project netvirt by opendaylight.
the class NaptManager method registerMapping.
// 1. napt service functions
/**
* This method is used to inform this service of what external IP address to be used
* as mapping when requested one for the internal IP address given in the input.
*
* @param segmentId – segmentation in which the mapping to be used. Eg; routerid
* @param internal subnet prefix or ip address
* @param external subnet prefix or ip address
*/
public void registerMapping(Uint32 segmentId, IPAddress internal, IPAddress external) {
LOG.debug("registerMapping : called with segmentid {}, internalIp {}, prefix {}, externalIp {} " + "and prefix {} ", segmentId, internal.getIpAddress(), internal.getPrefixLength(), external.getIpAddress(), external.getPrefixLength());
// Create Pool per ExternalIp and not for all IPs in the subnet.
// Create new Pools during getExternalAddressMapping if exhausted.
String externalIpPool;
// subnet case
if (external.getPrefixLength() != 0 && external.getPrefixLength() != NatConstants.DEFAULT_PREFIX) {
String externalSubnet = external.getIpAddress() + "/" + external.getPrefixLength();
LOG.debug("registerMapping : externalSubnet is : {}", externalSubnet);
SubnetUtils subnetUtils = new SubnetUtils(externalSubnet);
SubnetInfo subnetInfo = subnetUtils.getInfo();
externalIpPool = subnetInfo.getLowAddress();
} else {
// ip case
externalIpPool = external.getIpAddress();
}
createNaptPortPool(externalIpPool);
// Store the ip to ip map in Operational DS
String internalIp = internal.getIpAddress();
if (internal.getPrefixLength() != 0) {
internalIp = internal.getIpAddress() + "/" + internal.getPrefixLength();
}
String externalIp = external.getIpAddress();
if (external.getPrefixLength() != 0) {
externalIp = external.getIpAddress() + "/" + external.getPrefixLength();
}
updateCounter(segmentId, externalIp, true);
// update the actual ip-map
IpMap ipm = new IpMapBuilder().withKey(new IpMapKey(internalIp)).setInternalIp(internalIp).setExternalIp(externalIp).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, getIpMapIdentifier(segmentId, internalIp), ipm);
LOG.debug("registerMapping : registerMapping exit after updating DS with internalIP {}, externalIP {}", internalIp, externalIp);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo in project netvirt by opendaylight.
the class NaptManager method checkIpMap.
@Nullable
protected String checkIpMap(Uint32 segmentId, String internalIp) {
LOG.debug("checkIpMap : called with segmentId {} and internalIp {}", segmentId, internalIp);
String externalIp;
// check if ip-map node is there
InstanceIdentifierBuilder<IpMapping> idBuilder = InstanceIdentifier.builder(IntextIpMap.class).child(IpMapping.class, new IpMappingKey(segmentId));
InstanceIdentifier<IpMapping> id = idBuilder.build();
Optional<IpMapping> ipMapping = Optional.empty();
try {
ipMapping = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
} catch (ExecutionException | InterruptedException e) {
LOG.error("checkIpMap: Exception while reading IpMapping DS for the segmentId {} internalIp {}", segmentId, internalIp, e);
}
if (ipMapping.isPresent()) {
for (IpMap ipMap : ipMapping.get().nonnullIpMap().values()) {
if (Objects.equals(ipMap.getInternalIp(), internalIp)) {
LOG.debug("checkIpMap : IpMap : {}", ipMap);
externalIp = ipMap.getExternalIp();
LOG.debug("checkIpMap : successfully returning externalIp {}", externalIp);
return externalIp;
} else if (ipMap.getInternalIp().contains("/")) {
// subnet case
SubnetUtils subnetUtils = new SubnetUtils(ipMap.getInternalIp());
SubnetInfo subnetInfo = subnetUtils.getInfo();
if (subnetInfo.isInRange(internalIp)) {
LOG.debug("checkIpMap : internalIp {} found to be IpMap of internalIpSubnet {}", internalIp, ipMap.getInternalIp());
externalIp = ipMap.getExternalIp();
LOG.debug("checkIpMap : checkIpMap successfully returning externalIp {}", externalIp);
return externalIp;
}
}
}
}
// return null if not found
LOG.error("checkIpMap : failed, returning NULL for segmentId {} and internalIp {}", segmentId, internalIp);
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo 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