use of org.onosproject.net.config.basics.BasicHostConfig in project onos by opennetworkinglab.
the class NetworkConfigHostProvider method readInitialConfig.
private void readInitialConfig() {
networkConfigRegistry.getSubjects(HostId.class).forEach(hostId -> {
MacAddress mac = hostId.mac();
VlanId vlan = hostId.vlanId();
BasicHostConfig hostConfig = networkConfigRegistry.getConfig(hostId, BasicHostConfig.class);
Set<IpAddress> ipAddresses = hostConfig.ipAddresses();
Set<HostLocation> locs = hostConfig.locations();
if (locs != null) {
Set<HostLocation> locations = locs.stream().map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis())).collect(Collectors.toSet());
// auxLocations allows to be null
Set<HostLocation> auxLocations = hostConfig.auxLocations();
if (auxLocations != null) {
auxLocations = auxLocations.stream().map(auxLocation -> new HostLocation(auxLocation, System.currentTimeMillis())).collect(Collectors.toSet());
}
VlanId innerVlan = hostConfig.innerVlan();
EthType outerTpid = hostConfig.outerTpid();
addHost(mac, vlan, locations, auxLocations, ipAddresses, innerVlan, outerTpid);
} else {
log.warn("Host {} configuration {} is missing locations", hostId, hostConfig);
}
});
}
use of org.onosproject.net.config.basics.BasicHostConfig in project onos by opennetworkinglab.
the class CreateNullHosts method doExecute.
@Override
protected void doExecute() {
NullProviders service = get(NullProviders.class);
NetworkConfigService cfgService = get(NetworkConfigService.class);
TopologySimulator simulator = service.currentSimulator();
if (!validateSimulator(simulator)) {
return;
}
CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
List<ConnectPoint> points = findAvailablePorts(sim.deviceId(deviceName));
String pattern = hostIpPattern.replace("*", "%d");
double yStep = rowGap / hostsPerRow;
double y = gridY;
double x = gridX - (colGap * (hostsPerRow - 1)) / 2;
for (int h = 0; h < hostCount; h++) {
HostLocation location = new HostLocation(points.get(h), System.currentTimeMillis());
IpAddress ip = IpAddress.valueOf(String.format(pattern, h));
HostId id = sim.nextHostId();
if (gridY != NONE) {
BasicHostConfig cfg = cfgService.addConfig(id, BasicHostConfig.class);
setUiCoordinates(cfg, GRID, y, x);
if (((h + 1) % hostsPerRow) == 0) {
x = gridX - (colGap * (hostsPerRow - 1)) / 2;
} else {
x += colGap;
y += yStep;
}
}
Tools.delay(10);
sim.createHost(id, location, ip);
}
}
use of org.onosproject.net.config.basics.BasicHostConfig in project onos by opennetworkinglab.
the class CreateNullHost method doExecute.
@Override
protected void doExecute() {
NullProviders service = get(NullProviders.class);
NetworkConfigService cfgService = get(NetworkConfigService.class);
TopologySimulator simulator = service.currentSimulator();
if (!validateSimulator(simulator) || !validateLocType(locType)) {
return;
}
CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
HostId id = sim.nextHostId();
Set<HostLocation> locations;
try {
locations = getLocations(sim, deviceNames);
} catch (NoLocationException e) {
error("\u001B[1;31mHost not created - no location (free port) available on %s\u001B[0m", e.getMessage());
return;
}
Set<IpAddress> ips = getIps(hostIps);
BasicHostConfig cfg = cfgService.addConfig(id, BasicHostConfig.class);
setUiCoordinates(cfg, locType, latOrY, longOrX);
Tools.delay(10);
sim.createHost(id, locations, ips);
}
use of org.onosproject.net.config.basics.BasicHostConfig in project onos by opennetworkinglab.
the class TopologyViewMessageHandlerBase method hostMessage.
// Produces a host event message to the client.
protected ObjectNode hostMessage(HostEvent event) {
Host host = event.subject();
Host prevHost = event.prevSubject();
String hostType = host.annotations().value(AnnotationKeys.UI_TYPE);
String connectionType = host.annotations().value(AnnotationKeys.CONNECTION_TYPE);
String ip = ip(host.ipAddresses());
ObjectNode payload = objectNode().put("id", host.id().toString()).put("type", isNullOrEmpty(hostType) ? "endstation" : hostType).put("connectionType", isNullOrEmpty(connectionType) ? "wired" : connectionType);
// set most recent connect point (and previous if we know it)
payload.set("cp", hostConnect(host.location()));
if (prevHost != null && prevHost.location() != null) {
payload.set("prevCp", hostConnect(prevHost.location()));
}
// set ALL connect points
addAllCps(host.locations(), payload);
payload.set("labels", labels(nameForHost(host), ip, host.mac().toString(), ""));
payload.set("props", props(host.annotations()));
BasicHostConfig cfg = get(NetworkConfigService.class).getConfig(host.id(), BasicHostConfig.class);
if (!addLocation(cfg, payload)) {
addMetaUi(host.id().toString(), payload);
}
String type = HOST_EVENT.get(event.type());
return JsonUtils.envelope(type, payload);
}
Aggregations