Search in sources :

Example 1 with Key

use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.

the class StopMonitorCommand method doExecute.

@Override
protected void doExecute() {
    imrService = get(IntentMonitorAndRerouteService.class);
    intentService = get(IntentService.class);
    if (appId != null && appName != null) {
        if (key != null) {
            /*
                Intent key might be a StringKey or a LongKey, but in any case is
                provided via CLI as a string. To solve only ambiguity we check if
                "--longkey" CLI parameter has been set.
                 */
            if (treatAsLongKey) {
                try {
                    Key intentKeyLong = Key.of(Integer.decode(key), new DefaultApplicationId(appId, appName));
                    if (imrService.stopMonitorIntent(intentKeyLong)) {
                        print("Stopped monitoring of intent with LongKey %s", intentKeyLong);
                        return;
                    }
                } catch (NumberFormatException nfe) {
                    print("\"%s\" is not a valid LongKey", key);
                    return;
                }
            } else {
                Key intentKeyString = Key.of(key, new DefaultApplicationId(appId, appName));
                if (imrService.stopMonitorIntent(intentKeyString)) {
                    print("Stopped monitoring of intent with StringKey %s", intentKeyString);
                    return;
                }
            }
            // No intent found in IMR
            print("No monitored intent with key %s found", key);
        } else {
            intentService.getIntents().forEach(i -> {
                if (i.appId().equals(new DefaultApplicationId(appId, appName))) {
                    imrService.stopMonitorIntent(i.key());
                    print("Stopped monitoring of intent with key %s", i.key());
                }
            });
        }
    }
}
Also used : IntentService(org.onosproject.net.intent.IntentService) IntentMonitorAndRerouteService(org.onosproject.imr.IntentMonitorAndRerouteService) Key(org.onosproject.net.intent.Key) DefaultApplicationId(org.onosproject.core.DefaultApplicationId)

Example 2 with Key

use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.

the class PeerConnectivityManagerTest method icmpPathintentConstructor.

/**
 * Constructs a BGP intent and put it into the intentList.
 * <p/>
 * The purpose of this method is too simplify the setUpBgpIntents() method,
 * and to make the setUpBgpIntents() easy to read.
 *
 * @param srcVlanId ingress VlanId
 * @param dstVlanId egress VlanId
 * @param srcPrefix source IP prefix to match
 * @param dstPrefix destination IP prefix to match
 * @param srcConnectPoint source connect point for PointToPointIntent
 * @param dstConnectPoint destination connect point for PointToPointIntent
 */
private void icmpPathintentConstructor(VlanId srcVlanId, VlanId dstVlanId, String srcPrefix, String dstPrefix, ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) {
    TrafficSelector.Builder builder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPProtocol(IPv4.PROTOCOL_ICMP).matchIPSrc(IpPrefix.valueOf(srcPrefix)).matchIPDst(IpPrefix.valueOf(dstPrefix));
    if (!srcVlanId.equals(VlanId.NONE)) {
        builder.matchVlanId(srcVlanId);
    }
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    if (!dstVlanId.equals(VlanId.NONE)) {
        treatment.setVlanId(dstVlanId);
    }
    Key key = Key.of(srcPrefix.split("/")[0] + "-" + dstPrefix.split("/")[0] + "-" + "icmp", APPID);
    PointToPointIntent intent = PointToPointIntent.builder().appId(APPID).key(key).selector(builder.build()).treatment(treatment.build()).filteredIngressPoint(new FilteredConnectPoint(srcConnectPoint)).filteredEgressPoint(new FilteredConnectPoint(dstConnectPoint)).build();
    intentList.add(intent);
}
Also used : PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 3 with Key

use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.

the class PeerConnectivityManagerTest method bgpPathintentConstructor.

/**
 * Constructs a BGP intent and put it into the intentList.
 * <p/>
 * The purpose of this method is too simplify the setUpBgpIntents() method,
 * and to make the setUpBgpIntents() easy to read.
 *
 * @param srcVlanId ingress VlanId
 * @param dstVlanId egress VlanId
 * @param srcPrefix source IP prefix to match
 * @param dstPrefix destination IP prefix to match
 * @param srcTcpPort source TCP port to match
 * @param dstTcpPort destination TCP port to match
 * @param srcConnectPoint source connect point for PointToPointIntent
 * @param dstConnectPoint destination connect point for PointToPointIntent
 */
private void bgpPathintentConstructor(VlanId srcVlanId, VlanId dstVlanId, String srcPrefix, String dstPrefix, Short srcTcpPort, Short dstTcpPort, ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) {
    TrafficSelector.Builder builder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPProtocol(IPv4.PROTOCOL_TCP).matchIPSrc(IpPrefix.valueOf(srcPrefix)).matchIPDst(IpPrefix.valueOf(dstPrefix));
    if (!srcVlanId.equals(VlanId.NONE)) {
        builder.matchVlanId(srcVlanId);
    }
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    if (!dstVlanId.equals(VlanId.NONE)) {
        treatment.setVlanId(dstVlanId);
    }
    if (srcTcpPort != null) {
        builder.matchTcpSrc(TpPort.tpPort(srcTcpPort));
    }
    if (dstTcpPort != null) {
        builder.matchTcpDst(TpPort.tpPort(dstTcpPort));
    }
    Key key = Key.of(srcPrefix.split("/")[0] + "-" + dstPrefix.split("/")[0] + "-" + ((srcTcpPort == null) ? "dst" : "src"), APPID);
    PointToPointIntent intent = PointToPointIntent.builder().appId(APPID).key(key).selector(builder.build()).treatment(treatment.build()).filteredIngressPoint(new FilteredConnectPoint(srcConnectPoint)).filteredEgressPoint(new FilteredConnectPoint(dstConnectPoint)).build();
    intentList.add(intent);
}
Also used : PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 4 with Key

use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.

the class PeerConnectivityManager method setUpConnectivity.

/**
 * Sets up paths to establish connectivity between all internal
 * BGP speakers and external BGP peers.
 */
private void setUpConnectivity() {
    BgpConfig bgpConfig = configService.getConfig(routerAppId, RoutingService.CONFIG_CLASS);
    SdnIpConfig sdnIpConfig = configService.getConfig(appId, SdnIpConfig.class);
    Set<BgpConfig.BgpSpeakerConfig> bgpSpeakers;
    EncapsulationType encap;
    if (bgpConfig == null) {
        log.debug("No BGP config available");
        bgpSpeakers = Collections.emptySet();
    } else {
        bgpSpeakers = bgpConfig.bgpSpeakers();
    }
    if (sdnIpConfig == null) {
        log.debug("No SDN-IP config available");
        encap = EncapsulationType.NONE;
    } else {
        encap = sdnIpConfig.encap();
    }
    Map<Key, PointToPointIntent> existingIntents = new HashMap<>(peerIntents);
    for (BgpConfig.BgpSpeakerConfig bgpSpeaker : bgpSpeakers) {
        log.debug("Start to set up BGP paths for BGP speaker: {}", bgpSpeaker);
        buildSpeakerIntents(bgpSpeaker, encap).forEach(i -> {
            PointToPointIntent intent = existingIntents.remove(i.key());
            if (intent == null || !IntentUtils.intentsAreEqual(i, intent)) {
                peerIntents.put(i.key(), i);
                intentSynchronizer.submit(i);
            }
        });
    }
    // Remove any remaining intents that we used to have that we don't need
    // anymore
    existingIntents.values().forEach(i -> {
        peerIntents.remove(i.key());
        intentSynchronizer.withdraw(i);
    });
}
Also used : BgpConfig(org.onosproject.routing.config.BgpConfig) EncapsulationType(org.onosproject.net.EncapsulationType) HashMap(java.util.HashMap) SdnIpConfig(org.onosproject.sdnip.config.SdnIpConfig) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) Key(org.onosproject.net.intent.Key)

Example 5 with Key

use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.

the class PeerConnectivityManager method buildIntents.

/**
 * Builds the required intents between a BGP speaker and an external router.
 *
 * @param portOne the BGP speaker connect point
 * @param vlanOne the BGP speaker VLAN
 * @param ipOne the BGP speaker IP address
 * @param portTwo the external BGP peer connect point
 * @param vlanTwo the external BGP peer VLAN
 * @param ipTwo the external BGP peer IP address
 * @param encap the encapsulation type
 * @return the intents to install
 */
private Collection<PointToPointIntent> buildIntents(ConnectPoint portOne, VlanId vlanOne, IpAddress ipOne, ConnectPoint portTwo, VlanId vlanTwo, IpAddress ipTwo, EncapsulationType encap) {
    List<PointToPointIntent> intents = new ArrayList<>();
    TrafficTreatment.Builder treatmentToPeer = DefaultTrafficTreatment.builder();
    TrafficTreatment.Builder treatmentToSpeaker = DefaultTrafficTreatment.builder();
    PointToPointIntent.Builder intentBuilder;
    TrafficSelector selector;
    Key key;
    byte tcpProtocol;
    byte icmpProtocol;
    if (ipOne.isIp4()) {
        tcpProtocol = IPv4.PROTOCOL_TCP;
        icmpProtocol = IPv4.PROTOCOL_ICMP;
    } else {
        tcpProtocol = IPv6.PROTOCOL_TCP;
        icmpProtocol = IPv6.PROTOCOL_ICMP6;
    }
    // Add VLAN treatment for traffic going from BGP speaker to BGP peer
    treatmentToPeer = applyVlanTreatment(vlanOne, vlanTwo, treatmentToPeer);
    // Path from BGP speaker to BGP peer matching destination TCP port 179
    selector = buildSelector(tcpProtocol, vlanOne, ipOne, ipTwo, null, BGP_PORT);
    key = buildKey(ipOne, ipTwo, SUFFIX_DST);
    intentBuilder = PointToPointIntent.builder().appId(appId).key(key).filteredIngressPoint(new FilteredConnectPoint(portOne)).filteredEgressPoint(new FilteredConnectPoint(portTwo)).selector(selector).treatment(treatmentToPeer.build()).priority(PRIORITY_OFFSET);
    encap(intentBuilder, encap);
    intents.add(intentBuilder.build());
    // Path from BGP speaker to BGP peer matching source TCP port 179
    selector = buildSelector(tcpProtocol, vlanOne, ipOne, ipTwo, BGP_PORT, null);
    key = buildKey(ipOne, ipTwo, SUFFIX_SRC);
    intentBuilder = PointToPointIntent.builder().appId(appId).key(key).filteredIngressPoint(new FilteredConnectPoint(portOne)).filteredEgressPoint(new FilteredConnectPoint(portTwo)).selector(selector).treatment(treatmentToPeer.build()).priority(PRIORITY_OFFSET);
    encap(intentBuilder, encap);
    intents.add(intentBuilder.build());
    // ICMP path from BGP speaker to BGP peer
    selector = buildSelector(icmpProtocol, vlanOne, ipOne, ipTwo, null, null);
    key = buildKey(ipOne, ipTwo, SUFFIX_ICMP);
    intentBuilder = PointToPointIntent.builder().appId(appId).key(key).filteredIngressPoint(new FilteredConnectPoint(portOne)).filteredEgressPoint(new FilteredConnectPoint(portTwo)).selector(selector).treatment(treatmentToPeer.build()).priority(PRIORITY_OFFSET);
    encap(intentBuilder, encap);
    intents.add(intentBuilder.build());
    // Add VLAN treatment for traffic going from BGP peer to BGP speaker
    treatmentToSpeaker = applyVlanTreatment(vlanTwo, vlanOne, treatmentToSpeaker);
    // Path from BGP peer to BGP speaker matching destination TCP port 179
    selector = buildSelector(tcpProtocol, vlanTwo, ipTwo, ipOne, null, BGP_PORT);
    key = buildKey(ipTwo, ipOne, SUFFIX_DST);
    intentBuilder = PointToPointIntent.builder().appId(appId).key(key).filteredIngressPoint(new FilteredConnectPoint(portTwo)).filteredEgressPoint(new FilteredConnectPoint(portOne)).selector(selector).treatment(treatmentToSpeaker.build()).priority(PRIORITY_OFFSET);
    encap(intentBuilder, encap);
    intents.add(intentBuilder.build());
    // Path from BGP peer to BGP speaker matching source TCP port 179
    selector = buildSelector(tcpProtocol, vlanTwo, ipTwo, ipOne, BGP_PORT, null);
    key = buildKey(ipTwo, ipOne, SUFFIX_SRC);
    intentBuilder = PointToPointIntent.builder().appId(appId).key(key).filteredIngressPoint(new FilteredConnectPoint(portTwo)).filteredEgressPoint(new FilteredConnectPoint(portOne)).selector(selector).treatment(treatmentToSpeaker.build()).priority(PRIORITY_OFFSET);
    encap(intentBuilder, encap);
    intents.add(intentBuilder.build());
    // ICMP path from BGP peer to BGP speaker
    selector = buildSelector(icmpProtocol, vlanTwo, ipTwo, ipOne, null, null);
    key = buildKey(ipTwo, ipOne, SUFFIX_ICMP);
    intentBuilder = PointToPointIntent.builder().appId(appId).key(key).filteredIngressPoint(new FilteredConnectPoint(portTwo)).filteredEgressPoint(new FilteredConnectPoint(portOne)).selector(selector).treatment(treatmentToSpeaker.build()).priority(PRIORITY_OFFSET);
    encap(intentBuilder, encap);
    intents.add(intentBuilder.build());
    return intents;
}
Also used : PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Aggregations

Key (org.onosproject.net.intent.Key)63 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)25 Intent (org.onosproject.net.intent.Intent)22 ConnectPoint (org.onosproject.net.ConnectPoint)20 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 TrafficSelector (org.onosproject.net.flow.TrafficSelector)19 MultiPointToSinglePointIntent (org.onosproject.net.intent.MultiPointToSinglePointIntent)19 Test (org.junit.Test)15 Constraint (org.onosproject.net.intent.Constraint)15 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)14 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)12 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)12 IntentService (org.onosproject.net.intent.IntentService)11 SinglePointToMultiPointIntent (org.onosproject.net.intent.SinglePointToMultiPointIntent)11 ApplicationId (org.onosproject.core.ApplicationId)10 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 Interface (org.onosproject.net.intf.Interface)9 Set (java.util.Set)8 MacAddress (org.onlab.packet.MacAddress)8