use of org.onosproject.k8snode.api.K8sNodeInfo in project onos by opennetworkinglab.
the class K8sNodeCodecTest method testK8sMinionNodeEncode.
/**
* Tests the kubernetes minion node encoding.
*/
@Test
public void testK8sMinionNodeEncode() {
K8sNode node = DefaultK8sNode.builder().clusterName("kubernetes").hostname("minion").type(K8sNode.Type.MINION).segmentId(100).state(K8sNodeState.INIT).managementIp(IpAddress.valueOf("10.10.10.1")).dataIp(IpAddress.valueOf("20.20.20.2")).nodeInfo(new K8sNodeInfo(IpAddress.valueOf("30.30.30.3"), null)).intgBridge(DeviceId.deviceId("kbr-int")).extIntf("eth1").extBridgeIp(IpAddress.valueOf("10.10.10.5")).extGatewayIp(IpAddress.valueOf("10.10.10.1")).extGatewayMac(MacAddress.valueOf("FF:FF:FF:FF:FF:FF")).build();
ObjectNode nodeJson = k8sNodeCodec.encode(node, context);
assertThat(nodeJson, matchesK8sNode(node));
}
use of org.onosproject.k8snode.api.K8sNodeInfo in project onos by opennetworkinglab.
the class K8sSwitchingArpHandler method processArpReply.
private void processArpReply(PacketContext context, Ethernet ethPacket) {
ARP arpPacket = (ARP) ethPacket.getPayload();
IpAddress srcIp = IpAddress.valueOf(INET, arpPacket.getSenderProtocolAddress());
MacAddress srcMac = MacAddress.valueOf(arpPacket.getSenderHardwareAddress());
IpAddress dstIp = IpAddress.valueOf(INET, arpPacket.getTargetProtocolAddress());
if (dstIp.equals(IpAddress.valueOf(NODE_FAKE_IP_STR))) {
// mutable MAP scenario is not considered for now
if (!extHostMacStore.containsKey(srcIp)) {
extHostMacStore.put(srcIp, srcMac);
}
K8sNode k8sNode = k8sNodeService.nodes().stream().filter(n -> n.nodeIp().equals(srcIp)).findAny().orElse(null);
if (k8sNode == null) {
return;
} else {
if (k8sNode.nodeInfo().nodeMac() != null) {
return;
}
}
// we update node MAC address which will be referred in node port scenario
K8sNodeInfo nodeInfo = new K8sNodeInfo(k8sNode.nodeIp(), srcMac);
K8sNode updatedNode = k8sNode.updateNodeInfo(nodeInfo);
k8sNodeService.updateNode(updatedNode);
}
}
use of org.onosproject.k8snode.api.K8sNodeInfo in project onos by opennetworkinglab.
the class K8sNodeCodec method decode.
@Override
public K8sNode decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
String clusterName = json.get(CLUSTER_NAME).asText();
if (StringUtils.isEmpty(clusterName)) {
clusterName = DEFAULT_CLUSTER_NAME;
}
String hostname = nullIsIllegal(json.get(HOSTNAME).asText(), HOSTNAME + MISSING_MESSAGE);
String type = nullIsIllegal(json.get(TYPE).asText(), TYPE + MISSING_MESSAGE);
String mIp = nullIsIllegal(json.get(MANAGEMENT_IP).asText(), MANAGEMENT_IP + MISSING_MESSAGE);
String nIp = nullIsIllegal(json.get(NODE_IP).asText(), NODE_IP + MISSING_MESSAGE);
K8sNodeInfo nodeInfo = new K8sNodeInfo(IpAddress.valueOf(nIp), null);
DefaultK8sNode.Builder nodeBuilder = DefaultK8sNode.builder().clusterName(clusterName).hostname(hostname).type(K8sNode.Type.valueOf(type)).state(K8sNodeState.INIT).managementIp(IpAddress.valueOf(mIp)).nodeInfo(nodeInfo);
if (json.get(DATA_IP) != null) {
nodeBuilder.dataIp(IpAddress.valueOf(json.get(DATA_IP).asText()));
}
JsonNode segmentIdJson = json.get(SEGMENT_ID);
int segmentId = DEFAULT_SEGMENT_ID;
if (segmentIdJson != null) {
segmentId = segmentIdJson.asInt();
}
nodeBuilder.segmentId(segmentId);
JsonNode intBridgeJson = json.get(INTEGRATION_BRIDGE);
if (intBridgeJson != null) {
nodeBuilder.intgBridge(DeviceId.deviceId(intBridgeJson.asText()));
}
JsonNode extBridgeJson = json.get(EXTERNAL_BRIDGE);
if (extBridgeJson != null) {
nodeBuilder.extBridge(DeviceId.deviceId(extBridgeJson.asText()));
}
JsonNode localBridgeJson = json.get(LOCAL_BRIDGE);
if (localBridgeJson != null) {
nodeBuilder.localBridge(DeviceId.deviceId(localBridgeJson.asText()));
}
JsonNode tunBridgeJson = json.get(TUNNEL_BRIDGE);
if (tunBridgeJson != null) {
nodeBuilder.tunBridge(DeviceId.deviceId(tunBridgeJson.asText()));
}
JsonNode extIntfJson = json.get(EXTERNAL_INTF);
if (extIntfJson != null) {
nodeBuilder.extIntf(extIntfJson.asText());
}
JsonNode extBridgeIpJson = json.get(EXTERNAL_BRIDGE_IP);
if (extBridgeIpJson != null) {
nodeBuilder.extBridgeIp(IpAddress.valueOf(extBridgeIpJson.asText()));
}
JsonNode extGatewayIpJson = json.get(EXTERNAL_GATEWAY_IP);
if (extGatewayIpJson != null) {
nodeBuilder.extGatewayIp(IpAddress.valueOf(extGatewayIpJson.asText()));
}
JsonNode extGatewayMacJson = json.get(EXTERNAL_GATEWAY_MAC);
if (extGatewayMacJson != null) {
nodeBuilder.extGatewayMac(MacAddress.valueOf(extGatewayMacJson.asText()));
}
log.trace("node is {}", nodeBuilder.build().toString());
return nodeBuilder.build();
}
use of org.onosproject.k8snode.api.K8sNodeInfo in project onos by opennetworkinglab.
the class DefaultK8sApiConfigHandler method buildK8sNode.
private K8sNode buildK8sNode(Node node, K8sApiConfig config) {
String hostname = node.getMetadata().getName();
IpAddress managementIp = null;
IpAddress dataIp = null;
IpAddress nodeIp = null;
// normal mode: we use K8S node's internal IP as the management and data IP
if (config.mode() == PASSTHROUGH) {
HostNodesInfo info = config.infos().stream().filter(h -> h.nodes().contains(hostname)).findAny().orElse(null);
if (info == null) {
log.error("None of the nodes were found in the host nodes info mapping list");
} else {
managementIp = info.hostIp();
dataIp = info.hostIp();
}
for (NodeAddress nodeAddress : node.getStatus().getAddresses()) {
if (nodeAddress.getType().equals(INTERNAL_IP)) {
nodeIp = IpAddress.valueOf(nodeAddress.getAddress());
}
}
} else {
for (NodeAddress nodeAddress : node.getStatus().getAddresses()) {
if (nodeAddress.getType().equals(INTERNAL_IP)) {
managementIp = IpAddress.valueOf(nodeAddress.getAddress());
dataIp = IpAddress.valueOf(nodeAddress.getAddress());
nodeIp = IpAddress.valueOf(nodeAddress.getAddress());
}
}
}
String roleStr = node.getMetadata().getLabels().keySet().stream().filter(l -> l.contains(K8S_ROLE)).findFirst().orElse(null);
K8sNode.Type nodeType = MINION;
if (roleStr != null) {
String role = roleStr.split("/")[1];
if (MASTER.name().equalsIgnoreCase(role)) {
nodeType = MASTER;
} else {
nodeType = MINION;
}
}
Map<String, String> annots = node.getMetadata().getAnnotations();
String extIntf = "";
String extGatewayIpStr = DEFAULT_GATEWAY_IP;
String extBridgeIpStr = DEFAULT_BRIDGE_IP;
if (config.mode() == PASSTHROUGH) {
extNetworkService.registerNetwork(config.extNetworkCidr());
extIntf = EXTERNAL_TO_ROUTER + "-" + config.clusterShortName();
IpAddress gatewayIp = extNetworkService.getGatewayIp(config.extNetworkCidr());
IpAddress bridgeIp = extNetworkService.allocateIp(config.extNetworkCidr());
if (gatewayIp != null) {
extGatewayIpStr = gatewayIp.toString();
}
if (bridgeIp != null) {
extBridgeIpStr = bridgeIp.toString();
}
} else {
extIntf = annots.get(EXT_INTF_NAME);
extGatewayIpStr = annots.get(EXT_GATEWAY_IP);
extBridgeIpStr = annots.get(EXT_BRIDGE_IP);
}
K8sNode.Builder builder = DefaultK8sNode.builder().clusterName(DEFAULT_CLUSTER_NAME).hostname(hostname).managementIp(managementIp).dataIp(dataIp).nodeInfo(new K8sNodeInfo(nodeIp, null)).extIntf(extIntf).type(nodeType).segmentId(config.segmentId()).state(PRE_ON_BOARD).mode(config.mode()).extBridgeIp(IpAddress.valueOf(extBridgeIpStr)).extGatewayIp(IpAddress.valueOf(extGatewayIpStr)).podCidr(node.getSpec().getPodCIDR());
if (config.dvr()) {
builder.extGatewayMac(MacAddress.valueOf(DEFAULT_EXTERNAL_GATEWAY_MAC));
}
return builder.build();
}
use of org.onosproject.k8snode.api.K8sNodeInfo in project onos by opennetworkinglab.
the class K8sNodeWebResourceTest method setUpTest.
/**
* Sets up the global values for all the tests.
*/
@Before
public void setUpTest() {
final CodecManager codecService = new CodecManager();
codecService.activate();
codecService.registerCodec(K8sNode.class, new K8sNodeCodec());
codecService.registerCodec(K8sApiConfig.class, new K8sApiConfigCodec());
codecService.registerCodec(HostNodesInfo.class, new HostNodesInfoCodec());
ServiceDirectory testDirectory = new TestServiceDirectory().add(K8sNodeAdminService.class, mockK8sNodeAdminService).add(K8sApiConfigAdminService.class, mockK8sApiConfigAdminService).add(CodecService.class, codecService);
setServiceDirectory(testDirectory);
k8sNode = DefaultK8sNode.builder().clusterName("kubernetes").hostname("minion-node").type(K8sNode.Type.MINION).dataIp(IpAddress.valueOf("10.134.34.222")).managementIp(IpAddress.valueOf("10.134.231.30")).nodeInfo(new K8sNodeInfo(IpAddress.valueOf("30.30.30.3"), null)).intgBridge(DeviceId.deviceId("of:00000000000000a1")).extBridge(DeviceId.deviceId("of:00000000000000b1")).state(K8sNodeState.INIT).build();
k8sApiConfig = DefaultK8sApiConfig.builder().clusterName("kubernetes").segmentId(1).mode(K8sApiConfig.Mode.NORMAL).scheme(K8sApiConfig.Scheme.HTTPS).ipAddress(IpAddress.valueOf("10.134.34.223")).port(6443).state(DISCONNECTED).token("tokenMod").caCertData("caCertData").clientCertData("clientCertData").clientKeyData("clientKeyData").build();
}
Aggregations