<groupId>org.opendaylight.controller.model</groupId>
<artifactId>model-inventory</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.openflowjava</groupId>
+ <artifactId>util</artifactId>
+ </dependency>
</dependencies>
<build>
*/
package org.opendaylight.openflowplugin.testcommon;
+import static org.opendaylight.openflowjava.util.ByteBufUtils.macAddressToString;
+
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
-
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
abstract class AbstractDropTest implements PacketProcessingListener, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(AbstractDropTest.class);
- private static final AtomicIntegerFieldUpdater<AbstractDropTest> SENT_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "_sent");
- private volatile int _sent;
+ protected static final Integer PRIORITY = 4;
+ protected static final Long BUFFER_ID = 0L;
+ protected static final Integer HARD_TIMEOUT = 300;
+ protected static final Integer IDLE_TIMEOUT = 240;
+ protected static final short TABLE_ID = 0;
+
+ private static final AtomicIntegerFieldUpdater<AbstractDropTest> SENT_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "sent");
+ private volatile int sent;
- private static final AtomicIntegerFieldUpdater<AbstractDropTest> RCVD_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "_rcvd");
- private volatile int _rcvd;
+ private static final AtomicIntegerFieldUpdater<AbstractDropTest> RCVD_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "rcvd");
+ private volatile int rcvd;
- private static final AtomicIntegerFieldUpdater<AbstractDropTest> EXCS_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "_excs");
- private volatile int _excs;
+ private static final AtomicIntegerFieldUpdater<AbstractDropTest> EXCS_UPDATER = AtomicIntegerFieldUpdater.newUpdater(AbstractDropTest.class, "excs");
+ private volatile int excs;
public final DropTestStats getStats() {
- return new DropTestStats(this._sent, this._rcvd, this._excs);
+ return new DropTestStats(this.sent, this.rcvd, this.excs);
}
public final void clearStats(){
- this._sent = 0;
- this._rcvd = 0;
- this._excs = 0;
+ this.sent = 0;
+ this.rcvd = 0;
+ this.excs = 0;
}
@Override
try {
final byte[] rawPacket = notification.getPayload();
-
- // LOG.debug("onPacketReceived - received Packet on Node {} and NodeConnector {} payload {}",
- // nodeKey.getId(), ncKey.getId(), Hex.encodeHexString(rawPacket));
-
final byte[] srcMac = Arrays.copyOfRange(rawPacket, 6, 12);
- //LOG.debug("onPacketReceived - received Packet on Node {} and NodeConnector {} srcMac {}",
- // nodeKey.getId(), ncKey.getId(), Hex.encodeHexString(srcMac));
-
final MatchBuilder match = new MatchBuilder();
final EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
final EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
//TODO: use HEX, use binary form
//Hex.decodeHex("000000000001".toCharArray());
- ethSourceBuilder.setAddress(new MacAddress(DropTestUtils.macToString(srcMac)));
+ ethSourceBuilder.setAddress(new MacAddress(macAddressToString(srcMac)));
ethernetMatch.setEthernetSource(ethSourceBuilder.build());
match.setEthernetMatch(ethernetMatch.build());
import java.math.BigInteger;
import java.util.concurrent.atomic.AtomicLong;
-
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.slf4j.LoggerFactory;
/**
- * provides cbench responder behavior: upon packetIn arrival addFlow action is sent out to
+ * provides cbench responder behavior: upon packetIn arrival addFlow action is sent out to
* device using dataStore strategy (FRM involved)
*/
public class DropTestCommiter extends AbstractDropTest {
- private final static Logger LOG = LoggerFactory.getLogger(DropTestCommiter.class);
-
+ private static final Logger LOG = LoggerFactory.getLogger(DropTestCommiter.class);
+
private DataBroker dataService;
-
- private static final AtomicLong idCounter = new AtomicLong();
+
+ private static final AtomicLong ID_COUNTER = new AtomicLong();
private static final ThreadLocal<FlowBuilder> BUILDER = new ThreadLocal<FlowBuilder>() {
@Override
protected FlowBuilder initialValue() {
final FlowBuilder fb = new FlowBuilder();
- fb.setPriority(4);
- fb.setBufferId(0L);
+ fb.setPriority(PRIORITY);
+ fb.setBufferId(BUFFER_ID);
final FlowCookie cookie = new FlowCookie(BigInteger.TEN);
fb.setCookie(cookie);
fb.setCookieMask(cookie);
- fb.setTableId((short) 0);
- fb.setHardTimeout(300);
- fb.setIdleTimeout(240);
+ fb.setTableId(TABLE_ID);
+ fb.setHardTimeout(HARD_TIMEOUT);
+ fb.setIdleTimeout(IDLE_TIMEOUT);
fb.setFlags(new FlowModFlags(false, false, false, false, false));
return fb;
}
private NotificationProviderService notificationService;
private ListenerRegistration<NotificationListener> notificationRegistration;
-
+
/**
* start listening on packetIn
*/
public void start() {
notificationRegistration = notificationService.registerNotificationListener(this);
}
-
+
/**
* @param dataService the dataService to set
*/
final FlowBuilder fb = BUILDER.get();
fb.setMatch(match);
fb.setInstructions(instructions);
- fb.setId(new FlowId(String.valueOf(fb.hashCode()) +"."+ String.valueOf(idCounter.getAndIncrement())));
-
+ fb.setId(new FlowId(String.valueOf(fb.hashCode()) +"."+ ID_COUNTER.getAndIncrement()));
+
// Construct the flow instance id
final InstanceIdentifier<Flow> flowInstanceId =
- InstanceIdentifier.builder(Nodes.class) // File under nodes
- .child(Node.class, node) // A particular node identified by nodeKey
- .augmentation(FlowCapableNode.class) // That is flow capable, only FlowCapableNodes have tables
- .child(Table.class, new TableKey((short) 0)) // In the table identified by TableKey
- .child(Flow.class, new FlowKey(fb.getId())) // A flow identified by flowKey
+ // File under nodes
+ InstanceIdentifier.builder(Nodes.class)
+ // A particular node identified by nodeKey
+ .child(Node.class, node)
+ // That is flow capable, only FlowCapableNodes have tables
+ .augmentation(FlowCapableNode.class)
+ // In the table identified by TableKey
+ .child(Table.class, new TableKey((short) 0))
+ // A flow identified by flowKey
+ .child(Flow.class, new FlowKey(fb.getId()))
.build();
final Flow flow = fb.build();
transaction.submit();
LOG.debug("onPacketReceived - About to write flow commited");
}
-
+
@Override
public void close() {
try {
* provides activation and deactivation of drop responder service - responds on packetIn
*/
public class DropTestDsProvider implements AutoCloseable {
- private final static Logger LOG = LoggerFactory.getLogger(DropTestDsProvider.class);
+ private static final Logger LOG = LoggerFactory.getLogger(DropTestDsProvider.class);
private DataBroker dataService;
private NotificationProviderService notificationService;
active = false;
}
}
-
+
/**
* @return the active
*/
* provides activation and deactivation of drop responder service - responds on packetIn
*/
public class DropTestRpcProvider implements AutoCloseable {
- private final static Logger LOG = LoggerFactory.getLogger(DropTestDsProvider.class);
+ private static final Logger LOG = LoggerFactory.getLogger(DropTestDsProvider.class);
private SalFlowService flowService;
private NotificationProviderService notificationService;
active = false;
}
}
-
+
/**
* @return the active
*/
*/
package org.opendaylight.openflowplugin.testcommon;
-import java.math.BigInteger;
+import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.BUFFER_ID;
+import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.HARD_TIMEOUT;
+import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.IDLE_TIMEOUT;
+import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.PRIORITY;
+import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.TABLE_ID;
+import java.math.BigInteger;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
import org.slf4j.LoggerFactory;
/**
- * provides cbench responder behavior: upon packetIn arrival addFlow action is sent out to
+ * provides cbench responder behavior: upon packetIn arrival addFlow action is sent out to
* device using {@link SalFlowService} strategy
*/
public class DropTestRpcSender extends AbstractDropTest {
- private final static Logger LOG = LoggerFactory.getLogger(DropTestRpcSender.class);
+ private static final Logger LOG = LoggerFactory.getLogger(DropTestRpcSender.class);
private SalFlowService flowService;
-
+
/**
* @param flowService the flowService to set
*/
protected AddFlowInputBuilder initialValue() {
final AddFlowInputBuilder fb = new AddFlowInputBuilder();
- fb.setPriority(4);
- fb.setBufferId(0L);
+ fb.setPriority(PRIORITY);
+ fb.setBufferId(BUFFER_ID);
final FlowCookie cookie = new FlowCookie(BigInteger.TEN);
fb.setCookie(cookie);
fb.setCookieMask(cookie);
- fb.setTableId((short) 0);
- fb.setHardTimeout(300);
- fb.setIdleTimeout(240);
+ fb.setTableId(TABLE_ID);
+ fb.setHardTimeout(HARD_TIMEOUT);
+ fb.setIdleTimeout(IDLE_TIMEOUT);
fb.setFlags(new FlowModFlags(false, false, false, false, false));
return fb;
private NotificationProviderService notificationService;
private ListenerRegistration<NotificationListener> notificationRegistration;
-
+
/**
* start listening on packetIn
*/
// Construct the flow instance id
final InstanceIdentifier<Node> flowInstanceId = InstanceIdentifier
- .builder(Nodes.class) // File under nodes
- .child(Node.class, node).build(); // A particular node identified by nodeKey
+ // File under nodes
+ .builder(Nodes.class)
+ // A particular node identified by nodeKey
+ .child(Node.class, node).build();
fb.setNode(new NodeRef(flowInstanceId));
// Add flow
public void setNotificationService(NotificationProviderService notificationService) {
this.notificationService = notificationService;
}
-
+
@Override
public void close() {
try {
package org.opendaylight.openflowplugin.testcommon;
public class DropTestStats {
- private final int _rcvd;
- private final int _sent;
- private final int _excs;
- private final String _message;
-
- public DropTestStats(int sent, int rcvd) {
- this._sent = sent;
- this._rcvd = rcvd;
- this._excs = 0;
- this._message = null;
- }
-
- public DropTestStats(int sent, int rcvd, int excs) {
- this._sent = sent;
- this._rcvd = rcvd;
- this._excs = excs;
- this._message = null;
- }
-
- public DropTestStats(String message) {
- this._sent = -1;
- this._rcvd = -1;
- this._excs = -1;
- this._message = message;
- }
-
- public int getSent() { return this._sent; }
- public int getRcvd() { return this._rcvd; }
- public String getMessage() { return this._message; };
-
- @Override
- public String toString() {
- StringBuilder result = new StringBuilder();
- if (this._message == null) {
- result.append("Rcvd: " + this._rcvd);
- result.append(", Sent: " + this._sent);
- result.append("; Exceptions: " + this._excs);
- } else {
- result.append(this._message);
- }
-
- return result.toString();
- }
-
+ private final int rcvd;
+ private final int sent;
+ private final int excs;
+ private final String message;
+
+ public DropTestStats(int sent, int rcvd) {
+ this.sent = sent;
+ this.rcvd = rcvd;
+ this.excs = 0;
+ this.message = null;
+ }
+
+ public DropTestStats(int sent, int rcvd, int excs) {
+ this.sent = sent;
+ this.rcvd = rcvd;
+ this.excs = excs;
+ this.message = null;
+ }
+
+ public DropTestStats(String message) {
+ this.sent = -1;
+ this.rcvd = -1;
+ this.excs = -1;
+ this.message = message;
+ }
+
+ public int getSent() { return this.sent; }
+ public int getRcvd() { return this.rcvd; }
+ public String getMessage() { return this.message; }
+
+ @Override
+ public String toString() {
+ StringBuilder result = new StringBuilder();
+ if (this.message == null) {
+ result.append("Rcvd: ");
+ result.append(this.rcvd);
+ result.append(", Sent: ");
+ result.append(this.sent);
+ result.append("; Exceptions: ");
+ result.append(this.excs);
+ } else {
+ result.append(this.message);
+ }
+
+ return result.toString();
+ }
+
}
+++ /dev/null
-/**
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowplugin.testcommon;
-
-import com.google.common.base.Preconditions;
-import com.google.common.primitives.UnsignedBytes;
-
-public class DropTestUtils {
- private static final char[] HEX = "0123456789ABCDEF".toCharArray();
-
- private static final void appendByte(final StringBuilder sb, final byte b) {
- int v = UnsignedBytes.toInt(b);
- sb.append(HEX[v >>> 4]);
- sb.append(HEX[v & 15]);
- }
-
- public static String macToString(final byte[] mac) {
- Preconditions.checkArgument(mac.length == 6);
-
- final StringBuilder sb = new StringBuilder(17);
- appendByte(sb, mac[0]);
-
- for (int i = 1; i < mac.length; i++) {
- sb.append(':');
- appendByte(sb, mac[i]);
- }
-
- return sb.toString();
- }
-}