Search in sources :

Example 16 with Protocol

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol in project bgpcep by opendaylight.

the class FlowspecL3vpnIpv4NlriParserTest method testParseMpReachNlriConstraint.

@Test
public void testParseMpReachNlriConstraint() throws BGPParsingException {
    final List<Flowspec> fs = new ArrayList<>();
    final MpReachNlriBuilder mp = new MpReachNlriBuilder();
    final FlowspecBuilder builder = new FlowspecBuilder();
    final DestinationPrefixCase destinationPrefix = new DestinationPrefixCaseBuilder().setDestinationPrefix(new Ipv4Prefix("10.0.1.0/32")).build();
    builder.setFlowspecType(destinationPrefix);
    fs.add(builder.build());
    final SourcePrefixCase sourcePrefix = new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix("1.2.3.4/32")).build();
    builder.setFlowspecType(sourcePrefix);
    fs.add(builder.build());
    final FlowspecType prots = createProts();
    builder.setFlowspecType(prots);
    fs.add(builder.build());
    final PortCase ps = createPorts();
    builder.setFlowspecType(ps);
    fs.add(builder.build());
    final FlowspecType dps = createDps();
    builder.setFlowspecType(dps);
    fs.add(builder.build());
    final FlowspecType sps = createSps();
    builder.setFlowspecType(sps);
    fs.add(builder.build());
    final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
    final MpReachNlriBuilder result = new MpReachNlriBuilder();
    result.setAfi(Ipv4AddressFamily.class);
    result.setSafi(FlowspecL3vpnSubsequentAddressFamily.class);
    parser.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI_ADD_PATH), result, this.constraint);
    final DestinationFlowspecL3vpnIpv4 flowspecDst = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv4Case) result.getAdvertizedRoutes().getDestinationType()).getDestinationFlowspecL3vpnIpv4();
    final List<Flowspec> flows = flowspecDst.getFlowspec();
    final RouteDistinguisher rd = flowspecDst.getRouteDistinguisher();
    testFlows(flows, destinationPrefix, sourcePrefix, prots, rd, ps, dps, sps);
    mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv4CaseBuilder().setDestinationFlowspecL3vpnIpv4(new DestinationFlowspecL3vpnIpv4Builder().setRouteDistinguisher(rd).setPathId(PATH_ID).setFlowspec(fs).build()).build()).build());
    final ByteBuf buffer = Unpooled.buffer();
    parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mp.setAfi(Ipv4AddressFamily.class).build()).build()).build(), buffer);
    assertArrayEquals(REACHED_NLRI_ADD_PATH, ByteArray.readAllBytes(buffer));
    assertEquals("all packets to 10.0.1.0/32 AND from 1.2.3.4/32 AND where IP protocol equals to 6 AND where port is greater than or equals to 137 and is less than or equals to 139 or equals to 8080 AND where destination port is greater than 4089 or equals to 179 AND where source port equals to 8080 ", this.FS_PARSER.stringNlri(flows));
}
Also used : MpReachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder) SourcePrefixCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.group.ipv4.flowspec.flowspec.type.SourcePrefixCase) MockitoAnnotations(org.mockito.MockitoAnnotations) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) PortCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.PortCase) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) SourcePrefixCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.group.ipv4.flowspec.flowspec.type.SourcePrefixCaseBuilder) 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) RouteDistinguisherUtil.extractRouteDistinguisher(org.opendaylight.bgp.concepts.RouteDistinguisherUtil.extractRouteDistinguisher) RouteDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisher) DestinationPrefixCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCaseBuilder) FlowspecL3vpnIpv4NlriParser(org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv4.FlowspecL3vpnIpv4NlriParser) FlowspecBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.FlowspecBuilder) AdvertizedRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder) Attributes1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1Builder) DestinationFlowspecL3vpnIpv4(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.l3vpn.destination.ipv4.DestinationFlowspecL3vpnIpv4) DestinationFlowspecL3vpnIpv4Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.l3vpn.destination.ipv4.DestinationFlowspecL3vpnIpv4Builder) DestinationPrefixCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCase) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) Test(org.junit.Test)

Example 17 with Protocol

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol in project bgpcep by opendaylight.

the class AbstractBestPathSelector method isExistingPathBetter.

/**
 * Chooses best route according to BGP best path selection.
 *
 * @param state attributes of the new route
 * @return true if the existing path is better, false if the new path is better
 */
protected boolean isExistingPathBetter(@Nonnull final BestPathState state) {
    /*
         * 2. prefer path with higher LOCAL_PREF
         *
         * FIXME: for eBGP cases (when the LOCAL_PREF is missing), we should assign a policy-based preference
         *        before we ever get here.
         */
    if (this.bestState.getLocalPref() == null && state.getLocalPref() != null) {
        return true;
    }
    if (this.bestState.getLocalPref() != null && state.getLocalPref() == null) {
        return false;
    }
    if (state.getLocalPref() != null && state.getLocalPref() > this.bestState.getLocalPref()) {
        return false;
    }
    if (state.getLocalPref() != null && state.getLocalPref() < this.bestState.getLocalPref()) {
        return true;
    }
    // 4. prefer the path with the shortest AS_PATH.
    if (this.bestState.getAsPathLength() != state.getAsPathLength()) {
        return this.bestState.getAsPathLength() < state.getAsPathLength();
    }
    // - IGP is lower than Exterior Gateway Protocol (EGP), and EGP is lower than INCOMPLETE
    if (!this.bestState.getOrigin().equals(state.getOrigin())) {
        final BgpOrigin bo = this.bestState.getOrigin();
        final BgpOrigin no = state.getOrigin();
        // This trick relies on the order in which the values are declared in the model.
        return no.ordinal() > bo.ordinal();
    }
    // FIXME: we should be able to cache the best AS
    final Long bestAs = this.bestState.getPeerAs();
    final Long newAs = state.getPeerAs();
    /*
         * Checks 6 and 7 are mutually-exclusive, as MEDs are comparable
         * only when the routes originated from the same AS. On the other
         * hand, when they are from the same AS, they are in the same iBGP/eBGP
         * relationship.
         *
         */
    if (bestAs.equals(newAs)) {
        // 6. prefer the path with the lowest multi-exit discriminator (MED)
        if (this.bestState.getMultiExitDisc() != null || state.getMultiExitDisc() != null) {
            final Long bmed = this.bestState.getMultiExitDisc();
            final Long nmed = state.getMultiExitDisc();
            return nmed > bmed;
        }
    } else {
        /*
             * 7. prefer eBGP over iBGP paths
             *
             * EBGP is peering between two different AS, whereas IBGP is between same AS (Autonomous System),
             * so we just compare the AS numbers to our AS.
             *
             * FIXME: we should know this information from the peer directly.
             */
        if (this.ourAs != bestAs && this.ourAs == newAs) {
            return true;
        }
    }
    /*
         * 10. Prefer the route that comes from the BGP router with the lowest router ID.
         *
         * This is normally guaranteed by the iteration order of our caller, which runs selection
         * in the order of increasing router ID, but RFC-4456 Route Reflection throws a wrench into that.
         *
         * With RFC-5004, this gets a bit easier, because it completely eliminates step f) and later :-)
         *
         * RFC-5004 states that this algorithm should end here and select existing path over new path in the
         * best path selection process. Benefits are listed in the RFC: @see http://tools.ietf.org/html/rfc500
         * - This algorithm SHOULD NOT be applied when either path is from a BGP Confederation peer.
         *  - not applicable, we don't deal with confederation peers
         * - The algorithm SHOULD NOT be applied when both paths are from peers with an identical BGP identifier
         *   (i.e., there exist parallel BGP sessions between two BGP speakers).
         *  - not applicable, BUG-2631 prevents parallel sessions to be created.
         */
    return true;
}
Also used : BgpOrigin(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin)

Example 18 with Protocol

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol in project openflowplugin by opendaylight.

the class FlowStatsResponseConvertor method wrapOF10ActionsToInstruction.

/**
 * Method wraps openflow 1.0 actions list to Apply Action Instructions.
 *
 * @param actionsList list of action
 * @param ipProtocol ip protocol
 * @return OF10 actions as an instructions
 */
private Instructions wrapOF10ActionsToInstruction(List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action> actionsList, final short version, final Short ipProtocol) {
    ActionResponseConvertorData actionResponseConvertorData = new ActionResponseConvertorData(version);
    actionResponseConvertorData.setActionPath(ActionPath.FLOWS_STATISTICS_UPDATE_WRITE_ACTIONS);
    actionResponseConvertorData.setIpProtocol(ipProtocol);
    ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder();
    ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder();
    final Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>> actions = getConvertorExecutor().convert(actionsList, actionResponseConvertorData);
    applyActionsBuilder.setAction(FlowConvertorUtil.wrapActionList(actions.orElse(Collections.emptyList())));
    applyActionsCaseBuilder.setApplyActions(applyActionsBuilder.build());
    InstructionBuilder instBuilder = new InstructionBuilder();
    instBuilder.setInstruction(applyActionsCaseBuilder.build());
    instBuilder.setKey(new InstructionKey(0));
    instBuilder.setOrder(0);
    List<Instruction> salInstructionList = new ArrayList<>();
    salInstructionList.add(instBuilder.build());
    InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
    instructionsBuilder.setInstruction(salInstructionList);
    return instructionsBuilder.build();
}
Also used : InstructionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder) ArrayList(java.util.ArrayList) InstructionKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) InstructionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder) ApplyActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder) ActionResponseConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData) ArrayList(java.util.ArrayList) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) List(java.util.List) ApplyActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder)

Example 19 with Protocol

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol in project bgpcep by opendaylight.

the class SrPrefixAttributesParser method parseSrPrefix.

public static SrPrefix parseSrPrefix(final ByteBuf buffer, final ProtocolId protocol) {
    final SrPrefixBuilder builder = new SrPrefixBuilder();
    builder.setFlags(parsePrefixFlags(BitArray.valueOf(buffer, FLAGS_SIZE), protocol));
    builder.setAlgorithm(Algorithm.forValue(buffer.readUnsignedByte()));
    buffer.skipBytes(RESERVED_PREFIX);
    builder.setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer));
    return builder.build();
}
Also used : SrPrefixBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrPrefixBuilder)

Example 20 with Protocol

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol in project openflowplugin by opendaylight.

the class OF10DeviceInitializer method initializeNodeInformation.

@Override
protected Future<Void> initializeNodeInformation(@Nonnull final DeviceContext deviceContext, final boolean switchFeaturesMandatory, final boolean skipTableFeatures, @Nullable final MultipartWriterProvider multipartWriterProvider, @Nullable final ConvertorExecutor convertorExecutor) {
    final ConnectionContext connectionContext = Preconditions.checkNotNull(deviceContext.getPrimaryConnectionContext());
    final DeviceState deviceState = Preconditions.checkNotNull(deviceContext.getDeviceState());
    final DeviceInfo deviceInfo = Preconditions.checkNotNull(deviceContext.getDeviceInfo());
    final CapabilitiesV10 capabilitiesV10 = connectionContext.getFeatures().getCapabilitiesV10();
    // Set capabilities for this device based on capabilities of connection context
    LOG.debug("Setting capabilities for device {}", deviceInfo);
    DeviceStateUtil.setDeviceStateBasedOnV10Capabilities(deviceState, capabilitiesV10);
    final ListenableFuture<Boolean> future = requestMultipart(MultipartType.OFPMPDESC, deviceContext);
    Futures.addCallback(future, new FutureCallback<Boolean>() {

        @Override
        public void onSuccess(@Nullable final Boolean result) {
            if (Boolean.TRUE.equals(result)) {
                LOG.debug("Creating empty flow capable node: {}", deviceInfo);
                makeEmptyFlowCapableNode(deviceContext, deviceInfo);
                LOG.debug("Creating empty tables for {}", deviceInfo);
                DeviceInitializationUtil.makeEmptyTables(deviceContext, deviceInfo, deviceContext.getPrimaryConnectionContext().getFeatures().getTables());
            }
        }

        @Override
        public void onFailure(@Nonnull final Throwable throwable) {
            LOG.warn("Error occurred in preparation node {} for protocol 1.0", deviceInfo);
            LOG.trace("Error for node {} : ", deviceInfo, throwable);
        }
    }, MoreExecutors.directExecutor());
    return Futures.transform(future, new Function<Boolean, Void>() {

        @Nullable
        @Override
        public Void apply(@Nullable final Boolean input) {
            LOG.debug("Writing physical port information for {}", deviceInfo);
            writePhyPortInformation(deviceContext);
            return null;
        }
    }, MoreExecutors.directExecutor());
}
Also used : DeviceState(org.opendaylight.openflowplugin.api.openflow.device.DeviceState) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) ConnectionContext(org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext) CapabilitiesV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10) Nullable(javax.annotation.Nullable)

Aggregations

Test (org.junit.Test)16 ArrayList (java.util.ArrayList)15 BigInteger (java.math.BigInteger)9 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)8 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)8 ExecutionException (java.util.concurrent.ExecutionException)7 Ipv4Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match)6 TcpMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch)6 UdpMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch)6 ProtocolTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProtocolTypes)6 VersionDatapathIdConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)5 AceIpBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder)5 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)5 ByteBuf (io.netty.buffer.ByteBuf)4 List (java.util.List)4 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match)4 EthernetMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch)4 Icmpv4Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match)4 IpMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch)4 IntextIpPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpPortMap)4