Search in sources :

Example 1 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 2 with TpPort

use of org.onlab.packet.TpPort in project onos by opennetworkinglab.

the class TelemetryVflowListCommand method doExecute.

@Override
protected void doExecute() {
    CoreService coreService = get(CoreService.class);
    FlowRuleService flowService = get(FlowRuleService.class);
    ApplicationId appId = coreService.getAppId(OPENSTACK_TELEMETRY_APP_ID);
    List<FlowEntry> flows = Lists.newArrayList(flowService.getFlowEntriesById(appId));
    print(FORMAT, "SrcIp", "SrcPort", "DstIp", "DstPort", "Protocol");
    for (FlowEntry entry : flows) {
        TrafficSelector selector = entry.selector();
        IpPrefix srcIp = ((IPCriterion) selector.getCriterion(IPV4_SRC)).ip();
        IpPrefix dstIp = ((IPCriterion) selector.getCriterion(IPV4_DST)).ip();
        TpPort srcPort = TpPort.tpPort(0);
        TpPort dstPort = TpPort.tpPort(0);
        String protocolStr = "ANY";
        Criterion ipProtocolCriterion = selector.getCriterion(IP_PROTO);
        if (ipProtocolCriterion != null) {
            short protocol = ((IPProtocolCriterion) selector.getCriterion(IP_PROTO)).protocol();
            if (protocol == PROTOCOL_TCP) {
                srcPort = ((TcpPortCriterion) selector.getCriterion(TCP_SRC)).tcpPort();
                dstPort = ((TcpPortCriterion) selector.getCriterion(TCP_DST)).tcpPort();
                protocolStr = TCP;
            }
            if (protocol == PROTOCOL_UDP) {
                srcPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
                dstPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
                protocolStr = UDP;
            }
        }
        print(FORMAT, srcIp.toString(), srcPort.toString(), dstIp.toString(), dstPort.toString(), protocolStr);
    }
}
Also used : IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) CoreService(org.onosproject.core.CoreService) IpPrefix(org.onlab.packet.IpPrefix) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) TpPort(org.onlab.packet.TpPort) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 3 with TpPort

use of org.onlab.packet.TpPort in project onos by opennetworkinglab.

the class NetconfAccessInfo method valueOf.

/**
 * Builds NetconfAccessInfo from json.
 * @param root json root node for NetconfAccessinfo
 * @return NETCONF access information
 * @throws WorkflowException workflow exception
 */
public static NetconfAccessInfo 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 NetconfAccessInfo(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 4 with TpPort

use of org.onlab.packet.TpPort in project onos by opennetworkinglab.

the class PiCriterionTranslatorsTest method testSctpPortCriterion.

@Test
public void testSctpPortCriterion() 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;
    SctpPortCriterion criterion = (SctpPortCriterion) Criteria.matchSctpDst(value1);
    PiExactFieldMatch exactMatch = (PiExactFieldMatch) translateCriterion(criterion, fieldId, EXACT, bitWidth);
    SctpPortCriterion maskedCriterion = (SctpPortCriterion) Criteria.matchSctpDstMasked(value2, mask);
    PiTernaryFieldMatch ternaryMatch = (PiTernaryFieldMatch) translateCriterion(maskedCriterion, fieldId, TERNARY, bitWidth);
    assertThat(exactMatch.value().asReadOnlyBuffer().getShort(), is((short) criterion.sctpPort().toInt()));
    assertThat(ternaryMatch.value().asReadOnlyBuffer().getShort(), is((short) maskedCriterion.sctpPort().toInt()));
    assertThat(ternaryMatch.mask().asReadOnlyBuffer().getShort(), is((short) maskedCriterion.mask().toInt()));
}
Also used : TpPort(org.onlab.packet.TpPort) PiExactFieldMatch(org.onosproject.net.pi.runtime.PiExactFieldMatch) PiTernaryFieldMatch(org.onosproject.net.pi.runtime.PiTernaryFieldMatch) SctpPortCriterion(org.onosproject.net.flow.criteria.SctpPortCriterion) Test(org.junit.Test)

Example 5 with TpPort

use of org.onlab.packet.TpPort in project onos by opennetworkinglab.

the class OvsdbControllerConfig method getOvsdbClientService.

// Used for getting OvsdbClientService.
private OvsdbClientService getOvsdbClientService(DriverHandler handler) {
    OvsdbController ovsController = handler.get(OvsdbController.class);
    DeviceService deviceService = handler.get(DeviceService.class);
    DeviceId ofDeviceId = handler.data().deviceId();
    String[] mgmtAddress = deviceService.getDevice(ofDeviceId).annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS).split(":");
    String targetIp = mgmtAddress[0];
    TpPort targetPort = null;
    if (mgmtAddress.length > 1) {
        targetPort = TpPort.tpPort(Integer.parseInt(mgmtAddress[1]));
    }
    List<OvsdbNodeId> nodeIds = ovsController.getNodeIds().stream().filter(nodeId -> nodeId.getIpAddress().equals(targetIp)).collect(Collectors.toList());
    if (nodeIds.isEmpty()) {
        // TODO decide what port?
        ovsController.connect(IpAddress.valueOf(targetIp), targetPort == null ? TpPort.tpPort(OvsdbConstant.OVSDBPORT) : targetPort);
        // FIXME... connect is async
        delay(1000);
    }
    List<OvsdbClientService> clientServices = ovsController.getNodeIds().stream().filter(nodeId -> nodeId.getIpAddress().equals(targetIp)).map(ovsController::getOvsdbClient).filter(cs -> cs.getBridges().stream().anyMatch(b -> dpidMatches(b, ofDeviceId))).collect(Collectors.toList());
    checkState(!clientServices.isEmpty(), "No clientServices found");
    // FIXME add connection to management address if null --> done ?
    return !clientServices.isEmpty() ? clientServices.get(0) : null;
}
Also used : TpPort(org.onlab.packet.TpPort) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) ImmutableSet(com.google.common.collect.ImmutableSet) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId) DeviceService(org.onosproject.net.device.DeviceService) Set(java.util.Set) AnnotationKeys(org.onosproject.net.AnnotationKeys) ControllerConfig(org.onosproject.net.behaviour.ControllerConfig) Collectors(java.util.stream.Collectors) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) ArrayList(java.util.ArrayList) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) DriverHandler(org.onosproject.net.driver.DriverHandler) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) Tools.delay(org.onlab.util.Tools.delay) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) OvsdbConstant(org.onosproject.ovsdb.controller.OvsdbConstant) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) DeviceId(org.onosproject.net.DeviceId) IpAddress(org.onlab.packet.IpAddress) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) TpPort(org.onlab.packet.TpPort) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId)

Aggregations

TpPort (org.onlab.packet.TpPort)10 IpAddress (org.onlab.packet.IpAddress)5 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 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 DeviceId (org.onosproject.net.DeviceId)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