use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port in project netvirt by opendaylight.
the class PortPairGroupTranslator method buildServiceFunctionForwarder.
public static ServiceFunctionForwarder buildServiceFunctionForwarder(PortPairGroup portPairGroup, List<PortPair> portPairs) {
Preconditions.checkNotNull(portPairGroup, "Port pair group must not be null");
Preconditions.checkNotNull(portPairs, "Port pairs must not be null");
Preconditions.checkElementIndex(0, portPairs.size(), "There must be at least one port pair");
// Currently we only support one SF per type. Mean, one port-pair per port-pair-group.
final PortPair portPair = portPairs.get(0);
ServiceFunctionForwarderBuilder sffBuilder = new ServiceFunctionForwarderBuilder();
sffBuilder.setName(new SffName(SfcMdsalHelper.NETVIRT_LOGICAL_SFF_NAME));
DataPlaneLocatorBuilder forwardDplBuilder = new DataPlaneLocatorBuilder();
forwardDplBuilder.setTransport(Mac.class);
String forwardPort = portPair.getIngress().getValue();
LogicalInterface forwardInterface = new LogicalInterfaceBuilder().setInterfaceName(forwardPort).build();
forwardDplBuilder.setLocatorType(forwardInterface);
SffDataPlaneLocatorBuilder sffForwardDplBuilder = new SffDataPlaneLocatorBuilder();
sffForwardDplBuilder.setDataPlaneLocator(forwardDplBuilder.build());
String forwardDplName = portPair.getName() + DPL_INGRESS_SUFFIX;
sffForwardDplBuilder.setName(new SffDataPlaneLocatorName(forwardDplName));
DataPlaneLocatorBuilder reverseDplBuilder = new DataPlaneLocatorBuilder();
reverseDplBuilder.setTransport(Mac.class);
String reversePort = portPair.getEgress().getValue();
LogicalInterface reverseInterface = new LogicalInterfaceBuilder().setInterfaceName(reversePort).build();
reverseDplBuilder.setLocatorType(reverseInterface);
SffDataPlaneLocatorBuilder sffReverseDplBuilder = new SffDataPlaneLocatorBuilder();
sffReverseDplBuilder.setDataPlaneLocator(reverseDplBuilder.build());
String reverseDplName = portPair.getName() + DPL_EGRESS_SUFFIX;
sffReverseDplBuilder.setName(new SffDataPlaneLocatorName(reverseDplName));
List<SffDataPlaneLocator> sffDataPlaneLocator = new ArrayList<>();
sffDataPlaneLocator.add(sffForwardDplBuilder.build());
sffDataPlaneLocator.add(sffReverseDplBuilder.build());
sffBuilder.setSffDataPlaneLocator(sffDataPlaneLocator);
SffSfDataPlaneLocatorBuilder sffSfDataPlaneLocatorBuilder = new SffSfDataPlaneLocatorBuilder();
sffSfDataPlaneLocatorBuilder.setSffForwardDplName(new SffDataPlaneLocatorName(forwardDplName));
sffSfDataPlaneLocatorBuilder.setSfForwardDplName(new SfDataPlaneLocatorName(forwardDplName));
sffSfDataPlaneLocatorBuilder.setSffReverseDplName(new SffDataPlaneLocatorName(reverseDplName));
sffSfDataPlaneLocatorBuilder.setSfReverseDplName(new SfDataPlaneLocatorName(reverseDplName));
ServiceFunctionDictionaryBuilder sfdBuilder = new ServiceFunctionDictionaryBuilder();
sfdBuilder.setName(new SfName(portPair.getName()));
sfdBuilder.setSffSfDataPlaneLocator(sffSfDataPlaneLocatorBuilder.build());
List<ServiceFunctionDictionary> sfdList = new ArrayList<>();
sfdList.add(sfdBuilder.build());
sffBuilder.setServiceFunctionDictionary(sfdList);
return sffBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port in project netvirt by opendaylight.
the class NeutronPortPairListener method remove.
/**
* Method removes PortPair which is identified by InstanceIdentifier.
*
* @param deletedPortPair - PortPair for removing
*/
@Override
public void remove(PortPair deletedPortPair) {
LOG.info("Received remove port pair event {}", deletedPortPair);
ServiceFunctionKey sfKey = PortPairTranslator.getSFKey(deletedPortPair);
LOG.info("Removing service function {}", sfKey);
sfcMdsalHelper.removeServiceFunction(sfKey);
ServiceFunctionForwarder sff;
ServiceFunctionForwarder updatedSff;
SffName sffName = new SffName(SfcMdsalHelper.NETVIRT_LOGICAL_SFF_NAME);
sff = sfcMdsalHelper.readServiceFunctionForwarder(new ServiceFunctionForwarderKey(sffName));
updatedSff = PortPairGroupTranslator.removePortPairFromServiceFunctionForwarder(sff, deletedPortPair);
LOG.info("Updating service function forwarder as {}", updatedSff);
sfcMdsalHelper.addServiceFunctionForwarder(updatedSff);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port in project netvirt by opendaylight.
the class AclServiceOFFlowBuilder method programUdpFlow.
/**
*Converts UDP matches to flows.
* @param acl the access control list
* @return the map containing the flows and the respective flow id
*/
public static Map<String, List<MatchInfoBase>> programUdpFlow(AceIp acl) {
Map<String, List<MatchInfoBase>> flowMatchesMap = new HashMap<>();
SourcePortRange sourcePortRange = acl.getSourcePortRange();
DestinationPortRange destinationPortRange = acl.getDestinationPortRange();
if (sourcePortRange == null && destinationPortRange == null) {
List<MatchInfoBase> flowMatches = new ArrayList<>();
flowMatches.addAll(addSrcIpMatches(acl));
flowMatches.addAll(addDstIpMatches(acl));
flowMatches.add(new MatchIpProtocol(acl.getProtocol()));
String flowId = "UDP_SOURCE_ALL_";
flowMatchesMap.put(flowId, flowMatches);
return flowMatchesMap;
}
if (sourcePortRange != null) {
Map<Integer, Integer> portMaskMap = getLayer4MaskForRange(sourcePortRange.getLowerPort().getValue(), sourcePortRange.getUpperPort().getValue());
for (Entry<Integer, Integer> entry : portMaskMap.entrySet()) {
Integer port = entry.getKey();
List<MatchInfoBase> flowMatches = new ArrayList<>();
flowMatches.addAll(addSrcIpMatches(acl));
flowMatches.addAll(addDstIpMatches(acl));
Integer mask = entry.getValue();
if (mask != AclConstants.ALL_LAYER4_PORT_MASK) {
flowMatches.add(new NxMatchUdpSourcePort(port, mask));
}
flowMatches.add(new MatchIpProtocol(acl.getProtocol()));
String flowId = "UDP_SOURCE_" + port + "_" + mask;
flowMatchesMap.put(flowId, flowMatches);
}
}
if (destinationPortRange != null) {
Map<Integer, Integer> portMaskMap = getLayer4MaskForRange(destinationPortRange.getLowerPort().getValue(), destinationPortRange.getUpperPort().getValue());
for (Entry<Integer, Integer> entry : portMaskMap.entrySet()) {
Integer port = entry.getKey();
List<MatchInfoBase> flowMatches = new ArrayList<>();
flowMatches.addAll(addSrcIpMatches(acl));
flowMatches.addAll(addDstIpMatches(acl));
Integer mask = entry.getValue();
if (mask != AclConstants.ALL_LAYER4_PORT_MASK) {
flowMatches.add(new NxMatchUdpDestinationPort(port, mask));
}
flowMatches.add(new MatchIpProtocol(acl.getProtocol()));
String flowId = "UDP_DESTINATION_" + port + "_" + mask;
flowMatchesMap.put(flowId, flowMatches);
}
}
return flowMatchesMap;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port in project netvirt by opendaylight.
the class AclServiceOFFlowBuilder method programIcmpFlow.
/**
*Converts icmp matches to flows.
* @param acl the access control list
* @return the map containing the flows and the respective flow id
*/
public static Map<String, List<MatchInfoBase>> programIcmpFlow(AceIp acl) {
List<MatchInfoBase> flowMatches = new ArrayList<>();
flowMatches.addAll(addSrcIpMatches(acl));
flowMatches.addAll(addDstIpMatches(acl));
// For ICMP port range indicates type and code
SourcePortRange sourcePortRange = acl.getSourcePortRange();
String flowId = "ICMP_";
if (sourcePortRange != null) {
if (acl.getAceIpVersion() instanceof AceIpv4) {
flowMatches.add(new MatchIcmpv4(sourcePortRange.getLowerPort().getValue().shortValue(), sourcePortRange.getUpperPort().getValue().shortValue()));
flowId = flowId + "V4_SOURCE_" + sourcePortRange.getLowerPort().getValue() + sourcePortRange.getUpperPort().getValue();
} else if (acl.getAceIpVersion() instanceof AceIpv6) {
flowMatches.add(new MatchIcmpv6(sourcePortRange.getLowerPort().getValue().shortValue(), sourcePortRange.getUpperPort().getValue().shortValue()));
flowId = flowId + "V6_SOURCE_" + sourcePortRange.getLowerPort().getValue() + "_" + sourcePortRange.getUpperPort().getValue() + "_";
}
}
DestinationPortRange destinationPortRange = acl.getDestinationPortRange();
if (destinationPortRange != null) {
if (acl.getAceIpVersion() instanceof AceIpv4) {
flowMatches.add(new MatchIcmpv4(destinationPortRange.getLowerPort().getValue().shortValue(), destinationPortRange.getUpperPort().getValue().shortValue()));
flowId = flowId + "V4_DESTINATION_" + destinationPortRange.getLowerPort().getValue() + destinationPortRange.getUpperPort().getValue() + "_";
} else if (acl.getAceIpVersion() instanceof AceIpv6) {
flowMatches.add(new MatchIcmpv6(destinationPortRange.getLowerPort().getValue().shortValue(), destinationPortRange.getUpperPort().getValue().shortValue()));
flowId = flowId + "V6_DESTINATION_" + destinationPortRange.getLowerPort().getValue() + destinationPortRange.getUpperPort().getValue() + "_";
}
}
if (acl.getAceIpVersion() instanceof AceIpv6 && acl.getProtocol() == NwConstants.IP_PROT_ICMP) {
// We are aligning our implementation similar to Neutron Firewall driver where a Security
// Group rule with "Ethertype as IPv6 and Protocol as icmp" is treated as ICMPV6 SG Rule.
flowMatches.add(new MatchIpProtocol(AclConstants.IP_PROT_ICMPV6));
} else {
flowMatches.add(new MatchIpProtocol(acl.getProtocol()));
}
Map<String, List<MatchInfoBase>> flowMatchesMap = new HashMap<>();
flowMatchesMap.put(flowId, flowMatches);
return flowMatchesMap;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port in project netvirt by opendaylight.
the class AclServiceUtils method deleteAclPortsLookup.
public List<ListenableFuture<Void>> deleteAclPortsLookup(AclInterface port, List<Uuid> aclList, List<AllowedAddressPairs> allowedAddresses) {
String portId = port.getInterfaceId();
LOG.trace("Deleting AclPortsLookup for port={}, acls={}, AAPs={}", portId, aclList, allowedAddresses);
if (aclList == null || allowedAddresses == null || allowedAddresses.isEmpty()) {
LOG.warn("aclList or allowedAddresses is null. port={}, acls={}, AAPs={}", portId, aclList, allowedAddresses);
return Collections.emptyList();
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
for (Uuid aclId : aclList) {
String aclName = aclId.getValue();
synchronized (aclName.intern()) {
futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
for (AllowedAddressPairs aap : allowedAddresses) {
InstanceIdentifier<PortIds> path = AclServiceUtils.getPortIdsPathInAclPortsLookup(aclName, aap.getIpAddress(), portId);
tx.delete(LogicalDatastoreType.OPERATIONAL, path);
}
cleanUpStaleEntriesInAclPortsLookup(aclName, tx);
}));
}
}
return futures;
}
Aggregations