use of org.onosproject.net.HostId 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.HostId in project onos by opennetworkinglab.
the class LayoutAlgorithm method placeHostBlock.
/**
* Places the specified collection of hosts (all presumably connected to
* the same network device) in a block.
*
* @param hosts hosts to place
* @param gridX grid X of the top of the block
* @param gridY grid Y of the center of the block
* @param hostsPerRow number of hosts in a 'row'
* @param rowGap gap width between rows
* @param colGap gap width between columns
*/
protected void placeHostBlock(Collection<HostId> hosts, double gridX, double gridY, int hostsPerRow, double rowGap, double colGap) {
double yStep = rowGap / hostsPerRow;
double y = gridY;
double x = gridX - (colGap * (hostsPerRow - 1)) / 2;
int i = 1;
for (HostId id : hosts) {
place(id, x, y);
if ((i % hostsPerRow) == 0) {
x = gridX - (colGap * (hostsPerRow - 1)) / 2;
} else {
x += colGap;
y += yStep;
}
i++;
}
}
use of org.onosproject.net.HostId in project onos by opennetworkinglab.
the class McastSinkDeleteCommand method doExecute.
@Override
protected void doExecute() {
MulticastRouteService mcastRouteManager = get(MulticastRouteService.class);
// Clear all routes
if ("*".equals(sAddr) && "*".equals(gAddr)) {
mcastRouteManager.getRoutes().forEach(mcastRouteManager::remove);
return;
}
// Removing/updating a specific entry
IpAddress sAddrIp = null;
// If the source Ip is * we want ASM so we leave it as null and the route will have it as an optional.empty()
if (!sAddr.equals("*")) {
sAddrIp = IpAddress.valueOf(sAddr);
}
McastRoute mRoute = new McastRoute(sAddrIp, IpAddress.valueOf(gAddr), McastRoute.Type.STATIC);
// If the user provides only sAddr and gAddr, we have to remove the route
if (host == null || host.isEmpty()) {
mcastRouteManager.remove(mRoute);
printMcastRoute(D_FORMAT_MAPPING, mRoute);
return;
}
// Otherwise we need to remove a specific sink
HostId hostId = HostId.hostId(host);
if (!mcastRouteManager.getRoutes().contains(mRoute)) {
print("Route is not present, store it first");
return;
}
// Remove the entire host id
mcastRouteManager.removeSink(mRoute, hostId);
// We have done
printMcastRoute(U_FORMAT_MAPPING, mRoute);
}
use of org.onosproject.net.HostId in project onos by opennetworkinglab.
the class McastShowHostCommand method prepareResult.
private void prepareResult(MulticastRouteService mcastService, McastRoute route) {
if (outputJson()) {
// McastHostRouteCodec is used to encode McastRoute
ObjectNode routeNode = jsonForEntity(route, McastRoute.class);
routesNode.add(routeNode);
} else {
Map<HostId, Set<ConnectPoint>> sinks = mcastService.routeData(route).sinks();
Map<HostId, Set<ConnectPoint>> sources = mcastService.routeData(route).sources();
String srcIp = "*";
if (route.source().isPresent()) {
srcIp = route.source().get().toString();
}
routesBuilder.append(String.format(FORMAT_MAPPING, route.type(), route.group(), srcIp, sources, sinks));
}
}
use of org.onosproject.net.HostId in project onos by opennetworkinglab.
the class McastRouteWebResource method createRoute.
/**
* Create new multicast route.
*
* @param stream multicast route JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel McastRoute
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response createRoute(InputStream stream) {
MulticastRouteService service = get(MulticastRouteService.class);
try {
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
McastRoute route = codec(McastRoute.class).decode(jsonTree, this);
service.add(route);
Set<HostId> sources = new HashSet<>();
jsonTree.path(SOURCES).elements().forEachRemaining(src -> {
sources.add(HostId.hostId(src.asText()));
});
Set<HostId> sinks = new HashSet<>();
jsonTree.path(SINKS).elements().forEachRemaining(sink -> {
sinks.add(HostId.hostId(sink.asText()));
});
if (!sources.isEmpty()) {
sources.forEach(source -> {
service.addSource(route, source);
});
}
if (!sinks.isEmpty()) {
sinks.forEach(sink -> {
service.addSink(route, sink);
});
}
} catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
return Response.created(URI.create("")).build();
}
Aggregations