use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.SfpName in project netvirt by opendaylight.
the class PortChainTranslator method buildServiceFunctionPath.
public static ServiceFunctionPath buildServiceFunctionPath(ServiceFunctionChain sfc) {
Preconditions.checkNotNull(sfc, "Service Function Chain must not be null");
ServiceFunctionPathBuilder sfpBuilder = new ServiceFunctionPathBuilder();
// Set the name
sfpBuilder.setName(new SfpName(SFP_NAME_PREFIX + sfc.getName().getValue()));
sfpBuilder.setSymmetric(sfc.isSymmetric());
// Set related SFC name
sfpBuilder.setServiceChainName(sfc.getName());
return sfpBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.SfpName in project netvirt by opendaylight.
the class ConfigurationClassifierImpl method getEntriesForAce.
private Set<ClassifierRenderableEntry> getEntriesForAce(Ace ace) {
String ruleName = ace.getRuleName();
LOG.debug("Generating classifier entries for Ace: {}", ruleName);
LOG.trace("Ace details: {}", ace);
Optional<NetvirtsfcAclActions> sfcActions = Optional.ofNullable(ace.getActions()).map(actions -> actions.getAugmentation(RedirectToSfc.class));
String rspName = sfcActions.map(NetvirtsfcAclActions::getRspName).map(Strings::emptyToNull).orElse(null);
String sfpName = sfcActions.map(NetvirtsfcAclActions::getSfpName).map(Strings::emptyToNull).orElse(null);
if (rspName == null && sfpName == null) {
LOG.debug("Ace {} ignored: no valid SFC redirect action", ruleName);
return Collections.emptySet();
}
if (rspName != null && sfpName != null) {
LOG.warn("Ace {} ignored: both SFP and a RSP as redirect actions not supported", ruleName);
return Collections.emptySet();
}
Matches matches = ace.getMatches();
if (matches == null) {
LOG.warn("Ace {} ignored: no matches", ruleName);
return Collections.emptySet();
}
NeutronNetwork network = matches.getAugmentation(NeutronNetwork.class);
if (sfpName != null && network != null) {
LOG.warn("Ace {} ignored: SFP redirect action with neutron network match not supported", ruleName);
return Collections.emptySet();
}
String sourcePort = Optional.ofNullable(matches.getAugmentation(NeutronPorts.class)).map(NeutronPorts::getSourcePortUuid).map(Strings::emptyToNull).orElse(null);
String destinationPort = Optional.ofNullable(matches.getAugmentation(NeutronPorts.class)).map(NeutronPorts::getDestinationPortUuid).map(Strings::emptyToNull).orElse(null);
if (rspName != null) {
return getEntriesForRspRedirect(ruleName, sourcePort, destinationPort, network, rspName, matches);
}
return getEntriesForSfpRedirect(ruleName, sourcePort, destinationPort, sfpName, matches);
}
use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.SfpName in project netvirt by opendaylight.
the class ConfigurationClassifierImpl method getEntriesForSfpRedirect.
private Set<ClassifierRenderableEntry> getEntriesForSfpRedirect(String ruleName, String srcPort, String dstPort, String sfpName, Matches matches) {
if (srcPort == null && dstPort == null) {
LOG.warn("Ace {} ignored: no source or destination port to match against", ruleName);
return Collections.emptySet();
}
if (Objects.equals(srcPort, dstPort)) {
LOG.warn("Ace {} ignored: equal source and destination port not supported", ruleName);
return Collections.emptySet();
}
List<RenderedServicePath> rsps = sfcProvider.readServicePathState(sfpName).orElse(Collections.emptyList()).stream().map(sfcProvider::getRenderedServicePath).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
// be missing. It will be handled on a later listener event.
if (rsps.isEmpty()) {
LOG.debug("Ace {} ignored: no RSPs for SFP {} yet available", ruleName, sfpName);
return Collections.emptySet();
}
// An SFP will have two RSPs associated if symmetric, one otherwise.
if (rsps.size() > 2) {
LOG.warn("Ace {} ignored: more than two RSPs associated to SFP {} not supported", ruleName, sfpName);
return Collections.emptySet();
}
RenderedServicePath forwardRsp = rsps.stream().filter(rsp -> !rsp.isReversePath()).findAny().orElse(null);
RenderedServicePath reverseRsp = rsps.stream().filter(RenderedServicePath::isReversePath).filter(rsp -> forwardRsp != null && rsp.getSymmetricPathId().equals(forwardRsp.getPathId())).findAny().orElse(null);
if (srcPort != null && forwardRsp == null) {
LOG.debug("Ace {} ignored: no forward RSP yet available for SFP {} and source port {}", ruleName, sfpName, srcPort);
return Collections.emptySet();
}
if (dstPort != null && reverseRsp == null) {
LOG.debug("Ace {} ignored: no reverse RSP yet available for SFP {} and destination port {}", ruleName, sfpName, dstPort);
return Collections.emptySet();
}
Set<ClassifierRenderableEntry> entries = new HashSet<>();
if (srcPort != null) {
entries.addAll(this.buildEntries(ruleName, Collections.singletonList(srcPort), matches, forwardRsp));
}
if (dstPort != null) {
Matches invertedMatches = AclMatches.invertMatches(matches);
entries.addAll(this.buildEntries(ruleName, Collections.singletonList(dstPort), invertedMatches, reverseRsp));
}
return entries;
}
use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.SfpName in project netvirt by opendaylight.
the class FlowClassifierTranslator method buildAcl.
public static Acl buildAcl(SfcFlowClassifier flowClassifier, String sfpName) {
LOG.info("OpenStack Networking SFC pushed Flow classifier : {}", flowClassifier);
AclBuilder aclBuilder = new AclBuilder();
AceBuilder aceBuilder = new AceBuilder();
ActionsBuilder actionsBuilder = new ActionsBuilder();
RedirectToSfcBuilder redirectToSfcBuilder = new RedirectToSfcBuilder();
NeutronPortsBuilder neutronPortsBuilder = new NeutronPortsBuilder();
AceIpBuilder aceIpBuilder = new AceIpBuilder();
DestinationPortRangeBuilder destinationPortRange = new DestinationPortRangeBuilder();
SourcePortRangeBuilder sourcePortRangeBuilder = new SourcePortRangeBuilder();
if (flowClassifier.getUuid() != null) {
if (flowClassifier.getName() != null) {
aclBuilder.setAclName(flowClassifier.getUuid().getValue() + "_" + flowClassifier.getName());
} else {
aclBuilder.setAclName(flowClassifier.getUuid().getValue());
}
}
if (flowClassifier.getEthertype() != null) {
IpPrefix sourceIp = null;
IpPrefix destinationIp = null;
if (flowClassifier.getSourceIpPrefix() != null) {
sourceIp = flowClassifier.getSourceIpPrefix();
}
if (flowClassifier.getDestinationIpPrefix() != null) {
destinationIp = flowClassifier.getDestinationIpPrefix();
}
if (flowClassifier.getEthertype() == EthertypeV4.class) {
AceIpv4Builder aceIpv4Builder = new AceIpv4Builder();
if (sourceIp != null && sourceIp.getIpv4Prefix() != null) {
aceIpv4Builder.setSourceIpv4Network(sourceIp.getIpv4Prefix());
}
if (destinationIp != null && destinationIp.getIpv4Prefix() != null) {
aceIpv4Builder.setDestinationIpv4Network(destinationIp.getIpv4Prefix());
}
aceIpBuilder.setAceIpVersion(aceIpv4Builder.build());
aclBuilder.setAclType(Ipv4Acl.class);
}
if (flowClassifier.getEthertype() == EthertypeV6.class) {
AceIpv6Builder aceIpv6Builder = new AceIpv6Builder();
if (sourceIp != null && sourceIp.getIpv6Prefix() != null) {
aceIpv6Builder.setSourceIpv6Network(sourceIp.getIpv6Prefix());
}
if (sourceIp != null && destinationIp.getIpv6Prefix() != null) {
aceIpv6Builder.setDestinationIpv6Network(destinationIp.getIpv6Prefix());
}
aceIpBuilder.setAceIpVersion(aceIpv6Builder.build());
aclBuilder.setAclType(Ipv6Acl.class);
}
}
if (flowClassifier.getProtocol() != null) {
if (flowClassifier.getProtocol() == ProtocolTcp.class) {
aceIpBuilder.setProtocol(PROTO_TCP);
}
if (flowClassifier.getProtocol() == ProtocolUdp.class) {
aceIpBuilder.setProtocol(PROTO_UDP);
}
}
if (flowClassifier.getSourcePortRangeMin() != null) {
sourcePortRangeBuilder.setLowerPort(new PortNumber(flowClassifier.getSourcePortRangeMin()));
// set source port range only if lower port is specified as it is a mandatory parameter in acl model
aceIpBuilder.setSourcePortRange(sourcePortRangeBuilder.build());
}
if (flowClassifier.getSourcePortRangeMax() != null) {
sourcePortRangeBuilder.setUpperPort(new PortNumber(flowClassifier.getSourcePortRangeMax()));
}
if (flowClassifier.getDestinationPortRangeMin() != null) {
destinationPortRange.setLowerPort(new PortNumber(flowClassifier.getDestinationPortRangeMin()));
// set destination port range only if lower port is specified as it is a mandatory parameter in acl model
aceIpBuilder.setDestinationPortRange(destinationPortRange.build());
}
if (flowClassifier.getDestinationPortRangeMax() != null) {
destinationPortRange.setUpperPort(new PortNumber(flowClassifier.getDestinationPortRangeMax()));
}
if (flowClassifier.getLogicalSourcePort() != null) {
neutronPortsBuilder.setSourcePortUuid(flowClassifier.getLogicalSourcePort().getValue());
}
if (flowClassifier.getLogicalDestinationPort() != null) {
neutronPortsBuilder.setDestinationPortUuid(flowClassifier.getLogicalDestinationPort().getValue());
}
// currently not supported.
// if (flowClassifier.getL7Parameter() != null) {
// }
MatchesBuilder matchesBuilder = new MatchesBuilder();
matchesBuilder.setAceType(aceIpBuilder.build());
matchesBuilder.addAugmentation(NeutronPorts.class, neutronPortsBuilder.build());
// Set redirect-to-rsp action if rsp name is provided
if (sfpName != null) {
redirectToSfcBuilder.setSfpName(sfpName);
actionsBuilder.addAugmentation(RedirectToSfc.class, redirectToSfcBuilder.build());
aceBuilder.setActions(actionsBuilder.build());
}
aceBuilder.setMatches(matchesBuilder.build());
// OpenStack networking-sfc don't pass action information
// with flow classifier. It need to be determined using the
// Port Chain data and then flow calssifier need to be updated
// with the actions.
aceBuilder.setRuleName(aclBuilder.getAclName() + RULE);
aceBuilder.setKey(new AceKey(aceBuilder.getRuleName()));
ArrayList<Ace> aceList = new ArrayList<>();
aceList.add(aceBuilder.build());
AccessListEntriesBuilder accessListEntriesBuilder = new AccessListEntriesBuilder();
accessListEntriesBuilder.setAce(aceList);
aclBuilder.setAccessListEntries(accessListEntriesBuilder.build());
aclBuilder.setKey(new AclKey(aclBuilder.getAclName(), aclBuilder.getAclType()));
LOG.info("Translated ACL Flow classfier : {}", aclBuilder.toString());
return aclBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.SfpName in project netvirt by opendaylight.
the class SfcProvider method readServicePathState.
public Optional<List<String>> readServicePathState(String sfpName) {
ServiceFunctionPathStateKey serviceFunctionPathStateKey = new ServiceFunctionPathStateKey(new SfpName(sfpName));
InstanceIdentifier<ServiceFunctionPathState> sfpIiD;
sfpIiD = InstanceIdentifier.builder(ServiceFunctionPathsState.class).child(ServiceFunctionPathState.class, serviceFunctionPathStateKey).build();
return MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, sfpIiD).toJavaUtil().map(ServiceFunctionPathState::getSfpRenderedServicePath).map(sfpRenderedServicePaths -> sfpRenderedServicePaths.stream().map(sfpRenderedServicePath -> sfpRenderedServicePath.getName().getValue()).collect(Collectors.toList()));
}
Aggregations