use of org.openkilda.testing.service.traffexam.model.ConsumerEndpoint in project open-kilda by telstra.
the class TraffExamServiceImpl method startExam.
@Override
public synchronized ExamResources startExam(Exam exam) throws NoResultsFoundException, OperationalException {
checkHostPresence(exam.getSource());
checkHostPresence(exam.getDest());
Inet4Network subnet;
try {
subnet = addressPool.allocate();
} catch (Inet4ValueException e) {
throw new OperationalException("Unable to allocate subnet for exam. There is no more addresses available.");
}
ExamResources resources = null;
List<HostResource> supplied = new ArrayList<>(4);
try {
Address sourceAddress = new Address(subnet.address(1), subnet.getPrefix(), exam.getSourceVlans());
sourceAddress = assignAddress(exam.getSource(), sourceAddress);
supplied.add(sourceAddress);
Address destAddress = new Address(subnet.address(2), subnet.getPrefix(), exam.getDestVlans());
destAddress = assignAddress(exam.getDest(), destAddress);
supplied.add(destAddress);
ConsumerEndpoint consumer = assignEndpoint(exam.getDest(), new ConsumerEndpoint(destAddress.getId()));
supplied.add(consumer);
ProducerEndpoint producer = new ProducerEndpoint(sourceAddress.getId(), new EndpointAddress(destAddress.getAddress(), consumer.getBindPort()));
if (exam.getBandwidthLimit() != null) {
producer.setBandwidth(exam.getBandwidthLimit());
producer.setBurstPkt(exam.getBurstPkt());
}
if (exam.getTimeLimitSeconds() != null) {
producer.setTime(exam.getTimeLimitSeconds());
}
producer.setUseUdp(exam.isUdp());
producer.setBufferLength(exam.getBufferLength());
try {
// give consumer some time to fully roll. Probably should be fixed on service's side, this is workaround
TimeUnit.MILLISECONDS.sleep(300);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
producer = assignEndpoint(exam.getSource(), producer);
supplied.add(producer);
resources = new ExamResources(subnet, producer, consumer);
} catch (Inet4ValueException e) {
throw new OperationalException("Insufficient resources - not enough IP address in subnet. Check addressPool configuration.");
} finally {
if (resources == null) {
extendFailedToRelease(releaseResources(supplied));
try {
addressPool.free(subnet);
} catch (Inet4ValueException e) {
// Unreachable point, free throw exception only if invalid (not allocated before) address passed
}
}
}
return resources;
}
Aggregations