use of org.onosproject.net.Port 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);
}
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class DefaultK8sNode method macAddress.
private MacAddress macAddress(DeviceId deviceId, String portName) {
Port port = port(deviceId, portName);
Annotations annots = port.annotations();
return annots != null ? MacAddress.valueOf(annots.value(PORT_MAC)) : null;
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class DefaultK8sNode method routerToExtPortNum.
@Override
public PortNumber routerToExtPortNum() {
if (mode() == PASSTHROUGH) {
K8sHostService hostService = DefaultServiceDirectory.getService(K8sHostService.class);
Port port = null;
for (K8sHost host : hostService.hosts()) {
if (host.nodeNames().contains(hostname())) {
for (K8sRouterBridge bridge : host.routerBridges()) {
if (bridge.segmentId() == segmentId()) {
port = port(bridge.deviceId(), routerToExtPatchPortName());
}
}
}
}
if (port == null) {
return null;
} else {
return port.number();
}
}
return null;
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class DefaultK8sNode method routerPortNum.
@Override
public PortNumber routerPortNum() {
if (mode() == PASSTHROUGH) {
K8sHostService hostService = DefaultServiceDirectory.getService(K8sHostService.class);
Port port = null;
for (K8sHost host : hostService.hosts()) {
if (host.nodeNames().contains(hostname())) {
for (K8sRouterBridge bridge : host.routerBridges()) {
if (bridge.segmentId() == segmentId()) {
port = port(bridge.deviceId(), routerPortName());
}
}
}
}
if (port == null) {
return null;
} else {
return port.number();
}
}
return null;
}
use of org.onosproject.net.Port in project onos by opennetworkinglab.
the class DefaultKubevirtNetwork method tenantToTunnelPort.
@Override
public PortNumber tenantToTunnelPort(DeviceId deviceId) {
String portName = TENANT_TO_TUNNEL_PREFIX + segmentIdHex(segmentId);
Port port = port(deviceId, portName);
if (port == null) {
return null;
} else {
return port.number();
}
}
Aggregations