Search in sources :

Example 31 with Match

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match 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);
}
Also used : NetvirtsfcAclActions(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.sfc.acl.rev150105.NetvirtsfcAclActions) NeutronNetwork(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.sfc.acl.rev150105.NeutronNetwork) Matches(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches) AclMatches(org.opendaylight.netvirt.sfc.classifier.utils.AclMatches) RedirectToSfc(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.sfc.acl.rev150105.RedirectToSfc) NeutronPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.sfc.acl.rev150105.NeutronPorts)

Example 32 with Match

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match in project netvirt by opendaylight.

the class ConfigurationClassifierImpl method getEntriesForRspRedirect.

private Set<ClassifierRenderableEntry> getEntriesForRspRedirect(String ruleName, String sourcePort, String destinationPort, NeutronNetwork neutronNetwork, String rspName, Matches matches) {
    RenderedServicePath rsp = sfcProvider.getRenderedServicePath(rspName).orElse(null);
    if (rsp == null) {
        LOG.debug("Ace {} ignored: RSP {} not yet available", ruleName, rspName);
        return Collections.emptySet();
    }
    if (destinationPort != null) {
        LOG.warn("Ace {}: destination port is ignored combined with RSP redirect");
    }
    List<String> interfaces = new ArrayList<>();
    if (neutronNetwork != null) {
        interfaces.addAll(netvirtProvider.getLogicalInterfacesFromNeutronNetwork(neutronNetwork));
    }
    if (sourcePort != null) {
        interfaces.add(sourcePort);
    }
    if (interfaces.isEmpty()) {
        LOG.debug("Ace {} ignored: no interfaces to match against", ruleName);
        return Collections.emptySet();
    }
    return this.buildEntries(ruleName, interfaces, matches, rsp);
}
Also used : ArrayList(java.util.ArrayList) RenderedServicePath(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath)

Example 33 with Match

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match 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;
}
Also used : Optional(java.util.Optional) Matches(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches) AclMatches(org.opendaylight.netvirt.sfc.classifier.utils.AclMatches) ClassifierRenderableEntry(org.opendaylight.netvirt.sfc.classifier.service.domain.api.ClassifierRenderableEntry) RenderedServicePath(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath) HashSet(java.util.HashSet)

Example 34 with Match

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match in project bgpcep by opendaylight.

the class PCEPClassTypeObjectParser method parseObject.

@Override
public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
    Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
    if (!header.isProcessingRule()) {
        LOG.debug("Processed bit not set on CLASS TYPE OBJECT, ignoring it");
        return null;
    }
    if (bytes.readableBytes() != SIZE) {
        throw new PCEPDeserializerException("Size of byte array doesn't match defined size. Expected: " + SIZE + "; Passed: " + bytes.readableBytes());
    }
    final ClassTypeBuilder builder = new ClassTypeBuilder();
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());
    final short ct = (short) bytes.readUnsignedInt();
    builder.setClassType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType(ct));
    final Object obj = builder.build();
    if (ct < 0 || ct > Byte.SIZE) {
        LOG.debug("Invalid class type {}", ct);
        return new UnknownObject(PCEPErrors.INVALID_CT, obj);
    }
    return obj;
}
Also used : Preconditions(com.google.common.base.Preconditions) UnknownObject(org.opendaylight.protocol.pcep.spi.UnknownObject) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object) UnknownObject(org.opendaylight.protocol.pcep.spi.UnknownObject) ClassTypeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassTypeBuilder) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)

Example 35 with Match

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match in project bgpcep by opendaylight.

the class FlowspecL3vpnIpv6NlriParserTest method testParseMpUnreachNlri.

@Test
public void testParseMpUnreachNlri() throws BGPParsingException {
    final List<Flowspec> fs = new ArrayList<>();
    final MpUnreachNlriBuilder mp = new MpUnreachNlriBuilder();
    final FlowspecBuilder builder = new FlowspecBuilder();
    final FragmentCase fragment = createFragment();
    builder.setFlowspecType(fragment);
    fs.add(builder.build());
    final FlowspecType label = createLabel();
    builder.setFlowspecType(label);
    fs.add(builder.build());
    final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
    result.setAfi(Ipv6AddressFamily.class);
    result.setSafi(FlowspecL3vpnSubsequentAddressFamily.class);
    this.FS_PARSER.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI), result);
    final DestinationFlowspecL3vpnIpv6 flowspecDst = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv6Case) result.getWithdrawnRoutes().getDestinationType()).getDestinationFlowspecL3vpnIpv6();
    final List<Flowspec> flows = flowspecDst.getFlowspec();
    final RouteDistinguisher rd = flowspecDst.getRouteDistinguisher();
    assertEquals(2, flows.size());
    assertEquals(ROUTE_DISTINGUISHER, new String(rd.getValue()));
    assertEquals(fragment, flows.get(0).getFlowspecType());
    assertEquals(label, flows.get(1).getFlowspecType());
    mp.setAfi(Ipv6AddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv6CaseBuilder().setDestinationFlowspecL3vpnIpv6(new DestinationFlowspecL3vpnIpv6Builder().setRouteDistinguisher(rd).setFlowspec(fs).build()).build()).build());
    final ByteBuf buffer = Unpooled.buffer();
    this.FS_PARSER.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mp.build()).build()).build(), buffer);
    assertArrayEquals(UNREACHED_NLRI, ByteArray.readAllBytes(buffer));
    assertEquals("all packets where fragment does match 'IS FIRST' 'IS LAST' 'IS A' AND where flow label equals to 16777222 or equals to 258 ", this.FS_PARSER.stringNlri(flows));
}
Also used : Ipv6AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily) MockitoAnnotations(org.mockito.MockitoAnnotations) DestinationFlowspecL3vpnIpv6Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.l3vpn.destination.ipv6.DestinationFlowspecL3vpnIpv6Builder) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) WithdrawnRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder) MpUnreachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpUnreachNlriBuilder) FlowspecType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.FlowspecType) Flowspec(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.Flowspec) RouteDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisher) FlowspecBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.FlowspecBuilder) DestinationFlowspecL3vpnIpv6(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.l3vpn.destination.ipv6.DestinationFlowspecL3vpnIpv6) Attributes2Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes2Builder) FragmentCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.FragmentCase) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)182 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)138 ArrayList (java.util.ArrayList)82 BigInteger (java.math.BigInteger)66 EthernetMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder)62 Ipv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder)61 Ipv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder)60 ByteBuf (io.netty.buffer.ByteBuf)59 IpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder)53 Icmpv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder)49 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)48 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match)45 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)44 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)43 ArpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder)43 TcpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder)42 VlanMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder)41 Icmpv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder)40 UdpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder)40 Ipv4Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match)39