Thomas Vachuska
Committed by Gerrit Code Review

Fixed the null-provider packet rate default value and ability to dynamically adjust the value.

Change-Id: Ifc86ff9a184f2b453038667ed32c944841ed7af6
......@@ -40,6 +40,7 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.google.common.collect.ImmutableList.copyOf;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.onosproject.net.MastershipRole.MASTER;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -99,7 +100,11 @@ class NullPacketProvider extends NullProviders.AbstractNullProvider
* @param packetRate new packet rate
*/
void adjustRate(int packetRate) {
delay = 1000 / packetRate;
boolean needsRestart = delay == 0 && packetRate > 0;
delay = packetRate > 0 ? 1000 / packetRate : 0;
if (needsRestart) {
timeout = timer.newTimeout(new PacketDriverTask(), 1, MILLISECONDS);
}
log.info("Settings: packetRate={}, delay={}", packetRate, delay);
}
......@@ -126,7 +131,7 @@ class NullPacketProvider extends NullProviders.AbstractNullProvider
ICMP icmp;
Ethernet eth;
public PacketDriverTask() {
PacketDriverTask() {
icmp = new ICMP();
icmp.setIcmpType((byte) 8).setIcmpCode((byte) 0).setChecksum((short) 0);
eth = new Ethernet();
......@@ -136,7 +141,7 @@ class NullPacketProvider extends NullProviders.AbstractNullProvider
@Override
public void run(Timeout to) {
if (!devices.isEmpty() && !to.isCancelled()) {
if (!devices.isEmpty() && !to.isCancelled() && delay > 0) {
sendEvent(devices.get(Math.min(currentDevice, devices.size() - 1)));
currentDevice = (currentDevice + 1) % devices.size();
timeout = timer.newTimeout(to.getTask(), delay, TimeUnit.MILLISECONDS);
......@@ -145,8 +150,8 @@ class NullPacketProvider extends NullProviders.AbstractNullProvider
private void sendEvent(Device device) {
// Make it look like things came from ports attached to hosts
eth.setSourceMACAddress("00:00:10:00:00:0" + SRC_HOST)
.setDestinationMACAddress("00:00:10:00:00:0" + DST_HOST);
eth.setSourceMACAddress("00:00:00:10:00:0" + SRC_HOST)
.setDestinationMACAddress("00:00:00:10:00:0" + DST_HOST);
InboundPacket inPkt = new DefaultInboundPacket(
new ConnectPoint(device.id(), PortNumber.portNumber(SRC_HOST)),
eth, ByteBuffer.wrap(eth.serialize()));
......
......@@ -152,7 +152,7 @@ public class NullProviders {
label = "Number of host to generate per device")
private int hostCount = DEFAULT_HOST_COUNT;
private static final int DEFAULT_PACKET_RATE = 5;
private static final int DEFAULT_PACKET_RATE = 0;
@Property(name = "packetRate", intValue = DEFAULT_PACKET_RATE,
label = "Packet-in/s rate; 0 for no packets")
private int packetRate = DEFAULT_PACKET_RATE;
......