Search in sources :

Example 6 with TpPort

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);
    });
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TpPort(org.onlab.packet.TpPort) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 7 with TpPort

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);
}
Also used : WorkflowException(org.onosproject.workflow.api.WorkflowException) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) IpAddress(org.onlab.packet.IpAddress) TpPort(org.onlab.packet.TpPort) NumericNode(com.fasterxml.jackson.databind.node.NumericNode)

Example 8 with TpPort

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);
}
Also used : WorkflowException(org.onosproject.workflow.api.WorkflowException) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) IpAddress(org.onlab.packet.IpAddress) TpPort(org.onlab.packet.TpPort) NumericNode(com.fasterxml.jackson.databind.node.NumericNode)

Example 9 with TpPort

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()));
}
Also used : TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) TpPort(org.onlab.packet.TpPort) PiExactFieldMatch(org.onosproject.net.pi.runtime.PiExactFieldMatch) PiTernaryFieldMatch(org.onosproject.net.pi.runtime.PiTernaryFieldMatch) Test(org.junit.Test)

Example 10 with TpPort

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()));
}
Also used : UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) TpPort(org.onlab.packet.TpPort) PiExactFieldMatch(org.onosproject.net.pi.runtime.PiExactFieldMatch) PiTernaryFieldMatch(org.onosproject.net.pi.runtime.PiTernaryFieldMatch) Test(org.junit.Test)

Aggregations

TpPort (org.onlab.packet.TpPort)11 IpAddress (org.onlab.packet.IpAddress)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 NumericNode (com.fasterxml.jackson.databind.node.NumericNode)3 TextNode (com.fasterxml.jackson.databind.node.TextNode)3 Test (org.junit.Test)3 DeviceId (org.onosproject.net.DeviceId)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Tools.delay (org.onlab.util.Tools.delay)2 AnnotationKeys (org.onosproject.net.AnnotationKeys)2 DeviceService (org.onosproject.net.device.DeviceService)2 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)2 DriverHandler (org.onosproject.net.driver.DriverHandler)2 TrafficSelector (org.onosproject.net.flow.TrafficSelector)2 PiExactFieldMatch (org.onosproject.net.pi.runtime.PiExactFieldMatch)2 PiTernaryFieldMatch (org.onosproject.net.pi.runtime.PiTernaryFieldMatch)2 OvsdbBridge (org.onosproject.ovsdb.controller.OvsdbBridge)2