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);
}
}
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;
}
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;
}
}
}
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();
}
Aggregations