From 643ee33289bd2cb9e6afbfb09b4ed72d467ba1c2 Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Tue, 3 Nov 2015 14:08:10 -0800 Subject: This updates ONOS src tree to commit id 03fa5e571cabbd001ddb1598847e1150b11c7333 Change-Id: I13b554026d6f902933e35887d29bd5fdb669c0bd Signed-off-by: Ashlee Young --- .../src/main/java/org/onlab/packet/Ethernet.java | 131 ++++++++++++++++++--- .../src/main/java/org/onlab/util/Bandwidth.java | 11 ++ .../src/main/java/org/onlab/util/DataRateUnit.java | 64 ++++++++++ .../org/onlab/util/AbstractAccumulatorTest.java | 27 +++-- .../org/onlab/util/ManuallyAdvancingTimer.java | 26 +++- .../org/onlab/util/ManuallyAdvancingTimerTest.java | 4 +- .../stc/src/main/java/org/onlab/stc/Main.java | 24 +++- 7 files changed, 248 insertions(+), 39 deletions(-) create mode 100644 framework/src/onos/utils/misc/src/main/java/org/onlab/util/DataRateUnit.java (limited to 'framework/src/onos/utils') diff --git a/framework/src/onos/utils/misc/src/main/java/org/onlab/packet/Ethernet.java b/framework/src/onos/utils/misc/src/main/java/org/onlab/packet/Ethernet.java index 003c1772..9ab5cab1 100644 --- a/framework/src/onos/utils/misc/src/main/java/org/onlab/packet/Ethernet.java +++ b/framework/src/onos/utils/misc/src/main/java/org/onlab/packet/Ethernet.java @@ -18,6 +18,12 @@ package org.onlab.packet; +import org.onlab.packet.ndp.NeighborAdvertisement; +import org.onlab.packet.ndp.NeighborSolicitation; +import org.onlab.packet.ndp.Redirect; +import org.onlab.packet.ndp.RouterAdvertisement; +import org.onlab.packet.ndp.RouterSolicitation; + import java.nio.ByteBuffer; import java.util.Arrays; import java.util.HashMap; @@ -531,27 +537,114 @@ public class Ethernet extends BasePacket { sb.append("\nnw_proto: "); sb.append(p.getProtocol()); - if (pkt instanceof TCP) { - sb.append("\ntp_src: "); - sb.append(((TCP) pkt).getSourcePort()); - sb.append("\ntp_dst: "); - sb.append(((TCP) pkt).getDestinationPort()); - - } else if (pkt instanceof UDP) { - sb.append("\ntp_src: "); - sb.append(((UDP) pkt).getSourcePort()); - sb.append("\ntp_dst: "); - sb.append(((UDP) pkt).getDestinationPort()); + IPacket payload = pkt.getPayload(); + if (payload != null) { + if (payload instanceof TCP) { + sb.append("\ntp_src: "); + sb.append(((TCP) payload).getSourcePort()); + sb.append("\ntp_dst: "); + sb.append(((TCP) payload).getDestinationPort()); + + } else if (payload instanceof UDP) { + sb.append("\ntp_src: "); + sb.append(((UDP) payload).getSourcePort()); + sb.append("\ntp_dst: "); + sb.append(((UDP) payload).getDestinationPort()); + } else if (payload instanceof ICMP) { + final ICMP icmp = (ICMP) payload; + sb.append("\nicmp_type: "); + sb.append(icmp.getIcmpType()); + sb.append("\nicmp_code: "); + sb.append(icmp.getIcmpCode()); + } } - - if (pkt instanceof ICMP) { - final ICMP icmp = (ICMP) pkt; - sb.append("\nicmp_type: "); - sb.append(icmp.getIcmpType()); - sb.append("\nicmp_code: "); - sb.append(icmp.getIcmpCode()); + } else if (pkt instanceof IPv6) { + final IPv6 ipv6 = (IPv6) pkt; + sb.append("\nipv6_src: "); + sb.append(Ip6Address.valueOf(ipv6.getSourceAddress()).toString()); + sb.append("\nipv6_dst: "); + sb.append(Ip6Address.valueOf(ipv6.getDestinationAddress()).toString()); + sb.append("\nipv6_proto: "); + sb.append(ipv6.getNextHeader()); + + IPacket payload = pkt.getPayload(); + if (payload != null && payload instanceof ICMP6) { + final ICMP6 icmp6 = (ICMP6) payload; + sb.append("\nicmp6_type: "); + sb.append(icmp6.getIcmpType()); + sb.append("\nicmp6_code: "); + sb.append(icmp6.getIcmpCode()); + + payload = payload.getPayload(); + if (payload != null) { + if (payload instanceof NeighborSolicitation) { + final NeighborSolicitation ns = (NeighborSolicitation) payload; + sb.append("\nns_target_addr: "); + sb.append(Ip6Address.valueOf(ns.getTargetAddress()).toString()); + ns.getOptions().forEach(option -> { + sb.append("\noption_type: "); + sb.append(option.type()); + sb.append("\noption_data: "); + sb.append(bytesToHex(option.data())); + }); + } else if (payload instanceof NeighborAdvertisement) { + final NeighborAdvertisement na = (NeighborAdvertisement) payload; + sb.append("\nna_target_addr: "); + sb.append(Ip6Address.valueOf(na.getTargetAddress()).toString()); + sb.append("\nna_solicited_flag: "); + sb.append(na.getSolicitedFlag()); + sb.append("\nna_router_flag: "); + sb.append(na.getRouterFlag()); + sb.append("\nna_override_flag: "); + sb.append(na.getOverrideFlag()); + na.getOptions().forEach(option -> { + sb.append("\noption_type: "); + sb.append(option.type()); + sb.append("\noption_data: "); + sb.append(bytesToHex(option.data())); + }); + } else if (payload instanceof RouterSolicitation) { + final RouterSolicitation rs = (RouterSolicitation) payload; + sb.append("\nrs"); + rs.getOptions().forEach(option -> { + sb.append("\noption_type: "); + sb.append(option.type()); + sb.append("\noption_data: "); + sb.append(bytesToHex(option.data())); + }); + } else if (payload instanceof RouterAdvertisement) { + final RouterAdvertisement ra = (RouterAdvertisement) payload; + sb.append("\nra_hop_limit: "); + sb.append(ra.getCurrentHopLimit()); + sb.append("\nra_mflag: "); + sb.append(ra.getMFlag()); + sb.append("\nra_oflag: "); + sb.append(ra.getOFlag()); + sb.append("\nra_reachable_time: "); + sb.append(ra.getReachableTime()); + sb.append("\nra_retransmit_time: "); + sb.append(ra.getRetransmitTimer()); + sb.append("\nra_router_lifetime: "); + sb.append(ra.getRouterLifetime()); + ra.getOptions().forEach(option -> { + sb.append("\noption_type: "); + sb.append(option.type()); + sb.append("\noption_data: "); + sb.append(bytesToHex(option.data())); + }); + } else if (payload instanceof Redirect) { + final Redirect rd = (Redirect) payload; + sb.append("\nrd_target_addr: "); + sb.append(Ip6Address.valueOf(rd.getTargetAddress()).toString()); + rd.getOptions().forEach(option -> { + sb.append("\noption_type: "); + sb.append(option.type()); + sb.append("\noption_data: "); + sb.append(bytesToHex(option.data())); + }); + } + } } - } else if (pkt instanceof DHCP) { sb.append("\ndhcp packet"); } else if (pkt instanceof Data) { diff --git a/framework/src/onos/utils/misc/src/main/java/org/onlab/util/Bandwidth.java b/framework/src/onos/utils/misc/src/main/java/org/onlab/util/Bandwidth.java index 349e660f..60806568 100644 --- a/framework/src/onos/utils/misc/src/main/java/org/onlab/util/Bandwidth.java +++ b/framework/src/onos/utils/misc/src/main/java/org/onlab/util/Bandwidth.java @@ -41,6 +41,17 @@ public final class Bandwidth implements RichComparable { this.bps = 0; } + /** + * Creates a new instance with given bandwidth. + * + * @param v bandwidth value + * @param unit {@link DataRateUnit} of {@code v} + * @return {@link Bandwidth} instance with given bandwidth + */ + public static Bandwidth of(double v, DataRateUnit unit) { + return new Bandwidth(unit.toBitsPerSecond(v)); + } + /** * Creates a new instance with given bandwidth in bps. * diff --git a/framework/src/onos/utils/misc/src/main/java/org/onlab/util/DataRateUnit.java b/framework/src/onos/utils/misc/src/main/java/org/onlab/util/DataRateUnit.java new file mode 100644 index 00000000..d49ed7b5 --- /dev/null +++ b/framework/src/onos/utils/misc/src/main/java/org/onlab/util/DataRateUnit.java @@ -0,0 +1,64 @@ +package org.onlab.util; + +import com.google.common.annotations.Beta; + +/** + * Data rate unit. + */ +@Beta +public enum DataRateUnit { + /** + * Bit per second. + */ + BPS(1L), + /** + * Kilobit per second. + * (Decimal/SI) + */ + KBPS(1_000L), + /** + * Megabit per second. + * (Decimal/SI) + */ + MBPS(1_000_000L), + /** + * Gigabit per second. + * (Decimal/SI) + */ + GBPS(1_000_000_000L); + + private final long multiplier; + + DataRateUnit(long multiplier) { + this.multiplier = multiplier; + } + + /** + * Returns the multiplier to use, when converting value of this unit to bps. + * + * @return multiplier + */ + public long multiplier() { + return multiplier; + } + + /** + * Converts given value in this unit to bits per seconds. + * + * @param v data rate value + * @return {@code v} in bits per seconds + */ + public long toBitsPerSecond(long v) { + return v * multiplier; + } + + /** + * Converts given value in this unit to bits per seconds. + * + * @param v data rate value + * @return {@code v} in bits per seconds + */ + public double toBitsPerSecond(double v) { + return v * multiplier; + } +} diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/util/AbstractAccumulatorTest.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/util/AbstractAccumulatorTest.java index db7224ad..8a409c3d 100644 --- a/framework/src/onos/utils/misc/src/test/java/org/onlab/util/AbstractAccumulatorTest.java +++ b/framework/src/onos/utils/misc/src/test/java/org/onlab/util/AbstractAccumulatorTest.java @@ -31,7 +31,10 @@ import static org.onlab.junit.TestTools.assertAfter; public class AbstractAccumulatorTest { - private final ManuallyAdvancingTimer timer = new ManuallyAdvancingTimer(); + private final ManuallyAdvancingTimer timer = new ManuallyAdvancingTimer(true); + + private static final int LONG_REAL_TIME_DELAY = 30; + private static final int SHORT_REAL_TIME_DELAY = 5; @Test @@ -52,7 +55,7 @@ public class AbstractAccumulatorTest { accumulator.add(new TestItem("d")); assertTrue("should not have fired yet", accumulator.batch.isEmpty()); accumulator.add(new TestItem("e")); - timer.advanceTimeMillis(20, 10); + timer.advanceTimeMillis(20, LONG_REAL_TIME_DELAY); assertFalse("should have fired", accumulator.batch.isEmpty()); assertEquals("incorrect batch", "abcde", accumulator.batch); } @@ -61,16 +64,16 @@ public class AbstractAccumulatorTest { public void timeTrigger() { TestAccumulator accumulator = new TestAccumulator(); accumulator.add(new TestItem("a")); - timer.advanceTimeMillis(30, 1); + timer.advanceTimeMillis(30, SHORT_REAL_TIME_DELAY); assertTrue("should not have fired yet", accumulator.batch.isEmpty()); accumulator.add(new TestItem("b")); - timer.advanceTimeMillis(30, 1); + timer.advanceTimeMillis(30, SHORT_REAL_TIME_DELAY); assertTrue("should not have fired yet", accumulator.batch.isEmpty()); accumulator.add(new TestItem("c")); - timer.advanceTimeMillis(30, 1); + timer.advanceTimeMillis(30, SHORT_REAL_TIME_DELAY); assertTrue("should not have fired yet", accumulator.batch.isEmpty()); accumulator.add(new TestItem("d")); - timer.advanceTimeMillis(10, 10); + timer.advanceTimeMillis(10, LONG_REAL_TIME_DELAY); assertFalse("should have fired", accumulator.batch.isEmpty()); assertEquals("incorrect batch", "abcd", accumulator.batch); } @@ -81,7 +84,7 @@ public class AbstractAccumulatorTest { accumulator.add(new TestItem("a")); assertTrue("should not have fired yet", accumulator.batch.isEmpty()); accumulator.add(new TestItem("b")); - timer.advanceTimeMillis(70, 10); + timer.advanceTimeMillis(70, LONG_REAL_TIME_DELAY); assertFalse("should have fired", accumulator.batch.isEmpty()); assertEquals("incorrect batch", "ab", accumulator.batch); } @@ -93,10 +96,10 @@ public class AbstractAccumulatorTest { accumulator.add(new TestItem("a")); assertTrue("should not have fired yet", accumulator.batch.isEmpty()); accumulator.add(new TestItem("b")); - timer.advanceTimeMillis(80, 1); + timer.advanceTimeMillis(80, SHORT_REAL_TIME_DELAY); assertTrue("should not have fired yet", accumulator.batch.isEmpty()); accumulator.ready = true; - timer.advanceTimeMillis(80, 10); + timer.advanceTimeMillis(80, LONG_REAL_TIME_DELAY); assertFalse("should have fired", accumulator.batch.isEmpty()); assertEquals("incorrect batch", "ab", accumulator.batch); } @@ -105,12 +108,12 @@ public class AbstractAccumulatorTest { public void readyLongTrigger() { TestAccumulator accumulator = new TestAccumulator(); accumulator.ready = false; - timer.advanceTimeMillis(120, 1); + timer.advanceTimeMillis(120, SHORT_REAL_TIME_DELAY); assertTrue("should not have fired yet", accumulator.batch.isEmpty()); accumulator.add(new TestItem("a")); assertTrue("should not have fired yet", accumulator.batch.isEmpty()); accumulator.ready = true; - timer.advanceTimeMillis(120, 10); + timer.advanceTimeMillis(120, LONG_REAL_TIME_DELAY); assertFalse("should have fired", accumulator.batch.isEmpty()); assertEquals("incorrect batch", "a", accumulator.batch); } @@ -128,7 +131,7 @@ public class AbstractAccumulatorTest { assertTrue("should not have fired yet", accumulator.batch.isEmpty()); accumulator.ready = true; accumulator.add(new TestItem("g")); - timer.advanceTimeMillis(10, 10); + timer.advanceTimeMillis(10, LONG_REAL_TIME_DELAY); assertFalse("should have fired", accumulator.batch.isEmpty()); assertEquals("incorrect batch", "abcdefg", accumulator.batch); } diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimer.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimer.java index 4116cbef..8fb008e8 100644 --- a/framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimer.java +++ b/framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimer.java @@ -65,6 +65,14 @@ public class ManuallyAdvancingTimer extends java.util.Timer { /* Data structure for tracking tasks */ private final TaskQueue queue = new TaskQueue(); + /* Whether execution should execute on the executor thread or the calling thread. */ + private final boolean runLocally; + + public ManuallyAdvancingTimer(boolean runLocally) { + this.runLocally = runLocally; + } + + @Override public void schedule(TimerTask task, long delay) { if (!staticsPopulated) { @@ -165,14 +173,16 @@ public class ManuallyAdvancingTimer extends java.util.Timer { /** * Advances the virtual time a certain number of millis triggers execution delays a certain amount to - * allow time for execution. + * allow time for execution. If runLocally is true then all real time delays are ignored. * * @param virtualTimeAdvance the time to be advances in millis of simulated time. * @param realTimeDelay the time to delay in real time to allow for processing. */ public void advanceTimeMillis(long virtualTimeAdvance, int realTimeDelay) { timerKeeper.advanceTimeMillis(virtualTimeAdvance); - delay(realTimeDelay); + if (!runLocally) { + delay(realTimeDelay); + } } /** @@ -238,7 +248,11 @@ public class ManuallyAdvancingTimer extends java.util.Timer { e.printStackTrace(); return false; } - executorService.execute(task); + if (runLocally) { + task.run(); + } else { + executorService.execute(task); + } return true; } else { //Calculate next execution time, using absolute value of period @@ -253,7 +267,11 @@ public class ManuallyAdvancingTimer extends java.util.Timer { } //Schedule next execution queue.insertOrdered(task); - executorService.execute(task); + if (runLocally) { + task.run(); + } else { + executorService.execute(task); + } return true; } } diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimerTest.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimerTest.java index b8e1e85e..36b50e67 100644 --- a/framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimerTest.java +++ b/framework/src/onos/utils/misc/src/test/java/org/onlab/util/ManuallyAdvancingTimerTest.java @@ -47,14 +47,14 @@ public class ManuallyAdvancingTimerTest { private AtomicInteger tasksRunCount; // FIXME if this class fails first try increasing the real time delay to account for heavy system load. - private static final int REAL_TIME_DELAY = 1; + private static final int REAL_TIME_DELAY = 10; /** * Sets up the testing environment. */ @Before public void setup() { - timer = new ManuallyAdvancingTimer(); + timer = new ManuallyAdvancingTimer(true); idGenerator = new AtomicInteger(1); tasksRunCount = new AtomicInteger(0); taskList = Lists.newArrayList(); diff --git a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Main.java b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Main.java index bc10ec7a..ca04a7c2 100644 --- a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Main.java +++ b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Main.java @@ -16,13 +16,16 @@ package org.onlab.stc; import com.google.common.collect.ImmutableList; +import com.google.common.io.Files; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.util.log.Logger; import org.onlab.stc.Coordinator.Status; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @@ -64,10 +67,12 @@ public final class Main { private String runToPatterns = ""; private Coordinator coordinator; + private Compiler compiler; private Monitor monitor; private Listener delegate = new Listener(); private static boolean useColor = Objects.equals("true", System.getenv("stcColor")); + private static boolean dumpLogs = Objects.equals("true", System.getenv("stcDumpLogs")); // usage: stc [] [run] // usage: stc [] run [from ] [to ]] @@ -113,7 +118,7 @@ public final class Main { Scenario scenario = Scenario.loadScenario(new FileInputStream(scenarioFile)); // Elaborate scenario - Compiler compiler = new Compiler(scenario); + compiler = new Compiler(scenario); compiler.compile(); // Setup the process flow coordinator @@ -221,7 +226,7 @@ public final class Main { /** * Internal delegate to monitor the process execution. */ - private static class Listener implements StepProcessListener { + private class Listener implements StepProcessListener { @Override public void onStart(Step step, String command) { logStatus(currentTimeMillis(), step.name(), IN_PROGRESS, command); @@ -230,6 +235,9 @@ public final class Main { @Override public void onCompletion(Step step, Status status) { logStatus(currentTimeMillis(), step.name(), status, null); + if (dumpLogs && !(step instanceof Group) && status == FAILED) { + dumpLogs(step); + } } @Override @@ -246,6 +254,18 @@ public final class Main { } } + // Dumps the step logs to standard output. + private void dumpLogs(Step step) { + File logFile = new File(compiler.logDir(), step.name() + ".log"); + try { + print(">>>>>"); + Files.copy(logFile, System.out); + print("<<<<<"); + } catch (IOException e) { + print("Unable to dump log file %s", logFile.getName()); + } + } + // Produces a description of event using the specified step status. private static String action(Status status) { return status == IN_PROGRESS ? "started" : -- cgit 1.2.3-korg