use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.
the class CreateNullHost method getLocations.
private Set<HostLocation> getLocations(CustomTopologySimulator sim, String deviceNames) throws NoLocationException {
ImmutableSet.Builder<HostLocation> locations = ImmutableSet.builder();
String[] csv = deviceNames.split(",");
for (String s : csv) {
HostLocation loc = findAvailablePort(sim.deviceId(s));
if (loc == null) {
throw new NoLocationException(deviceNames);
}
locations.add(requireNonNull(findAvailablePort(sim.deviceId(s))));
}
return locations.build();
}
use of org.onosproject.net.HostLocation 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.HostLocation 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.HostLocation 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.HostLocation in project onos by opennetworkinglab.
the class DefaultHostProbingProvider method processEvent.
@Override
public void processEvent(HostProbingEvent event) {
probeEventHandler.execute(() -> {
log.debug("Receiving HostProbingEvent {}", event);
HostProbe hostProbe = event.subject();
switch(event.type()) {
case PROBE_REQUESTED:
// Do nothing
break;
case PROBE_TIMEOUT:
// Retry probe until PROBE_FAIL
// TODO Only retry DISCOVER probes
probeHostInternal(hostProbe, hostProbe.connectPoint(), hostProbe.mode(), hostProbe.probeMac(), hostProbe.retry());
break;
case PROBE_FAIL:
// Remove this location if this is a verify probe.
if (hostProbe.mode() == ProbeMode.VERIFY) {
ConnectPoint oldConnectPoint = hostProbe.connectPoint();
if (!oldConnectPoint.port().hasName()) {
oldConnectPoint = translateSwitchPort(oldConnectPoint);
}
providerService.removeLocationFromHost(hostProbe.id(), new HostLocation(oldConnectPoint, 0L));
}
break;
case PROBE_COMPLETED:
// Add this location if this is a discover probe.
if (hostProbe.mode() == ProbeMode.DISCOVER) {
ConnectPoint newConnectPoint = hostProbe.connectPoint();
if (!newConnectPoint.port().hasName()) {
newConnectPoint = translateSwitchPort(newConnectPoint);
}
providerService.addLocationToHost(hostProbe.id(), new HostLocation(newConnectPoint, System.currentTimeMillis()));
}
break;
default:
log.warn("Unknown HostProbingEvent type: {}", event.type());
}
});
}
Aggregations