Search in sources :

Example 11 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode 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 12 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackK8sIntegrationManager method setPodToNodeIpRules.

private void setPodToNodeIpRules(IpAddress k8sNodeIp, IpAddress gatewayIp, String osK8sIntPortName, boolean install) {
    InstancePort instPort = instPortByNodeIp(k8sNodeIp);
    if (instPort == null) {
        return;
    }
    OpenstackNode osNode = osNodeByNodeIp(k8sNodeIp);
    if (osNode == null) {
        return;
    }
    PortNumber osK8sIntPortNum = osNode.portNumByName(osK8sIntPortName);
    if (osK8sIntPortNum == null) {
        return;
    }
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(gatewayIp, 32)).matchInPort(osK8sIntPortNum).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setIpDst(k8sNodeIp).setEthDst(instPort.macAddress()).transition(FLAT_TABLE).build();
    osFlowRuleService.setRule(appId, osNode.intgBridge(), selector, treatment, PRIORITY_CNI_PT_IP_RULE, PRE_FLAT_TABLE, install);
    setJumpRules(osK8sIntPortNum, osNode, install);
}
Also used : InstancePort(org.onosproject.openstacknetworking.api.InstancePort) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 13 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackRoutingHandler method setGatewayRules.

private void setGatewayRules(Subnet osSubnet, Router osRouter, boolean install) {
    OpenstackNode srcNatGw = osNodeService.completeNodes(GATEWAY).stream().findFirst().orElse(null);
    if (srcNatGw == null) {
        return;
    }
    if (Strings.isNullOrEmpty(osSubnet.getGateway())) {
        // do nothing if no gateway is set
        return;
    }
    Network net = osNetworkAdminService.network(osSubnet.getNetworkId());
    Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
    Set<Subnet> routableSubnets = routableSubnets(osRouter, osSubnet.getId());
    // install rules to each compute node for routing IP packets to gateways
    osNodeService.completeNodes(COMPUTE).stream().filter(cNode -> cNode.dataIp() != null).forEach(cNode -> setRulesToGatewayWithRoutableSubnets(cNode, srcNatGw, net.getProviderSegID(), osSubnet, routableSubnets, netType, install));
    // install rules to punt ICMP packets to controller at gateway node
    // this rule is only valid for stateless ICMP SNAT case
    osNodeService.completeNodes(GATEWAY).forEach(gNode -> setReactiveGatewayIcmpRule(IpAddress.valueOf(osSubnet.getGateway()), gNode.intgBridge(), install));
    final String updateStr = install ? MSG_ENABLED : MSG_DISABLED;
    log.debug(updateStr + "IP to {}", osSubnet.getGateway());
}
Also used : OpenstackRouterService(org.onosproject.openstacknetworking.api.OpenstackRouterService) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Constants(org.onosproject.openstacknetworking.api.Constants) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) STAT_OUTBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.STAT_OUTBOUND_TABLE) Ethernet(org.onlab.packet.Ethernet) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) PRIORITY_INTERNAL_ROUTING_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_INTERNAL_ROUTING_RULE) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) ApplicationId(org.onosproject.core.ApplicationId) NodeId(org.onosproject.cluster.NodeId) PRIORITY_ICMP_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ICMP_RULE) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ImmutableSet(com.google.common.collect.ImmutableSet) OpenstackFlowRuleService(org.onosproject.openstacknetworking.api.OpenstackFlowRuleService) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) PRIORITY_ADMIN_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ADMIN_RULE) ICMP(org.onlab.packet.ICMP) USE_STATEFUL_SNAT(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.USE_STATEFUL_SNAT) Collectors(java.util.stream.Collectors) OpenstackNetworkingUtil.getPropertyValueAsBoolean(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValueAsBoolean) Objects(java.util.Objects) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) ROUTING_TABLE(org.onosproject.openstacknetworking.api.Constants.ROUTING_TABLE) IpPrefix(org.onlab.packet.IpPrefix) GATEWAY(org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) RulePopulatorUtil.buildExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildExtension) RouterInterface(org.openstack4j.model.network.RouterInterface) OpenstackRouterEvent(org.onosproject.openstacknetworking.api.OpenstackRouterEvent) Strings(com.google.common.base.Strings) Component(org.osgi.service.component.annotations.Component) OpenstackNetworkingUtil.tunnelPortNumByNetType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) Router(org.openstack4j.model.network.Router) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ARP_MODE(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.ARP_MODE) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) PRIORITY_ICMP_REQUEST_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ICMP_REQUEST_RULE) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Subnet(org.openstack4j.model.network.Subnet) PRIORITY_SWITCHING_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_SWITCHING_RULE) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) IPv4(org.onlab.packet.IPv4) OpenstackRouterListener(org.onosproject.openstacknetworking.api.OpenstackRouterListener) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) OpenstackNetworkingUtil.getPropertyValue(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue) ConfigProperty(org.onosproject.cfg.ConfigProperty) OpenstackNetworkingUtil.deriveResourceName(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) ARP_BROADCAST_MODE(org.onosproject.openstacknetworking.api.Constants.ARP_BROADCAST_MODE) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) OpenstackNetworkingUtil.tunnelPortNumByNetType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType) Network(org.openstack4j.model.network.Network) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Subnet(org.openstack4j.model.network.Subnet)

Example 14 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackNetworkingUtil method getGwByIndex.

/**
 * Obtains gateway instance by giving index number.
 *
 * @param gws       a collection of gateway nodes
 * @param index     index number
 * @return gateway instance
 */
private static OpenstackNode getGwByIndex(Set<OpenstackNode> gws, int index) {
    Map<String, OpenstackNode> hashMap = new HashMap<>();
    gws.forEach(gw -> hashMap.put(gw.hostname(), gw));
    TreeMap<String, OpenstackNode> treeMap = new TreeMap<>(hashMap);
    Iterator<String> iteratorKey = treeMap.keySet().iterator();
    int intIndex = 0;
    OpenstackNode gw = null;
    while (iteratorKey.hasNext()) {
        String key = iteratorKey.next();
        if (intIndex == index) {
            gw = treeMap.get(key);
        }
        intIndex++;
    }
    return gw;
}
Also used : HashMap(java.util.HashMap) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) TreeMap(java.util.TreeMap)

Example 15 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackManagementWebResource method syncRulesBaseForNode.

private void syncRulesBaseForNode(OpenstackNode osNode) {
    OpenstackNode updated = osNode.updateState(NodeState.INIT);
    osNodeAdminService.updateNode(updated);
    boolean result = true;
    long timeoutExpiredMs = System.currentTimeMillis() + TIMEOUT_MS;
    while (osNodeAdminService.node(osNode.hostname()).state() != COMPLETE) {
        long waitMs = timeoutExpiredMs - System.currentTimeMillis();
        try {
            sleep(SLEEP_MS);
        } catch (InterruptedException e) {
            log.error("Exception caused during node synchronization...");
        }
        if (osNodeAdminService.node(osNode.hostname()).state() == COMPLETE) {
            break;
        } else {
            osNodeAdminService.updateNode(updated);
            log.info("Failed to synchronize flow rules, retrying...");
        }
        if (waitMs <= 0) {
            result = false;
            break;
        }
    }
    if (result) {
        log.info("Successfully synchronize flow rules for node {}!", osNode.hostname());
    } else {
        log.warn("Failed to synchronize flow rules for node {}.", osNode.hostname());
    }
}
Also used : OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Aggregations

OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)76 OpenstackNodeService (org.onosproject.openstacknode.api.OpenstackNodeService)22 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)19 TrafficSelector (org.onosproject.net.flow.TrafficSelector)19 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)19 PortNumber (org.onosproject.net.PortNumber)14 DefaultOpenstackNode (org.onosproject.openstacknode.api.DefaultOpenstackNode)14 DeviceService (org.onosproject.net.device.DeviceService)13 Set (java.util.Set)12 Test (org.junit.Test)12 IpAddress (org.onlab.packet.IpAddress)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 Objects (java.util.Objects)9 Optional (java.util.Optional)9 ExecutorService (java.util.concurrent.ExecutorService)9 Collectors (java.util.stream.Collectors)9 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)9 Produces (javax.ws.rs.Produces)8 InstancePort (org.onosproject.openstacknetworking.api.InstancePort)7