use of org.onlab.packet.TpPort in project onos by opennetworkinglab.
the class OpenstackK8sIntegrationManager method setNodePortIngressRules.
private void setNodePortIngressRules(IpAddress k8sNodeIp, String osK8sExtPortName, boolean install) {
OpenstackNode osNode = osNodeByNodeIp(k8sNodeIp);
if (osNode == null) {
return;
}
PortNumber osK8sExtPortNum = portNumberByNodeIpAndPortName(k8sNodeIp, osK8sExtPortName);
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(osK8sExtPortNum).build();
Map<TpPort, TpPort> portRangeMatchMap = buildPortRangeMatches(NODE_PORT_MIN, NODE_PORT_MAX);
portRangeMatchMap.forEach((key, value) -> {
TrafficSelector.Builder tcpSelectorBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(k8sNodeIp, 32)).matchIPProtocol(IPv4.PROTOCOL_TCP).matchTcpDstMasked(key, value);
TrafficSelector.Builder udpSelectorBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(k8sNodeIp, 32)).matchIPProtocol(IPv4.PROTOCOL_UDP).matchUdpDstMasked(key, value);
osFlowRuleService.setRule(appId, osNode.intgBridge(), tcpSelectorBuilder.build(), treatment, PRIORITY_CNI_PT_NODE_PORT_IP_RULE, PRE_FLAT_TABLE, install);
osFlowRuleService.setRule(appId, osNode.intgBridge(), udpSelectorBuilder.build(), treatment, PRIORITY_CNI_PT_NODE_PORT_IP_RULE, PRE_FLAT_TABLE, install);
});
}
use of org.onlab.packet.TpPort in project onos by opennetworkinglab.
the class RestAccessInfo method valueOf.
/**
* Builds RestAccessInfo from json.
* @param root json root node for RestAccessinfo
* @return REST access information
* @throws WorkflowException workflow exception
*/
public static RestAccessInfo valueOf(JsonNode root) throws WorkflowException {
JsonNode node = root.at(ptr(REMOTE_IP));
if (node == null || !(node instanceof TextNode)) {
throw new WorkflowException("invalid remoteIp for " + root);
}
IpAddress remoteIp = IpAddress.valueOf(node.asText());
node = root.at(ptr(PORT));
if (node == null || !(node instanceof NumericNode)) {
throw new WorkflowException("invalid port for " + root);
}
TpPort tpPort = TpPort.tpPort(node.asInt());
node = root.at(ptr(USER));
if (node == null || !(node instanceof TextNode)) {
throw new WorkflowException("invalid user for " + root);
}
String strUser = node.asText();
node = root.at(ptr(PASSWORD));
if (node == null || !(node instanceof TextNode)) {
throw new WorkflowException("invalid password for " + root);
}
String strPassword = node.asText();
return new RestAccessInfo(remoteIp, tpPort, strUser, strPassword);
}
use of org.onlab.packet.TpPort in project onos by opennetworkinglab.
the class SshAccessInfo method valueOf.
/**
* Builds SshAccessInfo from json.
* @param root json root node for SshAccessinfo
* @return SSH access information
* @throws WorkflowException workflow exception
*/
public static SshAccessInfo valueOf(JsonNode root) throws WorkflowException {
JsonNode node = root.at(ptr(REMOTE_IP));
if (node == null || !(node instanceof TextNode)) {
throw new WorkflowException("invalid remoteIp for " + root);
}
IpAddress sshIp = IpAddress.valueOf(node.asText());
node = root.at(ptr(PORT));
if (node == null || !(node instanceof NumericNode)) {
throw new WorkflowException("invalid port for " + root);
}
TpPort sshPort = TpPort.tpPort(node.asInt());
node = root.at(ptr(USER));
if (node == null || !(node instanceof TextNode)) {
throw new WorkflowException("invalid user for " + root);
}
String sshUser = node.asText();
node = root.at(ptr(PASSWORD));
if (node == null || !(node instanceof TextNode)) {
throw new WorkflowException("invalid password for " + root);
}
String sshPassword = node.asText();
node = root.at(ptr(KEYFILE));
if (node == null || !(node instanceof TextNode)) {
throw new WorkflowException("invalid keyfile for " + root);
}
String sshKeyfile = node.asText();
return new SshAccessInfo(sshIp, sshPort, sshUser, sshPassword, sshKeyfile);
}
use of org.onlab.packet.TpPort in project onos by opennetworkinglab.
the class PiCriterionTranslatorsTest method testTcpPortCriterion.
@Test
public void testTcpPortCriterion() throws Exception {
TpPort value1 = TpPort.tpPort(random.nextInt(1 << 16));
TpPort value2 = TpPort.tpPort(random.nextInt(1 << 16));
TpPort mask = TpPort.tpPort(random.nextInt(1 << 16));
int bitWidth = 16;
TcpPortCriterion criterion = (TcpPortCriterion) Criteria.matchTcpDst(value1);
PiExactFieldMatch exactMatch = (PiExactFieldMatch) translateCriterion(criterion, fieldId, EXACT, bitWidth);
TcpPortCriterion maskedCriterion = (TcpPortCriterion) Criteria.matchTcpDstMasked(value2, mask);
PiTernaryFieldMatch ternaryMatch = (PiTernaryFieldMatch) translateCriterion(maskedCriterion, fieldId, TERNARY, bitWidth);
assertThat(exactMatch.value().asReadOnlyBuffer().getShort(), is((short) criterion.tcpPort().toInt()));
assertThat(ternaryMatch.value().asReadOnlyBuffer().getShort(), is((short) maskedCriterion.tcpPort().toInt()));
assertThat(ternaryMatch.mask().asReadOnlyBuffer().getShort(), is((short) maskedCriterion.mask().toInt()));
}
use of org.onlab.packet.TpPort in project onos by opennetworkinglab.
the class PiCriterionTranslatorsTest method testUdpPortCriterion.
@Test
public void testUdpPortCriterion() throws Exception {
TpPort value1 = TpPort.tpPort(random.nextInt(65536));
TpPort value2 = TpPort.tpPort(random.nextInt(65536));
TpPort mask = TpPort.tpPort(random.nextInt(65536));
int bitWidth = 16;
UdpPortCriterion criterion = (UdpPortCriterion) Criteria.matchUdpDst(value1);
PiExactFieldMatch exactMatch = (PiExactFieldMatch) translateCriterion(criterion, fieldId, EXACT, bitWidth);
UdpPortCriterion maskedCriterion = (UdpPortCriterion) Criteria.matchUdpDstMasked(value2, mask);
PiTernaryFieldMatch ternaryMatch = (PiTernaryFieldMatch) translateCriterion(maskedCriterion, fieldId, TERNARY, bitWidth);
assertThat(exactMatch.value().asReadOnlyBuffer().getShort(), is((short) criterion.udpPort().toInt()));
assertThat(ternaryMatch.value().asReadOnlyBuffer().getShort(), is((short) maskedCriterion.udpPort().toInt()));
assertThat(ternaryMatch.mask().asReadOnlyBuffer().getShort(), is((short) maskedCriterion.mask().toInt()));
}
Aggregations