use of org.onosproject.net.flow.instructions.ExtensionTreatment in project onos by opennetworkinglab.
the class K8sServiceHandler method buildBuckets.
private GroupBucket buildBuckets(DeviceId deviceId, String podIpStr, ServicePort sp) {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setIpDst(IpAddress.valueOf(podIpStr));
int targetPort;
if (sp.getTargetPort().getIntVal() == null) {
Pod pod = podByIp(k8sPodService, podIpStr);
targetPort = portNumberByName(pod, sp.getTargetPort().getStrVal());
} else {
targetPort = sp.getTargetPort().getIntVal();
}
if (targetPort == 0) {
return null;
}
if (TCP.equals(sp.getProtocol())) {
tBuilder.setTcpDst(TpPort.tpPort(targetPort));
} else if (UDP.equals(sp.getProtocol())) {
tBuilder.setUdpDst(TpPort.tpPort(targetPort));
}
ExtensionTreatment resubmitTreatment = buildResubmitExtension(deviceService.getDevice(deviceId), ACL_TABLE);
tBuilder.extension(resubmitTreatment, deviceId);
// TODO: need to adjust group bucket weight by considering POD locality
return buildGroupBucket(tBuilder.build(), SELECT, (short) -1);
}
use of org.onosproject.net.flow.instructions.ExtensionTreatment in project onos by opennetworkinglab.
the class K8sSwitchingGatewayHandler method setLocalBridgeRule.
private void setLocalBridgeRule(K8sNetwork k8sNetwork, K8sNode k8sNode, String type, boolean install) {
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4);
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
ExtensionTreatment loadTreatment = null;
if (REQUEST.equals(type)) {
loadTreatment = buildLoadExtension(deviceService.getDevice(k8sNode.localBridge()), B_CLASS, SRC, SHIFTED_LOCAL_IP_PREFIX);
}
if (REPLY.equals(type)) {
loadTreatment = buildLoadExtension(deviceService.getDevice(k8sNode.localBridge()), B_CLASS, DST, SHIFTED_IP_PREFIX);
}
tBuilder.extension(loadTreatment, k8sNode.localBridge());
if (REQUEST.equals(type)) {
sBuilder.matchIPDst(IpPrefix.valueOf(k8sNetwork.gatewayIp(), HOST_PREFIX));
tBuilder.setOutput(PortNumber.LOCAL);
}
if (REPLY.equals(type)) {
sBuilder.matchIPSrc(IpPrefix.valueOf(k8sNetwork.gatewayIp(), HOST_PREFIX));
tBuilder.setOutput(k8sNode.localToIntgPatchPortNum());
}
k8sFlowRuleService.setRule(appId, k8sNode.localBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_LOCAL_BRIDGE_RULE, LOCAL_ENTRY_TABLE, install);
}
use of org.onosproject.net.flow.instructions.ExtensionTreatment in project onos by opennetworkinglab.
the class RulePopulatorUtil method buildResubmitExtension.
/**
* Returns the nicira resubmit extension treatment with given table ID.
*
* @param device device instance
* @param tableId table identifier
* @return resubmit extension treatment
*/
public static ExtensionTreatment buildResubmitExtension(Device device, int tableId) {
if (!checkTreatmentResolver(device)) {
return null;
}
ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_RESUBMIT_TABLE.type());
try {
treatment.setPropertyValue(TABLE_EXTENSION, ((short) tableId));
return treatment;
} catch (ExtensionPropertyException e) {
log.error("Failed to set nicira resubmit extension treatment for {}", device.id());
return null;
}
}
use of org.onosproject.net.flow.instructions.ExtensionTreatment in project onos by opennetworkinglab.
the class K8sNodePortHandler method setServiceToNodeRules.
private void setServiceToNodeRules(K8sNode k8sNode, String clusterIp, ServicePort servicePort, boolean install) {
String protocol = servicePort.getProtocol();
int nodePort = servicePort.getNodePort();
int svcPort = servicePort.getPort();
DeviceId deviceId = k8sNode.extBridge();
String nodeIp = k8sNode.nodeIp().toString();
String nodeIpPrefix = getBclassIpPrefixFromCidr(nodeIp);
if (nodeIpPrefix == null) {
return;
}
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchInPort(k8sNode.extToIntgPatchPortNum()).matchIPSrc(IpPrefix.valueOf(IpAddress.valueOf(clusterIp), HOST_CIDR));
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setIpSrc(k8sNode.nodeIp()).setEthSrc(k8sNode.nodeMac());
if (TCP.equals(protocol)) {
sBuilder.matchIPProtocol(IPv4.PROTOCOL_TCP).matchTcpSrc(TpPort.tpPort(svcPort));
tBuilder.setTcpSrc(TpPort.tpPort(nodePort));
} else if (UDP.equals(protocol)) {
sBuilder.matchIPProtocol(IPv4.PROTOCOL_UDP).matchUdpSrc(TpPort.tpPort(svcPort));
tBuilder.setUdpSrc(TpPort.tpPort(nodePort));
}
ExtensionTreatment loadTreatment = buildLoadExtension(deviceService.getDevice(deviceId), B_CLASS, DST, nodeIpPrefix);
tBuilder.extension(loadTreatment, deviceId);
// in normal mode, we steer the traffic to the local port
if (k8sNode.mode() == PASSTHROUGH) {
PortNumber output = k8sNode.portNumByName(k8sNode.extBridge(), k8sNode.k8sExtToOsPatchPortName());
if (output == null) {
log.warn("Kubernetes external to OpenStack patch port is null");
return;
}
tBuilder.setOutput(output);
} else {
tBuilder.setOutput(PortNumber.LOCAL);
}
k8sFlowRuleService.setRule(appId, deviceId, sBuilder.build(), tBuilder.build(), PRIORITY_NODE_PORT_RULE, EXT_ENTRY_TABLE, install);
}
use of org.onosproject.net.flow.instructions.ExtensionTreatment in project onos by opennetworkinglab.
the class K8sNodePortHandler method setNodeToServiceRules.
private void setNodeToServiceRules(K8sNode k8sNode, String clusterIp, ServicePort servicePort, boolean install) {
String protocol = servicePort.getProtocol();
int nodePort = servicePort.getNodePort();
int svcPort = servicePort.getPort();
DeviceId deviceId = k8sNode.extBridge();
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(k8sNode.nodeIp(), HOST_CIDR));
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setIpDst(IpAddress.valueOf(clusterIp));
if (TCP.equals(protocol)) {
sBuilder.matchIPProtocol(IPv4.PROTOCOL_TCP).matchTcpDst(TpPort.tpPort(nodePort));
tBuilder.setTcpDst(TpPort.tpPort(svcPort));
} else if (UDP.equals(protocol)) {
sBuilder.matchIPProtocol(IPv4.PROTOCOL_UDP).matchUdpDst(TpPort.tpPort(nodePort));
tBuilder.setUdpDst(TpPort.tpPort(svcPort));
}
String podCidr = k8sNetworkService.network(k8sNode.hostname()).cidr();
String prefix = NODE_IP_PREFIX + "." + podCidr.split("\\.")[2];
ExtensionTreatment loadTreatment = buildLoadExtension(deviceService.getDevice(deviceId), B_CLASS, SRC, prefix);
tBuilder.extension(loadTreatment, deviceId).setOutput(k8sNode.extToIntgPatchPortNum());
k8sFlowRuleService.setRule(appId, k8sNode.extBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_NODE_PORT_RULE, EXT_ENTRY_TABLE, install);
}
Aggregations