Search in sources :

Example 1 with TrafficSelector

use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.

the class TestCodecService method testPushIntAppConfig.

@Test
public void testPushIntAppConfig() throws IOException {
    IntReportConfig config = getIntReportConfig("/report-config.json");
    NetworkConfigEvent event = new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_ADDED, APP_ID, config, null, IntReportConfig.class);
    networkConfigListener.event(event);
    // We expected that the manager will store the device config which
    // converted from the app config.
    IntDeviceConfig expectedConfig = createIntDeviceConfig();
    IntDeviceConfig actualConfig = manager.getConfig();
    assertEquals(expectedConfig, actualConfig);
    // Install watch subnets via netcfg
    // In the report-config.json, there are 3 subnets we want to watch
    // For subnet 0.0.0.0/0, the IntManager will create only one IntIntent with an empty selector.
    Set<IntIntent> expectedIntIntents = Sets.newHashSet();
    ConsistentMap<IntIntentId, IntIntent> intentMap = TestUtils.getField(manager, "intentMap");
    IntIntent.Builder baseIntentBuilder = IntIntent.builder().withReportType(IntIntent.IntReportType.TRACKED_FLOW).withReportType(IntIntent.IntReportType.DROPPED_PACKET).withReportType(IntIntent.IntReportType.CONGESTED_QUEUE).withTelemetryMode(IntIntent.TelemetryMode.POSTCARD);
    // Watch IP Src == subnet 1
    TrafficSelector expectedSelector = DefaultTrafficSelector.builder().matchIPSrc(IpPrefix.valueOf(WATCHED_SUBNET_1)).build();
    expectedIntIntents.add(baseIntentBuilder.withSelector(expectedSelector).build());
    // Watch IP Dst == subnet 1
    expectedSelector = DefaultTrafficSelector.builder().matchIPDst(IpPrefix.valueOf(WATCHED_SUBNET_1)).build();
    expectedIntIntents.add(baseIntentBuilder.withSelector(expectedSelector).build());
    // Watch IP Src == subnet 2
    expectedSelector = DefaultTrafficSelector.builder().matchIPSrc(IpPrefix.valueOf(WATCHED_SUBNET_2)).build();
    expectedIntIntents.add(baseIntentBuilder.withSelector(expectedSelector).build());
    // Watch IP Dst == subnet 2
    expectedSelector = DefaultTrafficSelector.builder().matchIPDst(IpPrefix.valueOf(WATCHED_SUBNET_2)).build();
    expectedIntIntents.add(baseIntentBuilder.withSelector(expectedSelector).build());
    // Any packets
    expectedSelector = DefaultTrafficSelector.emptySelector();
    expectedIntIntents.add(baseIntentBuilder.withSelector(expectedSelector).build());
    // The INT intent installation order can be random, so we need to collect
    // all expected INT intents and check if actual intent exists.
    assertAfter(50, 100, () -> assertEquals(5, intentMap.size()));
    intentMap.entrySet().forEach(entry -> {
        IntIntent actualIntIntent = entry.getValue().value();
        assertTrue(expectedIntIntents.contains(actualIntIntent));
    });
}
Also used : NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) IntDeviceConfig(org.onosproject.net.behaviour.inbandtelemetry.IntDeviceConfig) IntIntent(org.onosproject.inbandtelemetry.api.IntIntent) IntIntentId(org.onosproject.inbandtelemetry.api.IntIntentId) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IntReportConfig(org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig) Test(org.junit.Test)

Example 2 with TrafficSelector

use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.

the class K8sRoutingArpHandler method setArpReplyRule.

private void setArpReplyRule(K8sNode k8sNode, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_ARP).matchArpOp(ARP.OP_REPLY).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build();
    k8sFlowRuleService.setRule(appId, k8sNode.extBridge(), selector, treatment, PRIORITY_ARP_REPLY_RULE, EXT_ENTRY_TABLE, install);
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 3 with TrafficSelector

use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.

the class K8sRoutingArpHandler method setPodArpReplyRule.

private void setPodArpReplyRule(K8sNode k8sNode, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(k8sNode.extBridgePortNum()).matchEthType(Ethernet.TYPE_ARP).matchArpOp(ARP.OP_REPLY).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(k8sNode.extToIntgPatchPortNum()).build();
    k8sFlowRuleService.setRule(appId, k8sNode.extBridge(), selector, treatment, PRIORITY_ARP_POD_RULE, EXT_ENTRY_TABLE, install);
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 4 with TrafficSelector

use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.

the class K8sServiceHandler method setSrcDstCidrRules.

private void setSrcDstCidrRules(DeviceId deviceId, String srcCidr, String dstCidr, String cidrClass, String segId, String shiftPrefix, String shiftType, int installTable, int transitTable, int priority, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(srcCidr)).matchIPDst(IpPrefix.valueOf(dstCidr)).build();
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    if (segId != null) {
        tBuilder.setTunnelId(Long.valueOf(segId));
    }
    if (shiftPrefix != null && shiftType != null) {
        ExtensionTreatment loadTreatment = buildLoadExtension(deviceService.getDevice(deviceId), cidrClass, shiftType, shiftPrefix);
        tBuilder.extension(loadTreatment, deviceId);
    }
    tBuilder.transition(transitTable);
    k8sFlowRuleService.setRule(appId, deviceId, selector, tBuilder.build(), priority, installTable, install);
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

Example 5 with TrafficSelector

use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.

the class K8sSwitchingGatewayHandler method setInterNodeRoutingRules.

private void setInterNodeRoutingRules(K8sNode srcNode, boolean install) {
    if (srcNode == null) {
        return;
    }
    for (K8sNode dstNode : k8sNodeService.nodes()) {
        if (StringUtils.equals(srcNode.hostname(), dstNode.hostname())) {
            continue;
        }
        boolean sameHost = false;
        for (K8sHost host : k8sHostService.completeHosts()) {
            Set<String> nodeNames = host.nodeNames();
            // we simply do not tunnel the traffic, instead we route the traffic
            if (nodeNames.contains(srcNode.hostname()) && nodeNames.contains(dstNode.hostname())) {
                sameHost = true;
            }
        }
        if (sameHost) {
            TrafficSelector originalSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(srcNode.podCidr())).matchIPDst(IpPrefix.valueOf(dstNode.podCidr())).build();
            TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(dstNode.tunToIntgPortNum()).build();
            k8sFlowRuleService.setRule(appId, dstNode.tunBridge(), originalSelector, treatment, PRIORITY_INTER_NODE_RULE, TUN_ENTRY_TABLE, install);
            TrafficSelector transformedSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(shiftIpDomain(srcNode.podCidr(), SHIFTED_IP_PREFIX))).matchIPDst(IpPrefix.valueOf(dstNode.podCidr())).build();
            k8sFlowRuleService.setRule(appId, dstNode.tunBridge(), transformedSelector, treatment, PRIORITY_INTER_NODE_RULE, TUN_ENTRY_TABLE, install);
            String nodeIpPrefix = NODE_IP_PREFIX + ".0.0.0/8";
            TrafficSelector nodePortSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(nodeIpPrefix)).matchIPDst(IpPrefix.valueOf(dstNode.podCidr())).build();
            k8sFlowRuleService.setRule(appId, dstNode.tunBridge(), nodePortSelector, treatment, PRIORITY_INTER_NODE_RULE, TUN_ENTRY_TABLE, install);
        }
    }
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) K8sHost(org.onosproject.k8snode.api.K8sHost) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

TrafficSelector (org.onosproject.net.flow.TrafficSelector)294 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)267 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)204 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)190 FlowRule (org.onosproject.net.flow.FlowRule)80 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)70 Test (org.junit.Test)54 ConnectPoint (org.onosproject.net.ConnectPoint)41 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)39 PortNumber (org.onosproject.net.PortNumber)36 DeviceId (org.onosproject.net.DeviceId)35 Instruction (org.onosproject.net.flow.instructions.Instruction)34 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)34 Intent (org.onosproject.net.intent.Intent)34 List (java.util.List)31 Criterion (org.onosproject.net.flow.criteria.Criterion)31 PiAction (org.onosproject.net.pi.runtime.PiAction)29 Set (java.util.Set)27 EthTypeCriterion (org.onosproject.net.flow.criteria.EthTypeCriterion)26 NextObjective (org.onosproject.net.flowobjective.NextObjective)26