use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class K8sRoutingSnatHandler method setRouterSnatUpstreamRule.
private void setRouterSnatUpstreamRule(K8sNode k8sNode, K8sRouterBridge bridge, boolean install) {
if (k8sNode.routerPortNum() == null) {
return;
}
TrafficSelector ipSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchInPort(k8sNode.routerToExtPortNum()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(k8sNode.routerPortNum()).build();
k8sFlowRuleService.setRule(appId, bridge.deviceId(), ipSelector, treatment, PRIORITY_ROUTER_RULE, ROUTER_ENTRY_TABLE, install);
TrafficSelector arpSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_ARP).matchInPort(k8sNode.routerToExtPortNum()).build();
k8sFlowRuleService.setRule(appId, bridge.deviceId(), arpSelector, treatment, PRIORITY_ROUTER_RULE, ROUTER_ENTRY_TABLE, install);
}
use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class K8sRoutingSnatHandler method setRouterSnatDownstreamRule.
private void setRouterSnatDownstreamRule(K8sNode k8sNode, K8sRouterBridge bridge, boolean install) {
if (k8sNode.routerPortNum() == null) {
return;
}
TrafficSelector ipSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchInPort(k8sNode.routerPortNum()).matchIPDst(IpPrefix.valueOf(k8sNode.extBridgeIp(), 32)).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(k8sNode.routerToExtPortNum()).build();
k8sFlowRuleService.setRule(appId, bridge.deviceId(), ipSelector, treatment, PRIORITY_ROUTER_RULE, ROUTER_ENTRY_TABLE, install);
TrafficSelector arpSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_ARP).matchInPort(k8sNode.routerPortNum()).matchArpTpa(Ip4Address.valueOf(k8sNode.extBridgeIp().toString())).build();
k8sFlowRuleService.setRule(appId, bridge.deviceId(), arpSelector, treatment, PRIORITY_ROUTER_RULE, ROUTER_ENTRY_TABLE, install);
}
use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class K8sRoutingSnatHandler method setExtIntfArpRule.
private void setExtIntfArpRule(K8sNode k8sNode, boolean install) {
k8sNodeService.completeNodes().forEach(n -> {
Device device = deviceService.getDevice(n.extBridge());
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_ARP).matchArpOp(ARP.OP_REQUEST).matchArpTpa(Ip4Address.valueOf(k8sNode.extBridgeIp().toString())).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setArpOp(ARP.OP_REPLY).extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setEthSrc(k8sNode.extBridgeMac()).setArpSha(k8sNode.extBridgeMac()).setArpSpa(Ip4Address.valueOf(k8sNode.extBridgeIp().toString())).setOutput(PortNumber.IN_PORT).build();
k8sFlowRuleService.setRule(appId, n.extBridge(), selector, treatment, PRIORITY_STATEFUL_SNAT_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