use of org.onosproject.k8snetworking.api.K8sNetwork in project onos by opennetworkinglab.
the class K8sSwitchingHandler method setExtToIntgTunnelTagFlowRules.
private void setExtToIntgTunnelTagFlowRules(K8sNode k8sNode, boolean install) {
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchInPort(k8sNode.intgToExtPatchPortNum()).build();
K8sNetwork net = k8sNetworkService.network(k8sNode.hostname());
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setTunnelId(Long.valueOf(net.segmentId())).transition(JUMP_TABLE);
k8sFlowRuleService.setRule(appId, k8sNode.intgBridge(), selector, tBuilder.build(), PRIORITY_TUNNEL_TAG_RULE, VTAG_TABLE, install);
}
use of org.onosproject.k8snetworking.api.K8sNetwork in project onos by opennetworkinglab.
the class K8sNetworkingUtil method nodeIpGatewayIpMap.
/**
* Obtains the kubernetes node IP and kubernetes network gateway IP map.
*
* @param nodeService kubernetes node service
* @param networkService kubernetes network service
* @return kubernetes node IP and kubernetes network gateway IP map
*/
public static Map<String, String> nodeIpGatewayIpMap(K8sNodeService nodeService, K8sNetworkService networkService) {
Map<String, String> ipMap = Maps.newConcurrentMap();
nodeService.completeNodes().forEach(n -> {
K8sNetwork network = networkService.network(n.hostname());
if (network != null) {
ipMap.put(n.nodeIp().toString(), network.gatewayIp().toString());
}
});
return ipMap;
}
use of org.onosproject.k8snetworking.api.K8sNetwork in project onos by opennetworkinglab.
the class K8sNetworkCodecTest method testK8sNetworkDecode.
/**
* Tests the kubernetes network decoding.
*/
@Test
public void testK8sNetworkDecode() throws IOException {
K8sNetwork network = getK8sNetwork("K8sNetwork.json");
assertEquals("network-1", network.networkId());
assertEquals("network-1", network.name());
assertEquals("1", network.segmentId());
assertEquals("VXLAN", network.type().name());
assertEquals("10.10.0.1", network.gatewayIp().toString());
assertEquals("10.10.0.0/24", network.cidr());
assertThat(network.mtu(), is(1500));
}
use of org.onosproject.k8snetworking.api.K8sNetwork in project onos by opennetworkinglab.
the class K8sNetworkCodecTest method getK8sNetwork.
/**
* Reads in an kubernetes network from the given resource and decodes it.
*
* @param resourceName resource to use to read the JSON for the rule
* @return decoded kubernetes network
* @throws IOException if processing the resource fails
*/
private K8sNetwork getK8sNetwork(String resourceName) throws IOException {
InputStream jsonStream = K8sNetworkCodecTest.class.getResourceAsStream(resourceName);
JsonNode json = context.mapper().readTree(jsonStream);
MatcherAssert.assertThat(json, notNullValue());
K8sNetwork network = k8sNetworkCodec.decode((ObjectNode) json, context);
assertThat(network, notNullValue());
return network;
}
use of org.onosproject.k8snetworking.api.K8sNetwork in project onos by opennetworkinglab.
the class K8sSwitchingHostProvider method processPortAdded.
/**
* Processes port addition event.
*
* @param port port object used in ONOS
*/
private void processPortAdded(Port port) {
K8sPort k8sPort = portToK8sPortByName(port);
if (k8sPort == null) {
k8sPort = portToK8sPortByMac(port);
if (k8sPort == null) {
log.warn(ERR_ADD_HOST + "Kubernetes port for {} not found", port);
return;
}
}
K8sNetwork k8sNet = k8sNetworkService.network(k8sPort.networkId());
if (k8sNet == null) {
log.warn(ERR_ADD_HOST + "Kubernetes network {} not found", k8sPort.networkId());
return;
}
MacAddress mac = k8sPort.macAddress();
HostId hostId = HostId.hostId(mac);
// connect point is the combination of switch ID with port number where
// the host is attached to
ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number());
long createTime = System.currentTimeMillis();
// update k8s port number by referring to ONOS port number
k8sNetworkService.updatePort(k8sPort.updatePortNumber(port.number()).updateState(K8sPort.State.ACTIVE));
// we check whether the host already attached to same locations
Host host = hostService.getHost(hostId);
// build host annotations to include a set of meta info from neutron
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(ANNOTATION_NETWORK_ID, k8sPort.networkId()).set(ANNOTATION_PORT_ID, k8sPort.portId()).set(ANNOTATION_CREATE_TIME, String.valueOf(createTime)).set(ANNOTATION_SEGMENT_ID, k8sNet.segmentId());
HostDescription hostDesc = new DefaultHostDescription(mac, VlanId.NONE, new HostLocation(connectPoint, createTime), ImmutableSet.of(k8sPort.ipAddress()), annotations.build());
if (host != null) {
Set<HostLocation> locations = host.locations().stream().filter(l -> l.deviceId().equals(connectPoint.deviceId())).filter(l -> l.port().equals(connectPoint.port())).collect(Collectors.toSet());
// therefore, we simply add this into the location list
if (locations.isEmpty()) {
hostProviderService.addLocationToHost(hostId, new HostLocation(connectPoint, createTime));
}
// the hostDetected method invocation in turn triggers host Update event
if (locations.size() == 1) {
hostProviderService.hostDetected(hostId, hostDesc, false);
}
} else {
hostProviderService.hostDetected(hostId, hostDesc, false);
}
}
Aggregations