Search in sources :

Example 1 with K8sTunnelBridge

use of org.onosproject.k8snode.api.K8sTunnelBridge in project onos by opennetworkinglab.

the class DefaultK8sHostHandler method processDeviceCreatedState.

@Override
public void processDeviceCreatedState(K8sHost k8sHost) {
    try {
        if (!isOvsdbConnected(k8sHost, ovsdbPortNum, ovsdbController, deviceService)) {
            ovsdbController.connect(k8sHost.hostIp(), tpPort(ovsdbPortNum));
            return;
        }
        // create patch ports into tunnel bridge face to integration bridge
        for (K8sTunnelBridge bridge : k8sHost.tunBridges()) {
            for (String node : k8sHost.nodeNames()) {
                K8sNode k8sNode = k8sNodeAdminService.node(node);
                if (k8sNode.segmentId() == bridge.tunnelId()) {
                    createTunnelPatchInterfaces(k8sHost.ovsdb(), bridge, k8sNode);
                    createInterPatchInterfaces(k8sHost.ovsdb(), k8sNode);
                }
            }
        }
        // create tunnel ports
        for (K8sTunnelBridge bridge : k8sHost.tunBridges()) {
            if (!isTunPortEnabled(bridge, bridge.vxlanPortName())) {
                createVxlanTunnelInterface(k8sHost.ovsdb(), bridge);
            }
            if (!isTunPortEnabled(bridge, bridge.grePortName())) {
                createGreTunnelInterface(k8sHost.ovsdb(), bridge);
            }
            if (!isTunPortEnabled(bridge, bridge.genevePortName())) {
                createGeneveTunnelInterface(k8sHost.ovsdb(), bridge);
            }
        }
        // create patch ports into router bridge face to external bridge
        for (K8sRouterBridge bridge : k8sHost.routerBridges()) {
            for (String node : k8sHost.nodeNames()) {
                K8sNode k8sNode = k8sNodeAdminService.node(node);
                if (k8sNode.segmentId() == bridge.segmentId()) {
                    createRouterPatchInterfaces(k8sHost.ovsdb(), bridge, k8sNode);
                }
            }
        }
    } catch (Exception e) {
        log.error("Exception occurred because of {}", e);
    }
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) K8sRouterBridge(org.onosproject.k8snode.api.K8sRouterBridge) K8sTunnelBridge(org.onosproject.k8snode.api.K8sTunnelBridge)

Example 2 with K8sTunnelBridge

use of org.onosproject.k8snode.api.K8sTunnelBridge in project onos by opennetworkinglab.

the class K8sNetworkingUtil method allK8sDevices.

/**
 * Returns all device identifiers belong to kubernetes nodes and hosts.
 *
 * @param nodeService   node service
 * @param hostService   host service
 * @return all device identifiers belong to kubernetes nodes and hosts
 */
public static Set<DeviceId> allK8sDevices(K8sNodeService nodeService, K8sHostService hostService) {
    Set<DeviceId> allDevIds = new HashSet<>();
    Set<DeviceId> intgDevIds = nodeService.completeNodes().stream().map(K8sNode::intgBridge).collect(Collectors.toSet());
    Set<DeviceId> extDevIds = nodeService.completeNodes().stream().map(K8sNode::extBridge).collect(Collectors.toSet());
    Set<DeviceId> tunDevIds = nodeService.completeNodes().stream().map(K8sNode::tunBridge).collect(Collectors.toSet());
    Set<DeviceId> localDevIds = nodeService.completeNodes().stream().map(K8sNode::localBridge).collect(Collectors.toSet());
    Set<DeviceId> hostTunDevIds = new HashSet<>();
    Set<DeviceId> hostRouterDevIds = new HashSet<>();
    for (K8sHost host : hostService.completeHosts()) {
        Set<K8sTunnelBridge> hostTunBrs = host.tunBridges();
        Set<K8sRouterBridge> hostRouterBrs = host.routerBridges();
        hostTunDevIds.addAll(hostTunBrs.stream().map(K8sTunnelBridge::deviceId).collect(Collectors.toSet()));
        hostRouterDevIds.addAll(hostRouterBrs.stream().map(K8sRouterBridge::deviceId).collect(Collectors.toSet()));
    }
    allDevIds.addAll(intgDevIds);
    allDevIds.addAll(extDevIds);
    allDevIds.addAll(tunDevIds);
    allDevIds.addAll(localDevIds);
    allDevIds.addAll(hostTunDevIds);
    allDevIds.addAll(hostRouterDevIds);
    return allDevIds;
}
Also used : DeviceId(org.onosproject.net.DeviceId) K8sHost(org.onosproject.k8snode.api.K8sHost) K8sRouterBridge(org.onosproject.k8snode.api.K8sRouterBridge) K8sTunnelBridge(org.onosproject.k8snode.api.K8sTunnelBridge) HashSet(java.util.HashSet)

Example 3 with K8sTunnelBridge

use of org.onosproject.k8snode.api.K8sTunnelBridge in project onos by opennetworkinglab.

the class K8sNetworkingUtil method tunnelPortNumByNetType.

/**
 * Returns the tunnel port number with specified net type and kubernetes node.
 *
 * @param netType       network type
 * @param node          kubernetes node
 * @return tunnel port number
 */
public static PortNumber tunnelPortNumByNetType(K8sNetwork.Type netType, K8sNode node) {
    if (node.mode() == PASSTHROUGH) {
        K8sHostService hostService = DefaultServiceDirectory.getService(K8sHostService.class);
        Port port = null;
        for (K8sHost host : hostService.hosts()) {
            if (host.nodeNames().contains(node.hostname())) {
                for (K8sTunnelBridge bridge : host.tunBridges()) {
                    if (bridge.tunnelId() == node.segmentId()) {
                        String portName = netType.name().toLowerCase() + "-" + node.segmentId();
                        port = port(bridge.deviceId(), portName);
                    }
                }
            }
        }
        if (port == null) {
            return null;
        } else {
            return port.number();
        }
    } else {
        switch(netType) {
            case VXLAN:
                return node.vxlanPortNum();
            case GRE:
                return node.grePortNum();
            case GENEVE:
                return node.genevePortNum();
            default:
                return null;
        }
    }
}
Also used : Port(org.onosproject.net.Port) DefaultK8sPort(org.onosproject.k8snetworking.api.DefaultK8sPort) K8sPort(org.onosproject.k8snetworking.api.K8sPort) TpPort(org.onlab.packet.TpPort) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) K8sHost(org.onosproject.k8snode.api.K8sHost) K8sHostService(org.onosproject.k8snode.api.K8sHostService) K8sTunnelBridge(org.onosproject.k8snode.api.K8sTunnelBridge)

Example 4 with K8sTunnelBridge

use of org.onosproject.k8snode.api.K8sTunnelBridge in project onos by opennetworkinglab.

the class DefaultK8sApiConfigHandler method buildK8sHost.

private K8sHost buildK8sHost(HostNodesInfo hostNodesInfo, K8sApiConfig config) {
    int segmentId = config.segmentId();
    K8sTunnelBridge tBridge = new K8sTunnelBridge(segmentId);
    K8sRouterBridge rBridge = new K8sRouterBridge(segmentId);
    return DefaultK8sHost.builder().hostIp(hostNodesInfo.hostIp()).state(K8sHostState.INIT).tunBridges(ImmutableSet.of(tBridge)).routerBridges(ImmutableSet.of(rBridge)).nodeNames(hostNodesInfo.nodes()).build();
}
Also used : K8sRouterBridge(org.onosproject.k8snode.api.K8sRouterBridge) K8sTunnelBridge(org.onosproject.k8snode.api.K8sTunnelBridge)

Aggregations

K8sTunnelBridge (org.onosproject.k8snode.api.K8sTunnelBridge)4 K8sRouterBridge (org.onosproject.k8snode.api.K8sRouterBridge)3 K8sHost (org.onosproject.k8snode.api.K8sHost)2 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)1 HashSet (java.util.HashSet)1 TpPort (org.onlab.packet.TpPort)1 DefaultK8sPort (org.onosproject.k8snetworking.api.DefaultK8sPort)1 K8sPort (org.onosproject.k8snetworking.api.K8sPort)1 K8sHostService (org.onosproject.k8snode.api.K8sHostService)1 K8sNode (org.onosproject.k8snode.api.K8sNode)1 DeviceId (org.onosproject.net.DeviceId)1 Port (org.onosproject.net.Port)1