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.
protected String checkIpMap(long 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 = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (ipMapping.isPresent()) {
List<IpMap> ipMaps = ipMapping.get().getIpMap();
for (IpMap ipMap : ipMaps) {
if (ipMap.getInternalIp().equals(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 IngressAclServiceImpl method programIcmpv6RARule.
@Override
protected void programIcmpv6RARule(List<FlowEntity> flowEntries, AclInterface port, List<SubnetInfo> subnets, int addOrRemove) {
if (!AclServiceUtils.isIpv6Subnet(subnets)) {
return;
}
Uint64 dpid = Uint64.valueOf(port.getDpId());
/* Allow ICMPv6 Router Advertisement packets from external routers as well as internal routers
* if subnet is configured with IPv6 version
* Allow ICMPv6 Router Advertisement packets if originating from any LinkLocal Address.
*/
List<InstructionInfo> instructions = getDispatcherTableResubmitInstructions();
List<MatchInfoBase> matches = AclServiceUtils.buildIcmpV6Matches(AclConstants.ICMPV6_TYPE_RA, 0, port.getLPortTag(), serviceMode);
matches.addAll(AclServiceUtils.buildIpMatches(new IpPrefixOrAddress(IpPrefixBuilder.getDefaultInstance(AclConstants.IPV6_LINK_LOCAL_PREFIX)), AclServiceManager.MatchCriteria.MATCH_SOURCE));
String flowName = "Ingress_ICMPv6" + "_" + dpid + "_" + port.getLPortTag() + "_" + AclConstants.ICMPV6_TYPE_RA + "_LinkLocal_Permit_";
addFlowEntryToList(flowEntries, dpid, getAclAntiSpoofingTable(), flowName, AclConstants.PROTO_IPV6_ALLOWED_PRIORITY, 0, 0, AclConstants.COOKIE_ACL_BASE, matches, instructions, addOrRemove);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo in project netvirt by opendaylight.
the class AclInterfaceStateListener method add.
@Override
public void add(InstanceIdentifier<Interface> key, Interface added) {
if (!L2vlan.class.equals(added.getType())) {
return;
}
if (aclInterfaceCache.get(added.getName()) == null) {
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = interfaceManager.getInterfaceInfoFromConfigDataStore(added.getName());
if (iface == null) {
LOG.error("No interface with name {} available in interfaceConfig, servicing interfaceState ADD" + "for ACL failed", added.getName());
return;
}
InterfaceAcl aclInPort = iface.augmentation(InterfaceAcl.class);
if (aclInPort == null) {
LOG.trace("Interface {} is not an ACL Interface, ignoring ADD interfaceState event", added.getName());
return;
}
aclInterfaceCache.addOrUpdate(added.getName(), (prevAclInterface, builder) -> {
builder.portSecurityEnabled(aclInPort.isPortSecurityEnabled()).interfaceType(aclInPort.getInterfaceType()).securityGroups(aclInPort.getSecurityGroups()).allowedAddressPairs(new ArrayList<AllowedAddressPairs>(aclInPort.nonnullAllowedAddressPairs().values())).subnetInfo(new ArrayList<SubnetInfo>(aclInPort.nonnullSubnetInfo().values()));
});
}
AclInterface aclInterface = aclInterfaceCache.addOrUpdate(added.getName(), (prevAclInterface, builder) -> {
builder.dpId(AclServiceUtils.getDpIdFromIterfaceState(added)).lPortTag(added.getIfIndex()).isMarkedForDelete(false);
if (AclServiceUtils.isOfInterest(prevAclInterface)) {
SortedSet<Integer> ingressRemoteAclTags = aclServiceUtils.getRemoteAclTags(prevAclInterface.getSecurityGroups(), DirectionIngress.class);
SortedSet<Integer> egressRemoteAclTags = aclServiceUtils.getRemoteAclTags(prevAclInterface.getSecurityGroups(), DirectionEgress.class);
builder.ingressRemoteAclTags(ingressRemoteAclTags).egressRemoteAclTags(egressRemoteAclTags);
}
});
if (AclServiceUtils.isOfInterest(aclInterface)) {
List<Uuid> aclList = aclInterface.getSecurityGroups();
if (aclList != null) {
aclDataUtil.addOrUpdateAclInterfaceMap(aclList, aclInterface);
}
if (aclInterface.getElanId() == null) {
LOG.debug("On Add event, skip ADD since ElanId is not updated");
return;
}
if (aclClusterUtil.isEntityOwner()) {
LOG.debug("On add event, notify ACL service manager to add ACL for interface: {}", aclInterface);
aclServiceManger.notify(aclInterface, null, Action.BIND);
if (aclList != null) {
aclServiceUtils.addAclPortsLookup(aclInterface, aclList, aclInterface.getAllowedAddressPairs());
}
aclServiceManger.notify(aclInterface, null, Action.ADD);
}
}
}
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(long 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().setKey(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 genius by opendaylight.
the class VtepConfigSchemaListener method calculateAvailableIps.
/**
* Calculate available ips.
*
* @param subnetUtils
* the subnet cidr
* @param excludeIpFilter
* the exclude ip filter
* @param gatewayIp
* the gateway IP
* @return the list
*/
private List<IpAddress> calculateAvailableIps(SubnetUtils subnetUtils, String excludeIpFilter, IpAddress gatewayIp) {
List<IpAddress> lstAvailableIps = new ArrayList<>();
SubnetInfo subnetInfo = subnetUtils.getInfo();
String[] arrIpAddresses = subnetInfo.getAllAddresses();
for (String ipAddress : arrIpAddresses) {
lstAvailableIps.add(IpAddressBuilder.getDefaultInstance(ipAddress));
}
lstAvailableIps.remove(gatewayIp);
lstAvailableIps.removeAll(ItmUtils.getExcludeIpAddresses(excludeIpFilter, subnetInfo));
return lstAvailableIps;
}
Aggregations