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));
});
}
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);
}
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);
}
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);
}
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);
}
}
}
Aggregations