+++ /dev/null
-Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-University
-
-We are making the OpenFlow specification and associated documentation
-(Software) available for public use and benefit with the expectation that
-others will use, modify and enhance the Software and contribute those
-enhancements back to the community. However, since we would like to make the
-Software available for broadest use, with as few restrictions as possible
-permission is hereby granted, free of charge, to any person obtaining a copy of
-this Software to deal in the Software under the copyrights without restriction,
-including without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to permit
-persons to whom the Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-
-The name and trademarks of copyright holder(s) may NOT be used in advertising
-or publicity pertaining to the Software or any derivatives without specific,
-written prior permission.
+++ /dev/null
-# `make` commands
-all:
- ant
-
-run:
- ant run
-
-doc:
- ant javadoc
-
-tests:
- ant tests
-
-count:
- @find . -name \*.java | xargs wc -l | sort -n
-
-clean:
- ant clean
-OpenFlow Java - v1.3
+openflow-codec has been moved to the openflowjava project as
+of Aug 30, 2013:
-A Java implementation of low-level OpenFlow packet marshalling/unmarshalling
-and IO operations. Implements v1.3 of the OpenFlow specification at
-http://www.openflow.org.
+https://git.opendaylight.org/gerrit/#/c/1047/
- - Yugandhar Sarraju (ysarraju@in.ibm.com)
- - Anil Gujele (angujele@in.ibm.com)
+You can include it in your maven project with:
-Building requires Maven 2.x+ (http://maven.apache.org/).
+<repositories>
+ <!-- OpenDayLight Released artifact -->
+ <repository>
+ <id>opendaylight-release</id>
+ <name>opendaylight-release</name>
+ <url>${nexusproxy}/repositories/opendaylight.release/</url>
+ </repository>
+ <!-- OpenDayLight Snapshot artifact -->
+ <repository>
+ <id>opendaylight-snapshot</id>
+ <name>opendaylight-snapshot</name>
+ <url>${nexusproxy}/repositories/opendaylight.snapshot/</url>
+ </repository>
+</repositories>
-To build:
- mvn package
-
-To build javadocs:
- mvn javadoc:javadoc
+<dependency>
+ <groupId>org.opendaylight.openflowjava.thirdparty</groupId>
+ <artifactId>org.openflow.codec</artifactId>
+ <version>1.0.2-SNAPSHOT</version>
+</dependency>
+++ /dev/null
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.opendaylight.openflowplugin</groupId>
- <artifactId>commons.openflowplugin</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <relativePath>../commons</relativePath>
- </parent>
-
- <!-- <groupId>org.opendaylight.controller.thirdparty</groupId> -->
- <artifactId>org.openflow.codec</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>bundle</packaging>
- <name>OpenFlow 1.3 Protocol Driver</name>
- <description>A Java implementation of the OpenFlow v1.3 protocol driver</description>
-
- <!-- Get some common settings for the project we are using it in -->
-
- <developers>
- <developer>
- <name>David Erickson</name>
- <email>daviderickson@cs.stanford.edu</email>
- </developer>
- <developer>
- <name>Rob Sherwood</name>
- <email>rob.sherwood@stanford.edu</email>
- </developer>
- <developer>
- <name>Yugandhar Sarraju</name>
- <email>ysarraju@in.ibm.com</email>
- </developer>
- <developer>
- <name>Anil Gujele</name>
- <email>angujele@in.ibm.com</email>
- </developer>
- <developer>
- <name>Anil Vishnoi</name>
- <email>avishnoi@in.ibm.com</email>
- </developer>
- </developers>
- <!-- <url>http://www.openflow.org</url> <licenses> <license> <name>The OpenFlow
- License</name> <url>http://www.openflowswitch.org/wp/legal/</url> <distribution>repo</distribution>
- </license> </licenses> <scm> <connection>scm:git://gitosis.stanford.edu:openflowj.git</connection>
- <url>https://openflow.stanford.edu/fisheye/browse/OpenFlowJ</url> </scm> -->
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
- <!-- For GPG release signing, use mvn release:perform -->
- <profiles>
- <!-- <profile> <id>release-sign-artifacts</id> <activation> <property>
- <name>performRelease</name> <value>true</value> </property> </activation>
- <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-gpg-plugin</artifactId>
- <version>1.1</version> <executions> <execution> <id>sign-artifacts</id> <phase>verify</phase>
- <goals> <goal>sign</goal> </goals> </execution> </executions> <configuration>
- <mavenExecutorId>forked-path</mavenExecutorId> </configuration> </plugin>
- </plugins> </build> </profile> -->
- <profile>
- <id>jenkins</id>
- <activation>
- <property>
- <name>env.BUILD_NUMBER</name>
- </property>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>cobertura-maven-plugin</artifactId>
- <version>2.5.1</version>
- <configuration>
- <formats>
- <format>xml</format>
- </formats>
- </configuration>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>cobertura</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>2.3.6</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Export-Package>
- org.openflow.example;version="1.3.1";
- uses:="org.openflow.example.cli,
- org.openflow.protocol,
- org.openflow.io,
- org.openflow.protocol.factory",
- org.openflow.io;version="1.3.1";
- uses:="org.openflow.protocol,
- org.openflow.protocol.factory",
- org.openflow.protocol;version="1.3.1";
- uses:="org.openflow.protocol.statistics,
- org.openflow.protocol,
- org.openflow.protocol.factory",
- org.openflow.protocol.action;version="1.3.1";
- uses:="org.openflow.protocol",
- org.openflow.protocol.factory;version="1.3.1";
- uses:="org.openflow.protocol.statistics,
- org.openflow.protocol,
- org.openflow.protocol.action,
- org.openflow.protocol.queue",
- org.openflow.protocol.queue;version="1.3.1";
- uses:="org.openflow.protocol,
- org.openflow.protocol.factory",
- org.openflow.protocol.statistics;version="1.3.1";
- uses:="org.openflow.protocol,
- org.openflow.protocol.factory",
- org.openflow.util;version="1.3.1"
- </Export-Package>
- </instructions>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
+++ /dev/null
-/**
- *
- */
-package org.openflow.codec.example;
-
-import java.io.IOException;
-import java.nio.channels.SelectionKey;
-
-/**
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- *
- */
-public interface SelectListener {
- /**
- * Tell the select listener that an event took place on the passed object
- *
- * @param key
- * the key used on the select
- * @param arg
- * some parameter passed by the caller when registering
- * @throws IOException
- */
- void handleEvent(SelectionKey key, Object arg) throws IOException;
-}
+++ /dev/null
-package org.openflow.codec.example;
-
-import java.io.IOException;
-import java.nio.channels.CancelledKeyException;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.SelectableChannel;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.nio.channels.spi.SelectorProvider;
-import java.util.Iterator;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-/***
- * Dirt simple SelectLoop for simple java controller
- */
-
-public class SelectLoop {
- protected SelectListener callback;
- protected boolean dontStop;
- protected Object registrationLock;
- protected int registrationRequests = 0;
- protected Queue<Object[]> registrationQueue;
- protected Selector selector;
- protected long timeout;
-
- public SelectLoop(SelectListener cb) throws IOException {
- callback = cb;
- dontStop = true;
- selector = SelectorProvider.provider().openSelector();
- registrationLock = new Object();
- registrationQueue = new ConcurrentLinkedQueue<Object[]>();
- timeout = 0;
- }
-
- /**
- * Initializes this SelectLoop
- *
- * @param cb
- * the callback to call when select returns
- * @param timeout
- * the timeout value in milliseconds that select will be called
- * with
- * @throws IOException
- */
- public SelectLoop(SelectListener cb, long timeout) throws IOException {
- callback = cb;
- dontStop = true;
- selector = SelectorProvider.provider().openSelector();
- registrationLock = new Object();
- registrationQueue = new ConcurrentLinkedQueue<Object[]>();
- this.timeout = timeout;
- }
-
- public void register(SelectableChannel ch, int ops, Object arg) throws ClosedChannelException {
- registrationQueue.add(new Object[] { ch, ops, arg });
- }
-
- /**
- * Registers the supplied SelectableChannel with this SelectLoop. Note this
- * method blocks until registration proceeds. It is advised that SelectLoop
- * is intialized with a timeout value when using this method.
- *
- * @param ch
- * the channel
- * @param ops
- * interest ops
- * @param arg
- * argument that will be returned with the SelectListener
- * @return
- * @throws ClosedChannelException
- */
- public synchronized SelectionKey registerBlocking(SelectableChannel ch, int ops, Object arg)
- throws ClosedChannelException {
- synchronized (registrationLock) {
- registrationRequests++;
- }
- selector.wakeup();
- SelectionKey key = ch.register(selector, ops, arg);
- synchronized (registrationLock) {
- registrationRequests--;
- registrationLock.notifyAll();
- }
- return key;
- }
-
- /****
- * Main top-level IO loop this dispatches all IO events and timer events
- * together I believe this is fairly efficient
- */
- public void doLoop() throws IOException {
- int nEvents;
- processRegistrationQueue();
-
- while (dontStop) {
- nEvents = selector.select(timeout);
- if (nEvents > 0) {
- for (Iterator<SelectionKey> i = selector.selectedKeys().iterator(); i.hasNext();) {
- SelectionKey sk = i.next();
- i.remove();
-
- if (!sk.isValid())
- continue;
-
- Object arg = sk.attachment();
- callback.handleEvent(sk, arg);
- }
- }
-
- if (this.registrationQueue.size() > 0)
- processRegistrationQueue();
-
- if (registrationRequests > 0) {
- synchronized (registrationLock) {
- while (registrationRequests > 0) {
- try {
- registrationLock.wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- }
-
- protected void processRegistrationQueue() {
- // add any elements in queue
- for (Iterator<Object[]> it = registrationQueue.iterator(); it.hasNext();) {
- Object[] args = it.next();
- SelectableChannel ch = (SelectableChannel) args[0];
- try {
- ch.register(selector, (Integer) args[1], args[2]);
- } catch (CancelledKeyException cke) {
- continue;
- } catch (ClosedChannelException e) {
- }
- it.remove();
- }
- }
-
- /**
- * Force this select loop to return immediately and re-enter select, useful
- * for example if a new item has been added to the select loop while it was
- * already blocked.
- */
- public void wakeup() {
- if (selector != null) {
- selector.wakeup();
- }
- }
-
- /**
- * Shuts down this select loop, may return before it has fully shutdown
- */
- public void shutdown() {
- this.dontStop = false;
- wakeup();
- }
-}
+++ /dev/null
-/**
- *
- */
-package org.openflow.codec.example;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import org.openflow.codec.example.cli.Options;
-import org.openflow.codec.example.cli.ParseException;
-import org.openflow.codec.example.cli.SimpleCLI;
-import org.openflow.codec.io.OFMessageAsyncStream;
-import org.openflow.codec.protocol.OFPEchoReply;
-import org.openflow.codec.protocol.OFPFlowMod;
-import org.openflow.codec.protocol.OFPFlowModCommand;
-import org.openflow.codec.protocol.OFPMatch;
-import org.openflow.codec.protocol.OFPMessage;
-import org.openflow.codec.protocol.OFPPacketIn;
-import org.openflow.codec.protocol.OFPPacketOut;
-import org.openflow.codec.protocol.OFPPortNo;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.protocol.action.OFPAction;
-import org.openflow.codec.protocol.action.OFPActionOutput;
-import org.openflow.codec.protocol.factory.OFPBasicFactoryImpl;
-import org.openflow.codec.protocol.instruction.OFPInstruction;
-import org.openflow.codec.protocol.instruction.OFPInstructionActions;
-import org.openflow.codec.protocol.instruction.OFPInstructionApplyActions;
-import org.openflow.codec.util.LRULinkedHashMap;
-import org.openflow.codec.util.U16;
-
-/**
- * @author Rob Sherwood (rob.sherwood@stanford.edu), David Erickson
- * (daviderickson@cs.stanford.edu)
- *
- */
-public class SimpleController implements SelectListener {
- protected ExecutorService es;
- protected OFPBasicFactoryImpl factory;
- protected SelectLoop listenSelectLoop;
- protected ServerSocketChannel listenSock;
- protected List<SelectLoop> switchSelectLoops;
- protected Map<SocketChannel, OFSwitch> switchSockets;
- protected Integer threadCount;
- protected int port;
-
- protected class OFSwitch {
- protected SocketChannel sock;
- protected OFMessageAsyncStream stream;
- protected Map<Integer, Short> macTable = new LRULinkedHashMap<Integer, Short>(64001, 64000);
-
- public OFSwitch(SocketChannel sock, OFMessageAsyncStream stream) {
- this.sock = sock;
- this.stream = stream;
- }
-
- public void handlePacketIn(OFPPacketIn pi) {
- // Build the Match
- OFPMatch match = new OFPMatch();
- // match.loadFromPacket(pi.getPacketData(), pi.getInPort());
- // byte[] dlDst = match.getDataLayerDestination();
- // Integer dlDstKey = Arrays.hashCode(dlDst);
- // byte[] dlSrc = match.getDataLayerSource();
- // Integer dlSrcKey = Arrays.hashCode(dlSrc);
- int bufferId = pi.getBufferId();
-
- // if the src is not multicast, learn it
- // if ((dlSrc[0] & 0x1) == 0) {
- // if (!macTable.containsKey(dlSrcKey) ||
- // !macTable.get(dlSrcKey).equals(pi.getInPort())) {
- // macTable.put(dlSrcKey, pi.getInPort());
- // }
- // }
- //
- Short outPort = null;
- // // if the destination is not multicast, look it up
- // if ((dlDst[0] & 0x1) == 0) {
- // outPort = macTable.get(dlDstKey);
- // }
-
- // push a flow mod if we know where the packet should be going
- if (outPort != null) {
- OFPFlowMod fm = (OFPFlowMod) factory.getMessage(OFPType.FLOW_MOD);
- fm.setBufferId(bufferId);
- fm.setCommand(OFPFlowModCommand.OFPFC_ADD);
- fm.setCookie(0);
- fm.setFlags((short) 0);
- fm.setHardTimeout((short) 0);
- fm.setIdleTimeout((short) 5);
- // match.setInputPort(pi.getInPort());
- // match.setWildcards(0);
- fm.setMatch(match);
- fm.setOutPort(OFPPortNo.OFPP_ANY.getValue());
- fm.setPriority((short) 0);
- OFPActionOutput action = new OFPActionOutput();
- action.setMaxLength((short) 0);
- action.setPort(outPort);
- List<OFPAction> actions = new ArrayList<OFPAction>();
- actions.add(action);
- OFPInstructionApplyActions instructions = new OFPInstructionApplyActions();
- instructions.setActions(actions);
- List<OFPInstruction> instrList = new ArrayList<OFPInstruction>();
- instrList.add(instructions);
- fm.setInstructions(instrList);
- fm.setLength(U16.t(OFPFlowMod.MINIMUM_LENGTH + instructions.getLength()));
- try {
- stream.write(fm);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- // Send a packet out
- if (outPort == null || pi.getBufferId() == 0xffffffff) {
- OFPPacketOut po = new OFPPacketOut();
- po.setBufferId(bufferId);
- // po.setInPort(pi.getInPort());
-
- // set actions
- OFPActionOutput action = new OFPActionOutput();
- action.setMaxLength((short) 0);
- action.setPort((short) ((outPort == null) ? OFPPortNo.OFPP_FLOOD.getValue() : outPort));
- List<OFPAction> actions = new ArrayList<OFPAction>();
- actions.add(action);
- po.setActions(actions);
- po.setActionsLength((short) OFPActionOutput.MINIMUM_LENGTH);
-
- // set data if needed
- if (bufferId == 0xffffffff) {
- byte[] packetData = pi.getPacketData();
- po.setLength(U16.t(OFPPacketOut.MINIMUM_LENGTH + po.getActionsLength() + packetData.length));
- po.setPacketData(packetData);
- } else {
- po.setLength(U16.t(OFPPacketOut.MINIMUM_LENGTH + po.getActionsLength()));
- }
- try {
- stream.write(po);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- public String toString() {
- InetAddress remote = sock.socket().getInetAddress();
- return remote.getHostAddress() + ":" + sock.socket().getPort();
- }
-
- public OFMessageAsyncStream getStream() {
- return stream;
- }
- }
-
- public SimpleController(int port) throws IOException {
- listenSock = ServerSocketChannel.open();
- listenSock.configureBlocking(false);
- listenSock.socket().bind(new java.net.InetSocketAddress(port));
- listenSock.socket().setReuseAddress(true);
- this.port = port;
- switchSelectLoops = new ArrayList<SelectLoop>();
- switchSockets = new ConcurrentHashMap<SocketChannel, OFSwitch>();
- threadCount = 1;
- listenSelectLoop = new SelectLoop(this);
- // register this connection for accepting
- listenSelectLoop.register(listenSock, SelectionKey.OP_ACCEPT, listenSock);
-
- this.factory = new OFPBasicFactoryImpl();
- }
-
- @Override
- public void handleEvent(SelectionKey key, Object arg) throws IOException {
- if (arg instanceof ServerSocketChannel)
- handleListenEvent(key, (ServerSocketChannel) arg);
- else
- handleSwitchEvent(key, (SocketChannel) arg);
- }
-
- protected void handleListenEvent(SelectionKey key, ServerSocketChannel ssc) throws IOException {
- SocketChannel sock = listenSock.accept();
- OFMessageAsyncStream stream = new OFMessageAsyncStream(sock, factory);
- switchSockets.put(sock, new OFSwitch(sock, stream));
- System.err.println("Got new connection from " + switchSockets.get(sock));
- List<OFPMessage> l = new ArrayList<OFPMessage>();
- l.add(factory.getMessage(OFPType.HELLO));
- l.add(factory.getMessage(OFPType.FEATURES_REQUEST));
- stream.write(l);
-
- int ops = SelectionKey.OP_READ;
- if (stream.needsFlush())
- ops |= SelectionKey.OP_WRITE;
-
- // hash this switch into a thread
- SelectLoop sl = switchSelectLoops.get(sock.hashCode() % switchSelectLoops.size());
- sl.register(sock, ops, sock);
- // force select to return and re-enter using the new set of keys
- sl.wakeup();
- }
-
- protected void handleSwitchEvent(SelectionKey key, SocketChannel sock) {
- OFSwitch sw = switchSockets.get(sock);
- OFMessageAsyncStream stream = sw.getStream();
- try {
- if (key.isReadable()) {
- List<OFPMessage> msgs = stream.read();
- if (msgs == null) {
- key.cancel();
- switchSockets.remove(sock);
- return;
- }
-
- for (OFPMessage m : msgs) {
- switch (m.getType()) {
- case PACKET_IN:
- sw.handlePacketIn((OFPPacketIn) m);
- break;
- case HELLO:
- System.err.println("GOT HELLO from " + sw);
- break;
- case ECHO_REQUEST:
- OFPEchoReply reply = (OFPEchoReply) stream.getMessageFactory().getMessage(OFPType.ECHO_REPLY);
- reply.setXid(m.getXid());
- stream.write(reply);
- break;
- default:
- System.err.println("Unhandled OF message: " + m.getType() + " from "
- + sock.socket().getInetAddress());
- }
- }
- }
- if (key.isWritable()) {
- stream.flush();
- }
-
- /**
- * Only register for interest in R OR W, not both, causes stream
- * deadlock after some period of time
- */
- if (stream.needsFlush())
- key.interestOps(SelectionKey.OP_WRITE);
- else
- key.interestOps(SelectionKey.OP_READ);
- } catch (IOException e) {
- // if we have an exception, disconnect the switch
- key.cancel();
- switchSockets.remove(sock);
- }
- }
-
- public void run() throws IOException {
- System.err.println("Starting " + this.getClass().getCanonicalName() + " on port " + this.port + " with "
- + this.threadCount + " threads");
- // Static number of threads equal to processor cores
- es = Executors.newFixedThreadPool(threadCount);
-
- // Launch one select loop per threadCount and start running
- for (int i = 0; i < threadCount; ++i) {
- final SelectLoop sl = new SelectLoop(this);
- switchSelectLoops.add(sl);
- es.execute(new Runnable() {
- @Override
- public void run() {
- try {
- sl.doLoop();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- });
- }
-
- // Start the listen loop
- listenSelectLoop.doLoop();
- }
-
- public static void main(String[] args) throws IOException {
- SimpleCLI cmd = parseArgs(args);
- int port = Integer.valueOf(cmd.getOptionValue("p"));
- SimpleController sc = new SimpleController(port);
- sc.threadCount = Integer.valueOf(cmd.getOptionValue("t"));
- sc.run();
- }
-
- public static SimpleCLI parseArgs(String[] args) {
- Options options = new Options();
- options.addOption("h", "help", "print help");
- // unused?
- // options.addOption("n", true, "the number of packets to send");
- options.addOption("p", "port", 6633, "the port to listen on");
- options.addOption("t", "threads", 1, "the number of threads to run");
- try {
- SimpleCLI cmd = SimpleCLI.parse(options, args);
- if (cmd.hasOption("h")) {
- printUsage(options);
- System.exit(0);
- }
- return cmd;
- } catch (ParseException e) {
- System.err.println(e);
- printUsage(options);
- }
-
- System.exit(-1);
- return null;
- }
-
- public static void printUsage(Options options) {
- SimpleCLI.printHelp("Usage: " + SimpleController.class.getCanonicalName() + " [options]", options);
- }
-}
+++ /dev/null
-package org.openflow.codec.example.cli;
-
-public class Option {
- String shortOpt;
- String longOpt;
- Object defaultVal;
- String val; // current value of this option, string form
- boolean specified; // was this option found in the cmdline?
- String comment;
-
- /**
- * Option information storrage
- *
- * @param shortOpt
- * Short name for the option, e.g., "-p"
- * @param longOpt
- * Long name for option, e.g., "--port"
- * @param defaultVal
- * default value: "6633" or null if no default value
- * @param comment
- * String to print to explain this option, e.g., a help message
- */
- public Option(String shortOpt, String longOpt, Object defaultVal, String comment) {
- super();
- this.shortOpt = shortOpt;
- this.longOpt = longOpt;
- this.defaultVal = defaultVal;
- this.comment = comment;
- this.specified = false;
- }
-
- public Option(String shortOpt, String longOpt, String comment) {
- this(shortOpt, longOpt, null, comment);
- }
-
- public boolean needsArg() {
- return this.defaultVal != null;
- }
-}
+++ /dev/null
-package org.openflow.codec.example.cli;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Very basic CLI options listing
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- *
- */
-
-public class Options {
- Map<String, Option> shortOptionsMap;
- Map<String, Option> longOptionsMap;
-
- public Options() {
- this.shortOptionsMap = new HashMap<String, Option>();
- this.longOptionsMap = new HashMap<String, Option>();
- }
-
- public static Options make(Option opts[]) {
- Options options = new Options();
- for (int i = 0; i < opts.length; i++)
- options.addOption(opts[i]);
- return options;
- }
-
- private void addOption(Option option) {
- if (option.shortOpt != null)
- this.shortOptionsMap.put(option.shortOpt, option);
- if (option.longOpt != null)
- this.longOptionsMap.put(option.longOpt, option);
- }
-
- protected void addOption(String shortName, String longName, Object o, String comment) {
- Option option = new Option(shortName, longName, o, comment);
- addOption(option);
- }
-
- public void addOption(String shortName, String longName, boolean b, String comment) {
- this.addOption(shortName, longName, Boolean.valueOf(b), comment);
- }
-
- public void addOption(String shortName, String longName, int i, String comment) {
- this.addOption(shortName, longName, Integer.valueOf(i), comment);
- }
-
- public Option getOption(String shortName) {
- return this.shortOptionsMap.get(shortName);
- }
-
- public Option getOptionByLongName(String longName) {
- return this.longOptionsMap.get(longName);
- }
-
- public Collection<Option> getOptions() {
- return this.shortOptionsMap.values();
- }
-
- public void addOption(String shortName, String longName, String comment) {
- this.addOption(shortName, longName, null, comment);
- }
-
-}
+++ /dev/null
-package org.openflow.codec.example.cli;
-
-public class ParseException extends Exception {
-
- public ParseException(String msg) {
- super(msg);
- }
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
-}
+++ /dev/null
-package org.openflow.codec.example.cli;
-
-import java.io.PrintStream;
-
-/**
- * Very basic command line interface
- *
- * (really should be something in java.* for this; only implementing this to
- * remove external dependencies)
- *
- * Modeled after org.apache.common.cli .
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- *
- */
-
-public class SimpleCLI {
-
- private static final String NAME_WIDTH = "-15";
- private static final String VALUE_WIDTH = "-20";
- private static final String FORMAT_STRING = "%1$" + NAME_WIDTH + "s%2$" + VALUE_WIDTH + "s%3$s\n";
- Options options;
-
- int optind;
-
- /**
- * Need to use SimpleCLI.parse() instead
- *
- * @param options
- */
-
- private SimpleCLI(Options options) {
- this.options = options;
- }
-
- /**
- * @return the index of the last parsed option
- *
- * Useful for finding options that don't start with "-" or "--"
- */
- public int getOptind() {
- return optind;
- }
-
- /**
- * @param optind
- * the optind to set
- */
- public void setOptind(int optind) {
- this.optind = optind;
- }
-
- public boolean hasOption(String shortName) {
- Option option = this.options.getOption(shortName);
- if (option == null)
- return false;
- return option.specified;
- }
-
- public String getOptionValue(String shortName) {
- Option option = this.options.getOption(shortName);
- if (option == null)
- return null;
- if (!option.specified)
- return option.defaultVal.toString();
- else
- return option.val;
- }
-
- public static SimpleCLI parse(Options options, String[] args) throws ParseException {
- SimpleCLI simpleCLI = new SimpleCLI(options);
- int i;
- for (i = 0; i < args.length; i++) {
- if (!args[i].startsWith("-"))
- break; // not a short or long option
- String optName = args[i].replaceFirst("^-*", ""); // remove leading
- // "--"
- Option option;
- if (args[i].startsWith("--"))
- option = options.getOptionByLongName(optName);
- else
- option = options.getOption(optName);
- if (option == null)
- throw new ParseException("unknown option: " + optName);
- option.specified = true;
- if (option.needsArg()) {
- if ((i + 1) >= args.length)
- throw new ParseException("option " + optName + " requires an argument:: " + option.comment);
- option.val = args[i + 1];
- i++; // skip next element; we've parsed it
- }
- }
- simpleCLI.setOptind(i);
- return simpleCLI;
- }
-
- public static void printHelp(String canonicalName, Options options) {
- printHelp(canonicalName, options, System.err);
- }
-
- private static void printHelp(String helpString, Options options, PrintStream err) {
- err.println(helpString);
- err.format(FORMAT_STRING, "\toption", "type [default]", "usage");
- for (Option option : options.getOptions()) {
- String msg = "\t";
- if (option.shortOpt != null)
- msg += "-" + option.shortOpt;
- if (option.longOpt != null) {
- if (!msg.equals("\t"))
- msg += "|";
- msg += "--" + option.longOpt;
- }
- String val = "";
- if (option.defaultVal != null)
- val += option.defaultVal.getClass().getSimpleName() + " [" + option.defaultVal.toString() + "]";
- String comment;
- if (option.comment != null)
- comment = option.comment;
- else
- comment = "";
-
- err.format(FORMAT_STRING, msg, val, comment);
- }
- err.println(""); // print blank line at the end, to look pretty
- }
-
-}
+++ /dev/null
-package org.openflow.codec.io;
-
-import java.nio.ByteBuffer;
-
-/**
- * ByteDataBuffer that uses java.nio.ByteBuffer to read/write data.
- *
- * @author AnilGujele
- *
- */
-public class ByteDataBuffer implements IDataBuffer {
- private ByteBuffer byteBuffer;
-
- public ByteDataBuffer(ByteBuffer byteBuffer) {
- this.byteBuffer = byteBuffer;
- }
-
- @Override
- public byte get() {
- return byteBuffer.get();
- }
-
- @Override
- public IDataBuffer put(byte b) {
- byteBuffer.put(b);
- return this;
- }
-
- @Override
- public byte get(int index) {
-
- return byteBuffer.get(index);
- }
-
- @Override
- public IDataBuffer put(int index, byte b) {
- byteBuffer.put(index, b);
- return this;
- }
-
- @Override
- public IDataBuffer get(byte[] dst) {
- byteBuffer.get(dst);
- return this;
- }
-
- @Override
- public IDataBuffer put(byte[] src) {
- byteBuffer.put(src);
- return this;
- }
-
- @Override
- public char getChar() {
- return byteBuffer.getChar();
- }
-
- @Override
- public IDataBuffer putChar(char value) {
- byteBuffer.putChar(value);
- return this;
-
- }
-
- @Override
- public char getChar(int index) {
- return byteBuffer.getChar(index);
- }
-
- @Override
- public IDataBuffer putChar(int index, char value) {
- byteBuffer.putChar(index, value);
- return this;
- }
-
- @Override
- public short getShort() {
-
- return byteBuffer.getShort();
- }
-
- @Override
- public IDataBuffer putShort(short value) {
- byteBuffer.putShort(value);
- return this;
- }
-
- @Override
- public short getShort(int index) {
-
- return byteBuffer.getShort(index);
- }
-
- @Override
- public IDataBuffer putShort(int index, short value) {
- byteBuffer.putShort(index, value);
- return this;
- }
-
- @Override
- public int getInt() {
-
- return byteBuffer.getInt();
- }
-
- @Override
- public IDataBuffer putInt(int value) {
- byteBuffer.putInt(value);
- return this;
- }
-
- @Override
- public int getInt(int index) {
-
- return byteBuffer.getInt(index);
- }
-
- @Override
- public IDataBuffer putInt(int index, int value) {
- byteBuffer.putInt(index, value);
- return this;
- }
-
- @Override
- public long getLong() {
-
- return byteBuffer.getLong();
- }
-
- @Override
- public IDataBuffer putLong(long value) {
- byteBuffer.putLong(value);
- return this;
- }
-
- @Override
- public long getLong(int index) {
-
- return byteBuffer.getLong(index);
- }
-
- @Override
- public IDataBuffer putLong(int index, long value) {
- byteBuffer.putLong(index, value);
- return this;
- }
-
- @Override
- public float getFloat() {
-
- return byteBuffer.getFloat();
- }
-
- @Override
- public IDataBuffer putFloat(float value) {
- byteBuffer.putFloat(value);
- return this;
- }
-
- @Override
- public float getFloat(int index) {
-
- return byteBuffer.getFloat(index);
- }
-
- @Override
- public IDataBuffer putFloat(int index, float value) {
- byteBuffer.putFloat(index, value);
- return this;
- }
-
- @Override
- public double getDouble() {
-
- return byteBuffer.getDouble();
- }
-
- @Override
- public IDataBuffer putDouble(double value) {
- byteBuffer.putDouble(value);
- return this;
- }
-
- @Override
- public double getDouble(int index) {
- return byteBuffer.getDouble(index);
- }
-
- @Override
- public IDataBuffer putDouble(int index, double value) {
- byteBuffer.putDouble(index, value);
- return this;
- }
-
- @Override
- public int remaining() {
-
- return byteBuffer.remaining();
- }
-
- @Override
- public IDataBuffer mark() {
- byteBuffer.mark();
- return this;
- }
-
- @Override
- public int position() {
-
- return byteBuffer.position();
- }
-
- @Override
- public IDataBuffer position(int newPosition) {
- byteBuffer.position(newPosition);
- return this;
- }
-
- @Override
- public IDataBuffer reset() {
- byteBuffer.reset();
- return this;
- }
-
- @Override
- public IDataBuffer clear() {
- byteBuffer.clear();
- return this;
- }
-
- @Override
- public IDataBuffer flip() {
- byteBuffer.flip();
- return this;
- }
-
- @Override
- public int limit() {
- // TODO Auto-generated method stub
- return byteBuffer.limit();
- }
-
- @Override
- public IDataBuffer limit(int newLimit) {
- byteBuffer.limit(newLimit);
- return this;
- }
-
- @Override
- public IDataBuffer wrap(byte[] array) {
- ByteBuffer buffer = ByteBuffer.wrap(array);
- IDataBuffer dataBuffer = new ByteDataBuffer(buffer);
- return dataBuffer;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.io;
-
-import java.nio.ByteBuffer;
-
-/**
- * Creates a new IDataBuffer by allocating new space. DataBuffers is responsible
- * to create buffer class that will used by test cases. currently it instantiate
- * ByteDataBuffer (java's ByteBuffer) but it can be updated to support other
- * data buffer in future.
- *
- * @author AnilGujele
- *
- */
-public final class DataBuffers {
- /**
- * private constructor to protect instantiation
- */
- private DataBuffers() {
-
- }
-
- /**
- * get a new data buffer.
- *
- * @param capacity
- * The new buffer's capacity, in bytes
- *
- * @return The new data buffer
- *
- * @throws IllegalArgumentException
- * If the <tt>capacity</tt> is a negative integer
- */
- public static IDataBuffer allocate(int capacity) {
-
- ByteBuffer bytebuffer = ByteBuffer.allocateDirect(capacity);
- ByteDataBuffer dataBuffer = new ByteDataBuffer(bytebuffer);
- return dataBuffer;
- }
-}
+++ /dev/null
-package org.openflow.codec.io;
-
-/**
- * Adaptor interface that declares all the methods that need to be implemented
- * by IO library used by openflow protocol plugin.
- *
- * @see {org.openflow.codec.io.ByteDataBuffer}
- *
- * @author AnilGujele
- *
- */
-public interface IDataBuffer {
- /**
- * Relative get method. Reads the byte at this buffer's current position,
- * and then increments the position.
- *
- * @return The byte at the buffer's current position
- *
- * @throws IndexOutOfBoundsException
- * If the buffer's current position is not smaller than its
- * limit
- */
- public byte get();
-
- /**
- * Writes the given byte into this buffer at the current position, and then
- * increments the position.
- *
- * @param b
- * The byte to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If this buffer's current position is not smaller than its
- * limit
- *
- */
- public IDataBuffer put(byte b);
-
- /**
- * Absolute get method. Reads the byte at the given index.
- *
- * @param index
- * The index from which the byte will be read
- *
- * @return The byte at the given index
- *
- * @throws IndexOutOfBoundsException
- * If index is negative or not smaller than the buffer's limit
- */
- public byte get(int index);
-
- /**
- * Writes the given byte into this buffer at the given index.
- *
- * @param index
- * The index at which the byte will be written
- *
- * @param b
- * The byte value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If index is negative or not smaller than the buffer's limit
- *
- */
- public IDataBuffer put(int index, byte b);
-
- /**
- * This method transfers bytes from this buffer into the given destination
- * array.
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If there are fewer than length bytes remaining in this buffer
- */
- public IDataBuffer get(byte[] dst);
-
- /**
- * This method transfers the entire content of the given source byte array
- * into this buffer.
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If there is insufficient space in this buffer
- *
- */
- public IDataBuffer put(byte[] src);
-
- /**
- * Reads the next two bytes at this buffer's current position, composing
- * them into a char value according to the current byte order, and then
- * increments the position by two.
- *
- *
- * @return The char value at the buffer's current position
- *
- * @throws IndexOutOfBoundsException
- * If there are fewer than two bytes remaining in this buffer
- */
- public char getChar();
-
- /**
- * Writes two bytes containing the given char value, in the current byte
- * order, into this buffer at the current position, and then increments the
- * position by two.
- *
- * @param value
- * The char value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If there are fewer than two bytes remaining in this buffer
- *
- */
- public IDataBuffer putChar(char value);
-
- /**
- * Reads two bytes at the given index, composing them into a char value
- * according to the current byte order.
- *
- * @param index
- * The index from which the bytes will be read
- *
- * @return The char value at the given index
- *
- * @throws IndexOutOfBoundsException
- * If index is negative or not smaller than the buffer's limit,
- * minus one
- */
- public char getChar(int index);
-
- /**
- * Writes two bytes containing the given char value, in the current byte
- * order, into this buffer at the given index.
- *
- * @param index
- * The index at which the bytes will be written
- *
- * @param value
- * The char value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If index is negative or not smaller than the buffer's limit,
- * minus one
- *
- */
- public IDataBuffer putChar(int index, char value);
-
- /**
- * Reads the next two bytes at this buffer's current position, composing
- * them into a short value according to the current byte order, and then
- * increments the position by two.
- *
- * @return The short value at the buffer's current position
- *
- * @throws IndexOutOfBoundsException
- * If there are fewer than two bytes remaining in this buffer
- */
- public short getShort();
-
- /**
- * Writes two bytes containing the given short value, in the current byte
- * order, into this buffer at the current position, and then increments the
- * position by two.
- *
- * @param value
- * The short value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If there are fewer than two bytes remaining in this buffer
- *
- */
- public IDataBuffer putShort(short value);
-
- /**
- * Reads two bytes at the given index, composing them into a short value
- * according to the current byte order.
- *
- * @param index
- * The index from which the bytes will be read
- *
- * @return The short value at the given index
- *
- * @throws IndexOutOfBoundsException
- * If index is negative or not smaller than the buffer's limit,
- * minus one
- */
- public short getShort(int index);
-
- /**
- * Writes two bytes containing the given short value, in the current byte
- * order, into this buffer at the given index.
- *
- * @param index
- * The index at which the bytes will be written
- *
- * @param value
- * The short value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If index is negative or not smaller than the buffer's limit,
- * minus one
- */
- public IDataBuffer putShort(int index, short value);
-
- /**
- * Reads the next four bytes at this buffer's current position, composing
- * them into an int value according to the current byte order, and then
- * increments the position by four.
- *
- * @return The int value at the buffer's current position
- *
- * @throws IndexOutOfBoundsException
- * If there are fewer than four bytes remaining in this buffer
- */
- public int getInt();
-
- /**
- * Writes four bytes containing the given int value, in the current byte
- * order, into this buffer at the current position, and then increments the
- * position by four.
- *
- * @param value
- * The int value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If there are fewer than four bytes remaining in this buffer
- *
- */
- public IDataBuffer putInt(int value);
-
- /**
- * Reads four bytes at the given index, composing them into a int value
- * according to the current byte order.
- *
- * @param index
- * The index from which the bytes will be read
- *
- * @return The int value at the given index
- *
- * @throws IndexOutOfBoundsException
- * If index is negative or not smaller than the buffer's limit,
- * minus three
- */
- public int getInt(int index);
-
- /**
- * Writes four bytes containing the given int value, in the current byte
- * order, into this buffer at the given index.
- *
- * @param index
- * The index at which the bytes will be written
- *
- * @param value
- * The int value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If index is negative or not smaller than the buffer's limit,
- * minus three
- */
- public IDataBuffer putInt(int index, int value);
-
- /**
- * Reads the next eight bytes at this buffer's current position, composing
- * them into a long value according to the current byte order, and then
- * increments the position by eight.
- *
- * @return The long value at the buffer's current position
- *
- * @throws IndexOutOfBoundsException
- * If there are fewer than eight bytes remaining in this buffer
- */
- public long getLong();
-
- /**
- * Writes eight bytes containing the given long value, in the current byte
- * order, into this buffer at the current position, and then increments the
- * position by eight.
- *
- * @param value
- * The long value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If there are fewer than eight bytes remaining in this buffer
- *
- */
- public IDataBuffer putLong(long value);
-
- /**
- * Reads eight bytes at the given index, composing them into a long value
- * according to the current byte order.
- *
- * @param index
- * The index from which the bytes will be read
- *
- * @return The long value at the given index
- *
- * @throws IndexOutOfBoundsException
- * If index is negative or not smaller than the buffer's limit,
- * minus seven
- */
- public long getLong(int index);
-
- /**
- * Writes eight bytes containing the given long value, in the current byte
- * order, into this buffer at the given index.
- *
- * @param index
- * The index at which the bytes will be written
- *
- * @param value
- * The long value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If index is negative or not smaller than the buffer's limit,
- * minus seven
- *
- */
- public IDataBuffer putLong(int index, long value);
-
- /**
- * Reads the next four bytes at this buffer's current position, composing
- * them into a float value according to the current byte order, and then
- * increments the position by four.
- *
- * @return The float value at the buffer's current position
- *
- * @throws IndexOutOfBoundsException
- * If there are fewer than four bytes remaining in this buffer
- */
- public float getFloat();
-
- /**
- * Writes four bytes containing the given float value, in the current byte
- * order, into this buffer at the current position, and then increments the
- * position by four.
- *
- * @param value
- * The float value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If there are fewer than four bytes remaining in this buffer
- */
- public IDataBuffer putFloat(float value);
-
- /**
- * Reads four bytes at the given index, composing them into a float value
- * according to the current byte order.
- *
- * @param index
- * The index from which the bytes will be read
- *
- * @return The float value at the given index
- *
- * @throws IndexOutOfBoundsException
- * If index is negative or not smaller than the buffer's limit,
- * minus three
- */
- public float getFloat(int index);
-
- /**
- * Writes four bytes containing the given float value, in the current byte
- * order, into this buffer at the given index.
- *
- * @param index
- * The index at which the bytes will be written
- *
- * @param value
- * The float value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If index is negative or not smaller than the buffer's limit,
- * minus three
- *
- */
- public IDataBuffer putFloat(int index, float value);
-
- /**
- * Reads the next eight bytes at this buffer's current position, composing
- * them into a double value according to the current byte order, and then
- * increments the position by eight.
- *
- * @return The double value at the buffer's current position
- *
- * @throws IndexOutOfBoundsException
- * If there are fewer than eight bytes remaining in this buffer
- */
- public double getDouble();
-
- /**
- * Writes eight bytes containing the given double value, in the current byte
- * order, into this buffer at the current position, and then increments the
- * position by eight.
- *
- * @param value
- * The double value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If there are fewer than eight bytes remaining in this buffer
- *
- */
- public IDataBuffer putDouble(double value);
-
- /**
- * Reads eight bytes at the given index, composing them into a double value
- * according to the current byte order.
- *
- * @param index
- * The index from which the bytes will be read
- *
- * @return The double value at the given index
- *
- * @throws IndexOutOfBoundsException
- * If index is negative or not smaller than the buffer's limit,
- * minus seven
- */
- public double getDouble(int index);
-
- /**
- * Writes eight bytes containing the given double value, in the current byte
- * order, into this buffer at the given index.
- *
- * @param index
- * The index at which the bytes will be written
- *
- * @param value
- * The double value to be written
- *
- * @return This buffer
- *
- * @throws IndexOutOfBoundsException
- * If index is negative or not smaller than the buffer's limit,
- * minus seven
- *
- */
- public IDataBuffer putDouble(int index, double value);
-
- /**
- * Returns the number of elements between the current position and the
- * limit.
- *
- * @return The number of elements remaining in this buffer
- */
- public int remaining();
-
- /**
- * Sets this buffer's mark at its position.
- *
- * @return This buffer
- */
- public IDataBuffer mark();
-
- /**
- * Returns this buffer's position.
- *
- * @return The position of this buffer
- */
- public int position();
-
- /**
- * Sets this buffer's position. If the mark is defined and larger than the
- * new position then it is discarded.
- *
- * @param newPosition
- * The new position value; must be non-negative and no larger
- * than the current limit
- *
- * @return This buffer
- *
- * @throws IllegalArgumentException
- * If the preconditions on newPosition do not hold
- */
- public IDataBuffer position(int newPosition);
-
- /**
- * Resets this buffer's position to the previously-marked position.
- *
- * Invoking this method neither changes nor discards the mark's value.
- *
- * @return This buffer
- *
- */
- public IDataBuffer reset();
-
- /**
- * Clears this buffer. The position is set to zero, the limit is set to the
- * capacity, and the mark is discarded.
- *
- * Invoke this method before using a sequence of channel-read or put
- * operations to fill this buffer. For example:
- *
- * buf.clear(); // Prepare buffer for reading in.read(buf); // Read data
- *
- * This method does not actually erase the data in the buffer, but it is
- * named as if it did because it will most often be used in situations in
- * which that might as well be the case.
- *
- * @return This buffer
- */
- public IDataBuffer clear();
-
- /**
- * Flips this buffer. The limit is set to the current position and then the
- * position is set to zero. If the mark is defined then it is discarded.
- *
- * After a sequence of channel-read or put operations, invoke this method to
- * prepare for a sequence of channel-write or relative get operations. For
- * example:
- *
- * buf.put(magic); // Prepend header in.read(buf); // Read data into rest of
- * buffer buf.flip(); // Flip buffer out.write(buf); // Write header + data
- * to channel
- *
- * @return This buffer
- */
- public IDataBuffer flip();
-
- /**
- * Returns this buffer's limit.
- *
- * @return The limit of this buffer
- */
- public int limit();
-
- /**
- * Sets this buffer's limit. If the position is larger than the new limit
- * then it is set to the new limit. If the mark is defined and larger than
- * the new limit then it is discarded.
- *
- * @param newLimit
- * The new limit value; must be non-negative and no larger than
- * this buffer's capacity
- *
- * @return This buffer
- *
- * @throws IllegalArgumentException
- * If the preconditions on newLimit do not hold
- */
- public IDataBuffer limit(int newLimit);
-
- /**
- * Wraps a data byte array into a buffer.
- *
- * The new buffer will be backed by the given byte array; that is,
- * modifications to the buffer will cause the array to be modified and vice
- * versa. The new buffer's capacity and limit will be array.length, its
- * position will be zero, and its mark will be undefined. Its backing array
- * will be the given array, and its array offset will be zero.
- *
- * @param array
- * The array that will back this buffer
- *
- * @return The new data buffer
- */
- public IDataBuffer wrap(byte[] array);
-
-}
+++ /dev/null
-/**
- *
- */
-package org.openflow.codec.io;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-import java.util.List;
-
-import org.openflow.codec.protocol.OFPMessage;
-import org.openflow.codec.protocol.factory.OFPMessageFactory;
-
-/**
- * Asynchronous OpenFlow message marshalling and unmarshalling stream wrapped
- * around an NIO SocketChannel
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- * @author David Erickson (daviderickson@cs.stanford.edu)
- *
- */
-public class OFMessageAsyncStream implements OFMessageInStream, OFMessageOutStream {
- static public int defaultBufferSize = 1048576; // 1MB
-
- protected ByteBuffer inBuf, outBuf;
- protected OFPMessageFactory messageFactory;
- protected SocketChannel sock;
- protected int partialReadCount = 0;
-
- public OFMessageAsyncStream(SocketChannel sock, OFPMessageFactory messageFactory) throws IOException {
- inBuf = ByteBuffer.allocateDirect(OFMessageAsyncStream.defaultBufferSize);
- outBuf = ByteBuffer.allocateDirect(OFMessageAsyncStream.defaultBufferSize);
- this.sock = sock;
- this.messageFactory = messageFactory;
- this.sock.configureBlocking(false);
- }
-
- @Override
- public List<OFPMessage> read() throws IOException {
- return this.read(0);
- }
-
- @Override
- public List<OFPMessage> read(int limit) throws IOException {
- List<OFPMessage> l;
- int read = sock.read(inBuf);
- if (read == -1)
- return null;
- inBuf.flip();
- IDataBuffer buffer = new ByteDataBuffer(inBuf);
- l = messageFactory.parseMessages(buffer, limit);
- if (inBuf.hasRemaining())
- inBuf.compact();
- else
- inBuf.clear();
- return l;
- }
-
- protected void appendMessageToOutBuf(OFPMessage m) throws IOException {
- int msglen = m.getLengthU();
- if (outBuf.remaining() < msglen) {
- throw new IOException("Message length exceeds buffer capacity: " + msglen);
- }
- IDataBuffer buffer = new ByteDataBuffer(outBuf);
- m.writeTo(buffer);
- }
-
- /**
- * Buffers a single outgoing openflow message
- */
- @Override
- public void write(OFPMessage m) throws IOException {
- appendMessageToOutBuf(m);
- }
-
- /**
- * Buffers a list of OpenFlow messages
- */
- @Override
- public void write(List<OFPMessage> l) throws IOException {
- for (OFPMessage m : l) {
- appendMessageToOutBuf(m);
- }
- }
-
- /**
- * Flush buffered outgoing data. Keep flushing until needsFlush() returns
- * false. Each flush() corresponds to a SocketChannel.write(), so this is
- * designed for one flush() per select() event
- */
- public void flush() throws IOException {
- outBuf.flip(); // swap pointers; lim = pos; pos = 0;
- sock.write(outBuf); // write data starting at pos up to lim
- outBuf.compact();
- }
-
- /**
- * Is there outgoing buffered data that needs to be flush()'d?
- */
- public boolean needsFlush() {
- return outBuf.position() > 0;
- }
-
- /**
- * @return the messageFactory
- */
- public OFPMessageFactory getMessageFactory() {
- return messageFactory;
- }
-
- /**
- * @param messageFactory
- * the messageFactory to set
- */
- public void setMessageFactory(OFPMessageFactory messageFactory) {
- this.messageFactory = messageFactory;
- }
-}
+++ /dev/null
-/**
- *
- */
-package org.openflow.codec.io;
-
-import java.util.List;
-
-import org.openflow.codec.protocol.OFPMessage;
-import org.openflow.codec.protocol.factory.OFPMessageFactory;
-
-/**
- * Interface for reading OFMessages from a buffered stream
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- *
- */
-public interface OFMessageInStream {
- /**
- * Read OF messages from the stream
- *
- * @return a list of OF Messages, empty if no complete messages are
- * available, null if the stream has closed
- */
- public List<OFPMessage> read() throws java.io.IOException;
-
- /**
- * Read OF messages from the stream
- *
- * @param limit
- * The maximum number of messages to read: 0 means all that are
- * buffered
- * @return a list of OF Messages, empty if no complete messages are
- * available, null if the stream has closed
- *
- */
- public List<OFPMessage> read(int limit) throws java.io.IOException;
-
- /**
- * Sets the OFPMessageFactory used to create messages on this stream
- *
- * @param factory
- */
- public void setMessageFactory(OFPMessageFactory factory);
-
- /**
- * Returns the OFPMessageFactory used to create messages on this stream
- *
- * @return
- */
- public OFPMessageFactory getMessageFactory();
-}
+++ /dev/null
-/**
- *
- */
-package org.openflow.codec.io;
-
-import java.util.List;
-
-import org.openflow.codec.protocol.OFPMessage;
-
-/**
- * Interface for writing OFMessages to a buffered stream
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- *
- */
-public interface OFMessageOutStream {
- /**
- * Write an OpenFlow message to the stream
- *
- * @param m
- * An OF Message
- */
- public void write(OFPMessage m) throws java.io.IOException;
-
- /**
- * Write an OpenFlow message to the stream. Messages are sent in one large
- * write() for efficiency
- *
- * @param l
- * A list of OF Messages
- */
- public void write(List<OFPMessage> l) throws java.io.IOException;
-
- /**
- * Pushes buffered data out the Stream; this is NOT guranteed to flush all
- * data, multiple flush() calls may be required, until needFlush() returns
- * false.
- */
- public void flush() throws java.io.IOException;
-
- /**
- * Is there buffered data that needs to be flushed?
- *
- * @return true if there is buffered data and flush() should be called
- */
- public boolean needsFlush();
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-/**
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public interface Instantiable<E> {
-
- /**
- * Create a new instance of a given subclass.
- *
- * @return the new instance.
- */
- public E instantiate();
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * OXM match field defined for OPENFLOW_BASIC type correspond to enum
- * oxm_ofb_match_fields
- *
- * @author AnilGujele
- *
- */
-public enum OFBMatchFields {
-
- IN_PORT((byte) 0, 32, false), /* Switch input port. */
- IN_PHY_PORT((byte) 1, 32, false), /* Switch physical input port. */
- METADATA((byte) 2, 64, true), /* Metadata passed between tables. */
- ETH_DST((byte) 3, 48, true), /* Ethernet destination address. */
- ETH_SRC((byte) 4, 48, true), /* Ethernet source address. */
- ETH_TYPE((byte) 5, 16, false), /* Ethernet frame type. */
- VLAN_VID((byte) 6, 13, true), /* VLAN id. */
- VLAN_PCP((byte) 7, 3, false), /* VLAN priority. */
- IP_DSCP((byte) 8, 6, false), /* IP DSCP (6 bits in ToS field). */
- IP_ECN((byte) 9, 2, false), /* IP ECN (2 bits in ToS field). */
- IP_PROTO((byte) 10, 8, false), /* IP protocol. */
- IPV4_SRC((byte) 11, 32, true), /* IPv4 source address. */
- IPV4_DST((byte) 12, 32, true), /* IPv4 destination address. */
- TCP_SRC((byte) 13, 16, false), /* TCP source port. */
- TCP_DST((byte) 14, 16, false), /* TCP destination port. */
- UDP_SRC((byte) 15, 16, false), /* UDP source port. */
- UDP_DST((byte) 16, 16, false), /* UDP destination port. */
- SCTP_SRC((byte) 17, 16, false), /* SCTP source port. */
- SCTP_DST((byte) 18, 16, false), /* SCTP destination port. */
- ICMPV4_TYPE((byte) 19, 8, false), /* ICMP type. */
- ICMPV4_CODE((byte) 20, 8, false), /* ICMP code. */
- ARP_OP((byte) 21, 16, false), /* ARP opcode. */
- ARP_SPA((byte) 22, 32, true), /* ARP source IPv4 address. */
- ARP_TPA((byte) 23, 32, true), /* ARP target IPv4 address. */
- ARP_SHA((byte) 24, 48, true), /* ARP source hardware address. */
- ARP_THA((byte) 25, 48, true), /* ARP target hardware address. */
- IPV6_SRC((byte) 26, 128, true), /* IPv6 source address. */
- IPV6_DST((byte) 27, 128, true), /* IPv6 destination address. */
- IPV6_FLABEL((byte) 28, 20, true), /* IPv6 Flow Label */
- ICMPV6_TYPE((byte) 29, 8, false), /* ICMPv6 type. */
- ICMPV6_CODE((byte) 30, 8, false), /* ICMPv6 code. */
- IPV6_ND_TARGET((byte) 31, 128, false), /* Target address for ND. */
- IPV6_ND_SLL((byte) 32, 48, false), /* Source link-layer for ND. */
- IPV6_ND_TLL((byte) 33, 48, false), /* Target link-layer for ND. */
- MPLS_LABEL((byte) 34, 20, false), /* MPLS label. */
- MPLS_TC((byte) 35, 3, false), /* MPLS TC. */
- OFP_MPLS_BOS((byte) 36, 1, false), /* MPLS BoS bit. */
- PBB_ISID((byte) 37, 24, true), /* PBB I-SID. */
- TUNNEL_ID((byte) 38, 64, true), /* Logical Port Metadata. */
- IPV6_EXTHDR((byte) 39, 9, true); /* IPv6 Extension Header pseudo-field */
-
- private static OFBMatchFields[] mapping;
- private byte value;
- private int lengthInBits;
- private boolean hasMask;
-
- private OFBMatchFields(byte value, int length, boolean hasMask) {
- this.value = value;
- this.lengthInBits = length;
- this.setHasMask(hasMask);
- OFBMatchFields.addMapping(value, this);
- }
-
- /**
- * 7 left most bit for match field is the value of match field
- *
- * @return Returns the wire protocol value corresponding to this match field
- */
- public byte getValue() {
- return this.value;
- }
-
- /**
- * get the length of data for match field in bits.
- *
- * @return
- */
- public int getLengthInBits() {
- return lengthInBits;
- }
-
- /**
- * get the length of data for match field in bytes.
- *
- * @return
- */
- public int getLengthInBytes() {
- int value = lengthInBits / 8;
- value = (lengthInBits % 8 != 0) ? value + 1 : value;
-
- return value;
- }
-
- /**
- * Adds a mapping from field value to OXMMatchField enum
- *
- * @param index
- * OpenFlow wire protocol field index
- * @param field
- * type
- */
- static void addMapping(byte index, OFBMatchFields field) {
- if (mapping == null) {
- mapping = new OFBMatchFields[40];
- }
- OFBMatchFields.mapping[index] = field;
- }
-
- /**
- * Remove a mapping from match value to OXMMatchField enum
- *
- * @param index
- * OpenFlow wire protocol field index
- */
- static void removeMapping(byte i) {
- OFBMatchFields.mapping[i] = null;
- }
-
- /**
- * Given a wire protocol OpenFlow field number, return the OXMMatchField
- * associated with it
- *
- * @param i
- * wire protocol field number
- * @return OXMMatchField enum type
- */
-
- public static OFBMatchFields valueOf(Byte i) {
- return OFBMatchFields.mapping[i];
- }
-
- /**
- * this field can have has mask
- *
- * @return
- */
- public boolean isHasMask() {
- return hasMask;
- }
-
- /**
- *
- * @param hasMask
- */
- void setHasMask(boolean hasMask) {
- this.hasMask = hasMask;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an OFPT_BARRIER_REPLY message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPBarrierReply extends OFPMessage {
- public OFPBarrierReply() {
- super();
- this.type = OFPType.BARRIER_REPLY;
- this.length = U16.t(OFPMessage.MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an OFPT_BARRIER_REQUEST message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPBarrierRequest extends OFPMessage {
- public OFPBarrierRequest() {
- super();
- this.type = OFPType.BARRIER_REQUEST;
- this.length = U16.t(OFPMessage.MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_echo_reply message
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- */
-
-public class OFPEchoReply extends OFPEchoRequest {
- public static int MINIMUM_LENGTH = 8;
-
- public OFPEchoReply() {
- super();
- this.type = OFPType.ECHO_REPLY;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_echo_request message
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- */
-
-public class OFPEchoRequest extends OFPMessage {
- public static int MINIMUM_LENGTH = 8;
- byte[] payload;
-
- public OFPEchoRequest() {
- super();
- this.type = OFPType.ECHO_REQUEST;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- @Override
- public void readFrom(IDataBuffer bb) {
- super.readFrom(bb);
- int datalen = this.getLengthU() - MINIMUM_LENGTH;
- if (datalen > 0) {
- this.payload = new byte[datalen];
- bb.get(payload);
- }
- }
-
- /**
- * @return the payload
- */
- public byte[] getPayload() {
- return payload;
- }
-
- /**
- * @param payload
- * the payload to set
- */
- public void setPayload(byte[] payload) {
- this.payload = payload;
- }
-
- @Override
- public void writeTo(IDataBuffer bb) {
- super.writeTo(bb);
- if (payload != null)
- bb.put(payload);
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.factory.OFPMessageFactory;
-import org.openflow.codec.protocol.factory.OFPMessageFactoryAware;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_error_msg
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- */
-public class OFPErrorMsg extends OFPMessage implements OFPMessageFactoryAware {
- public static int MINIMUM_LENGTH = 12;
-
- public enum OFErrorType {
- OFPET_HELLO_FAILED, OFPET_BAD_REQUEST, OFPET_BAD_ACTION, OFPET_FLOW_MOD_FAILED, OFPET_PORT_MOD_FAILED, OFPET_QUEUE_OP_FAILED
- }
-
- public enum OFHelloFailedCode {
- OFPHFC_INCOMPATIBLE, OFPHFC_EPERM
- }
-
- public enum OFBadRequestCode {
- OFPBRC_BAD_VERSION, OFPBRC_BAD_TYPE, OFPBRC_BAD_STAT, OFPBRC_BAD_VENDOR, OFPBRC_BAD_SUBTYPE, OFPBRC_EPERM, OFPBRC_BAD_LEN, OFPBRC_BUFFER_EMPTY, OFPBRC_BUFFER_UNKNOWN
- }
-
- public enum OFBadActionCode {
- OFPBAC_BAD_TYPE, OFPBAC_BAD_LEN, OFPBAC_BAD_VENDOR, OFPBAC_BAD_VENDOR_TYPE, OFPBAC_BAD_OUT_PORT, OFPBAC_BAD_ARGUMENT, OFPBAC_EPERM, OFPBAC_TOO_MANY, OFPBAC_BAD_QUEUE
- }
-
- public enum OFFlowModFailedCode {
- OFPFMFC_ALL_TABLES_FULL, OFPFMFC_OVERLAP, OFPFMFC_EPERM, OFPFMFC_BAD_EMERG_TIMEOUT, OFPFMFC_BAD_COMMAND, OFPFMFC_UNSUPPORTED
- }
-
- public enum OFPortModFailedCode {
- OFPPMFC_BAD_PORT, OFPPMFC_BAD_HW_ADDR
- }
-
- public enum OFQueueOpFailedCode {
- OFPQOFC_BAD_PORT, OFPQOFC_BAD_QUEUE, OFPQOFC_EPERM
- }
-
- protected short errorType;
- protected short errorCode;
- protected OFPMessageFactory factory;
- protected byte[] error;
- protected boolean errorIsAscii;
-
- public OFPErrorMsg() {
- super();
- this.type = OFPType.ERROR;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * @return the errorType
- */
- public short getErrorType() {
- return errorType;
- }
-
- /**
- * @param errorType
- * the errorType to set
- */
- public void setErrorType(short errorType) {
- this.errorType = errorType;
- }
-
- public void setErrorType(OFErrorType type) {
- this.errorType = (short) type.ordinal();
- }
-
- /**
- * @return the errorCode
- */
- public short getErrorCode() {
- return errorCode;
- }
-
- /**
- * @param errorCode
- * the errorCode to set
- */
- public void setErrorCode(OFHelloFailedCode code) {
- this.errorCode = (short) code.ordinal();
- }
-
- public void setErrorCode(short errorCode) {
- this.errorCode = errorCode;
- }
-
- public void setErrorCode(OFBadRequestCode code) {
- this.errorCode = (short) code.ordinal();
- }
-
- public void setErrorCode(OFBadActionCode code) {
- this.errorCode = (short) code.ordinal();
- }
-
- public void setErrorCode(OFFlowModFailedCode code) {
- this.errorCode = (short) code.ordinal();
- }
-
- public void setErrorCode(OFPortModFailedCode code) {
- this.errorCode = (short) code.ordinal();
- }
-
- public void setErrorCode(OFQueueOpFailedCode code) {
- this.errorCode = (short) code.ordinal();
- }
-
- public OFPMessage getOffendingMsg(IDataBuffer data) {
- // should only have one message embedded; if more than one, just
- // grab first
- if (this.error == null)
- return null;
- IDataBuffer errorMsg = data.wrap(this.error);
- if (factory == null)
- throw new RuntimeException("MessageFactory not set");
- List<OFPMessage> messages = this.factory.parseMessages(errorMsg, error.length);
- // OVS apparently sends partial messages in errors
- // need to be careful of that AND can't use data.limit() as
- // a packet boundary because there could be more data queued
- if (messages.size() > 0)
- return messages.get(0);
- else
- return null;
- }
-
- /**
- * Write this offending message into the payload of the Error message
- *
- * @param offendingMsg
- */
-
- public void setOffendingMsg(OFPMessage offendingMsg, IDataBuffer buffer) {
- if (offendingMsg == null) {
- super.setLengthU(MINIMUM_LENGTH);
- } else {
- this.error = new byte[offendingMsg.getLengthU()];
- IDataBuffer data = buffer.wrap(error);
- offendingMsg.writeTo(data);
- super.setLengthU(MINIMUM_LENGTH + offendingMsg.getLengthU());
- }
- }
-
- public OFPMessageFactory getFactory() {
- return factory;
- }
-
- @Override
- public void setMessageFactory(OFPMessageFactory factory) {
- this.factory = factory;
- }
-
- /**
- * @return the error
- */
- public byte[] getError() {
- return error;
- }
-
- /**
- * @param error
- * the error to set
- */
- public void setError(byte[] error) {
- this.error = error;
- }
-
- /**
- * @return the errorIsAscii
- */
- public boolean isErrorIsAscii() {
- return errorIsAscii;
- }
-
- /**
- * @param errorIsAscii
- * the errorIsAscii to set
- */
- public void setErrorIsAscii(boolean errorIsAscii) {
- this.errorIsAscii = errorIsAscii;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.errorType = data.getShort();
- this.errorCode = data.getShort();
- int dataLength = this.getLengthU() - MINIMUM_LENGTH;
- if (dataLength > 0) {
- this.error = new byte[dataLength];
- data.get(this.error);
- if (this.errorType == OFErrorType.OFPET_HELLO_FAILED.ordinal())
- this.errorIsAscii = true;
- }
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putShort(errorType);
- data.putShort(errorCode);
- if (error != null)
- data.put(error);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + Arrays.hashCode(error);
- result = prime * result + errorCode;
- result = prime * result + (errorIsAscii ? 1231 : 1237);
- result = prime * result + errorType;
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (getClass() != obj.getClass())
- return false;
- OFPErrorMsg other = (OFPErrorMsg) obj;
- if (!Arrays.equals(error, other.error))
- return false;
- if (errorCode != other.errorCode)
- return false;
- if (errorIsAscii != other.errorIsAscii)
- return false;
- if (errorType != other.errorType)
- return false;
- return true;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.Arrays;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents ofp_experimenter_header
- *
- * @author AnilGujele
- */
-public class OFPExperimenterHeader extends OFPMessage {
- public static int MINIMUM_LENGTH = 16;
-
- private int experimenter;
- private int expType;
- private byte[] data;
-
- /**
- * constructor
- */
- public OFPExperimenterHeader() {
- super();
- this.type = OFPType.EXPERIMENTER;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * get experimenter id
- *
- * @return
- */
- public int getExperimenter() {
- return experimenter;
- }
-
- /**
- * set experimenter id
- *
- * @param experimenter
- */
- public void setExperimenter(int experimenter) {
- this.experimenter = experimenter;
- }
-
- /**
- * get experimenter type
- *
- * @return
- */
- public int getExpType() {
- return expType;
- }
-
- /**
- * set experimenter type
- *
- * @param expType
- */
- public void setExpType(int expType) {
- this.expType = expType;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.experimenter = data.getInt();
- this.expType = data.getInt();
- if (this.length > MINIMUM_LENGTH) {
- this.data = new byte[this.length - MINIMUM_LENGTH];
- data.get(this.data);
- }
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(this.experimenter);
- data.putInt(this.expType);
- if (this.data != null)
- data.put(this.data);
- }
-
- /**
- * @return the data
- */
- public byte[] getData() {
- return data;
- }
-
- /**
- * @param data
- * the data to set
- */
- public void setData(byte[] data) {
- this.data = data;
- updateLength();
- }
-
- /**
- * update length
- */
- private void updateLength() {
- int dataLength = (null == data) ? 0 : data.length;
- this.length = (short) (OFPExperimenterHeader.MINIMUM_LENGTH + dataLength);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 337;
- int result = super.hashCode();
- result = prime * result + Arrays.hashCode(data);
- result = prime * result + experimenter;
- result = prime * result + expType;
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (getClass() != obj.getClass())
- return false;
- OFPExperimenterHeader other = (OFPExperimenterHeader) obj;
- if (experimenter != other.experimenter)
- return false;
- if (expType != other.expType)
- return false;
- if (!Arrays.equals(data, other.data))
- return false;
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.factory.OFPInstructionFactory;
-import org.openflow.codec.protocol.factory.OFPInstructionFactoryAware;
-import org.openflow.codec.protocol.instruction.OFPInstruction;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_flow_mod message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- *
- */
-public class OFPFlowMod extends OFPMessage implements OFPInstructionFactoryAware, Cloneable {
- public static int MINIMUM_LENGTH = 56;
- public static int MIN_LENGTH_WITHOUT_MATCH = MINIMUM_LENGTH - 8;
-
- public static final short OFPFC_ADD = 0; /* New flow. */
- public static final short OFPFC_MODIFY = 1; /* Modify all matching flows. */
- public static final short OFPFC_MODIFY_STRICT = 2; /*
- * Modify entry strictly
- * matching wildcards
- */
- public static final short OFPFC_DELETE = 3; /* Delete all matching flows. */
- public static final short OFPFC_DELETE_STRICT = 4; /*
- * Strictly match
- * wildcards and
- * priority.
- */
-
- private OFPInstructionFactory instructionFactory;
- private long cookie;
- private long cookieMask;
- private byte tableId;
- private OFPFlowModCommand command;
- private short idleTimeout;
- private short hardTimeout;
- private short priority;
- private int bufferId;
- private int outPort;
- private int outGroup;
- private short flags;
- private OFPMatch match;
- private List<OFPInstruction> instructions;
-
- public OFPFlowMod() {
- super();
- this.type = OFPType.FLOW_MOD;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * Get buffer_id
- *
- * @return
- */
- public int getBufferId() {
- return this.bufferId;
- }
-
- /**
- * Set buffer_id
- *
- * @param bufferId
- */
- public OFPFlowMod setBufferId(int bufferId) {
- this.bufferId = bufferId;
- return this;
- }
-
- /**
- * Get cookie
- *
- * @return
- */
- public long getCookie() {
- return this.cookie;
- }
-
- /**
- * Set cookie
- *
- * @param cookie
- */
- public OFPFlowMod setCookie(long cookie) {
- this.cookie = cookie;
- return this;
- }
-
- public long getCookieMask() {
- return cookieMask;
- }
-
- public void setCookieMask(long cookieMask) {
- this.cookieMask = cookieMask;
- }
-
- public byte getTableId() {
- return tableId;
- }
-
- public void setTableId(byte tableId) {
- this.tableId = tableId;
- }
-
- /**
- * Get command
- *
- * @return
- */
- public OFPFlowModCommand getCommand() {
- return this.command;
- }
-
- /**
- * Set command
- *
- * @param command
- */
- public OFPFlowMod setCommand(OFPFlowModCommand command) {
- this.command = command;
- return this;
- }
-
- /**
- * Get flags
- *
- * @return
- */
- public short getFlags() {
- return this.flags;
- }
-
- /**
- * Set flags
- *
- * @param flags
- */
- public OFPFlowMod setFlags(short flags) {
- this.flags = flags;
- return this;
- }
-
- /**
- * Get hard_timeout
- *
- * @return
- */
- public short getHardTimeout() {
- return this.hardTimeout;
- }
-
- /**
- * Set hard_timeout
- *
- * @param hardTimeout
- */
- public OFPFlowMod setHardTimeout(short hardTimeout) {
- this.hardTimeout = hardTimeout;
- return this;
- }
-
- /**
- * Get idle_timeout
- *
- * @return
- */
- public short getIdleTimeout() {
- return this.idleTimeout;
- }
-
- /**
- * Set idle_timeout
- *
- * @param idleTimeout
- */
- public OFPFlowMod setIdleTimeout(short idleTimeout) {
- this.idleTimeout = idleTimeout;
- return this;
- }
-
- /**
- * Gets a copy of the OFPMatch object for this FlowMod, changes to this
- * object do not modify the FlowMod
- *
- * @return
- */
- public OFPMatch getMatch() {
- return this.match;
- }
-
- /**
- * Set match
- *
- * @param match
- */
- public OFPFlowMod setMatch(OFPMatch match) {
- this.match = match;
- return this;
- }
-
- /**
- * Get out_port
- *
- * @return
- */
- public int getOutPort() {
- return this.outPort;
- }
-
- /**
- * Set out_port
- *
- * @param outPort
- */
- public OFPFlowMod setOutPort(int outPort) {
- this.outPort = outPort;
- return this;
- }
-
- /**
- * Set out_port
- *
- * @param port
- */
- public OFPFlowMod setOutPort(OFPPortNo port) {
- this.outPort = port.getValue();
- return this;
- }
-
- public int getOutGroup() {
- return outGroup;
- }
-
- public void setOutGroup(int outGroup) {
- this.outGroup = outGroup;
- }
-
- /**
- * Get priority
- *
- * @return
- */
- public short getPriority() {
- return this.priority;
- }
-
- /**
- * Set priority
- *
- * @param priority
- */
- public OFPFlowMod setPriority(short priority) {
- this.priority = priority;
- return this;
- }
-
- /**
- * Returns instructions contained in this Flow Mod
- *
- * @return a list of ordered OFPInstruction objects
- */
- public List<OFPInstruction> getInstructions() {
- return this.instructions;
- }
-
- /**
- * Sets the list of instruction this Flow Mod contains
- *
- * @param instruction
- * a list of ordered OFPInstruction objects
- */
- public OFPFlowMod setInstructions(List<OFPInstruction> instructions) {
- this.instructions = instructions;
- return this;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.cookie = data.getLong();
- this.cookieMask = data.getLong();
- this.tableId = data.get();
- this.command = OFPFlowModCommand.valueOf(data.get());
- this.idleTimeout = data.getShort();
- this.hardTimeout = data.getShort();
- this.priority = data.getShort();
- this.bufferId = data.getInt();
- this.outPort = data.getInt();
- this.outGroup = data.getInt();
- this.flags = data.getShort();
- data.getShort(); // pad
- if (this.match == null)
- this.match = new OFPMatch();
- this.match.readFrom(data);
- if (this.instructionFactory == null)
- throw new RuntimeException("OFPInstructionFactory is not set");
- int instructionLength = getLengthU() - MIN_LENGTH_WITHOUT_MATCH - match.getLengthWithPadding();
- this.instructions = this.instructionFactory.parseInstructions(data, instructionLength);
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- length = getLength();
- super.writeTo(data);
- data.putLong(cookie);
- data.putLong(cookieMask);
- data.put(tableId);
- data.put(command.getValue());
- data.putShort(idleTimeout);
- data.putShort(hardTimeout);
- data.putShort(priority);
- data.putInt(bufferId);
- data.putInt(outPort);
- data.putInt(outGroup);
- data.putShort(flags);
- data.putShort((short) 0);
- this.match.writeTo(data);
- if (instructions != null) {
- for (OFPInstruction instr : instructions) {
- instr.writeTo(data);
- }
- }
- }
-
- /**
- * get length based on match and instruction length
- */
- public short getLength() {
- int totalLength = MIN_LENGTH_WITHOUT_MATCH;
- totalLength += this.match.getLengthWithPadding();
- if (instructions != null) {
- for (OFPInstruction instr : instructions) {
- totalLength += instr.getLength();
- }
- }
- length = U16.t(totalLength);
- return length;
- }
-
- @Override
- public int hashCode() {
- final int prime = 227;
- int result = super.hashCode();
- result = prime * result + ((instructions == null) ? 0 : instructions.hashCode());
- result = prime * result + bufferId;
- result = prime * result + command.getValue();
- result = prime * result + (int) (cookie ^ (cookie >>> 32));
- result = prime * result + (int) (cookieMask ^ (cookieMask >>> 32));
- result = prime * result + tableId;
- result = prime * result + flags;
- result = prime * result + hardTimeout;
- result = prime * result + idleTimeout;
- result = prime * result + ((match == null) ? 0 : match.hashCode());
- result = prime * result + outPort;
- result = prime * result + outGroup;
- result = prime * result + priority;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPFlowMod)) {
- return false;
- }
- OFPFlowMod other = (OFPFlowMod) obj;
- if (instructions == null) {
- if (other.instructions != null) {
- return false;
- }
- } else if (!instructions.equals(other.instructions)) {
- return false;
- }
- if (bufferId != other.bufferId) {
- return false;
- }
- if (command != other.command) {
- return false;
- }
- if (cookie != other.cookie) {
- return false;
- }
- if (cookieMask != other.cookieMask) {
- return false;
- }
- if (tableId != other.tableId) {
- return false;
- }
- if (flags != other.flags) {
- return false;
- }
- if (hardTimeout != other.hardTimeout) {
- return false;
- }
- if (idleTimeout != other.idleTimeout) {
- return false;
- }
- if (match == null) {
- if (other.match != null) {
- return false;
- }
- } else if (!match.equals(other.match)) {
- return false;
- }
- if (outPort != other.outPort) {
- return false;
- }
- if (outGroup != other.outGroup) {
- return false;
- }
- if (priority != other.priority) {
- return false;
- }
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#clone()
- */
- @Override
- public OFPFlowMod clone() {
- try {
- OFPMatch neoMatch = match.clone();
- OFPFlowMod flowMod = (OFPFlowMod) super.clone();
- flowMod.setMatch(neoMatch);
- List<OFPInstruction> instrList = new LinkedList<OFPInstruction>();
- for (OFPInstruction instr : this.instructions)
- instrList.add((OFPInstruction) instr.clone());
- flowMod.setInstructions(instrList);
- return flowMod;
- } catch (CloneNotSupportedException e) {
- // Won't happen
- throw new RuntimeException(e);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "OFPFlowMod [instructionFactory=" + instructionFactory + ", instructions=" + instructions
- + ", bufferId=" + bufferId + ", command=" + command + ", cookie=" + cookie + ", cookieMask="
- + cookieMask + ", tableId=" + tableId + ", flags=" + flags + ", hardTimeout=" + hardTimeout
- + ", idleTimeout=" + idleTimeout + ", match=" + match + ", outPort=" + outPort + ", outGroup="
- + outGroup + ", priority=" + priority + ", length=" + length + ", type=" + type + ", version="
- + version + ", xid=" + xid + "]";
- }
-
- @Override
- public void setInstructionFactory(OFPInstructionFactory instructionFactory) {
- this.instructionFactory = instructionFactory;
-
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-/**
- * Correspond to enum ofp_flow_mod_command
- *
- * @author AnilGujele
- *
- */
-public enum OFPFlowModCommand {
- /* New flow. */
- OFPFC_ADD((byte) 0),
- /* Modify all matching flows. */
- OFPFC_MODIFY((byte) 1),
- /* Modify entry strictly matching wildcards and priority. */
- OFPFC_MODIFY_STRICT((byte) 2),
- /* Delete all matching flows. */
- OFPFC_DELETE((byte) 3),
- /* Delete entry strictly matching wildcards and priority. */
- OFPFC_DELETE_STRICT((byte) 4);
-
- private byte value;
-
- private static OFPFlowModCommand[] mapping;
-
- OFPFlowModCommand(byte value) {
- this.value = value;
- addMapping(value, this);
- }
-
- /**
- * add mapping
- *
- * @param key
- * @param value
- */
- private static void addMapping(byte index, OFPFlowModCommand value) {
- if (null == mapping) {
- mapping = new OFPFlowModCommand[5];
- }
- mapping[index] = value;
-
- }
-
- /**
- * get the enum having this value
- *
- * @param value
- * @return
- */
- public static OFPFlowModCommand valueOf(byte value) {
- return mapping[value];
- }
-
- /**
- *
- * @return
- */
- public byte getValue() {
- return value;
- }
-
- /**
- *
- * @param value
- */
- public void setValue(byte value) {
- this.value = value;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Correspond to enum ofp_flow_mod_flags
- *
- * @author AnilGujele
- *
- */
-public enum OFPFlowModFlags {
- /* Send flow removed message when flow expires or is deleted. */
- OFPFF_SEND_FLOW_REM(1 << 0),
- /* Check for overlapping entries first. */
- OFPFF_CHECK_OVERLAP(1 << 1),
- /* Reset flow packet and byte counts. */
- OFPFF_RESET_COUNTS(1 << 2),
- /* Don't keep track of packet count. */
- OFPFF_NO_PKT_COUNTS(1 << 3),
- /* Don't keep track of byte count. */
- OFPFF_NO_BYT_COUNTS(1 << 4);
-
- private short value;
-
- private static Map<Integer, OFPFlowModFlags> mapping;
-
- OFPFlowModFlags(int value) {
- addMapping(value, this);
- this.setValue((short) value);
- }
-
- /**
- * add mapping
- *
- * @param key
- * @param value
- */
- private static void addMapping(Integer key, OFPFlowModFlags value) {
- if (null == mapping) {
- mapping = new HashMap<Integer, OFPFlowModFlags>();
- }
- mapping.put(key, value);
-
- }
-
- /**
- * get the enum having this value
- *
- * @param value
- * @return
- */
- public static OFPFlowModFlags valueOf(short value) {
- return mapping.get(value);
- }
-
- /**
- *
- * @return
- */
- public short getValue() {
- return value;
- }
-
- /**
- *
- * @param value
- */
- public void setValue(short value) {
- this.value = value;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_flow_removed message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author AnilGujele
- *
- */
-public class OFPFlowRemoved extends OFPMessage {
- public static final int MINIMUM_LENGTH = 56;
- public static final int MATCH_DEFAULT_LENGTH = 8;
- public static final int MINIMUM_LENGTH_WITHOUT_MATCH = MINIMUM_LENGTH - MATCH_DEFAULT_LENGTH;
-
- /**
- * correspond to enum ofp_flow_removed_reason
- *
- * @author AnilGujele
- *
- */
- public enum OFFlowRemovedReason {
- OFPRR_IDLE_TIMEOUT, OFPRR_HARD_TIMEOUT, OFPRR_DELETE, OFPRR_GROUP_DELETE
- }
-
- protected long cookie;
- protected short priority;
- protected OFFlowRemovedReason reason;
- protected byte tableId;
- protected int durationSeconds;
- protected int durationNanoseconds;
- protected short idleTimeout;
- protected short hardTimeout;
- protected long packetCount;
- protected long byteCount;
- protected OFPMatch match;
-
- public OFPFlowRemoved() {
- super();
- this.type = OFPType.FLOW_REMOVED;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * Get cookie
- *
- * @return
- */
- public long getCookie() {
- return this.cookie;
- }
-
- /**
- * Set cookie
- *
- * @param cookie
- */
- public void setCookie(long cookie) {
- this.cookie = cookie;
- }
-
- /**
- * Get idle_timeout
- *
- * @return
- */
- public short getIdleTimeout() {
- return this.idleTimeout;
- }
-
- /**
- * Set idle_timeout
- *
- * @param idleTimeout
- */
- public void setIdleTimeout(short idleTimeout) {
- this.idleTimeout = idleTimeout;
- }
-
- /**
- * get hard timeout
- *
- * @return
- */
- public short getHardTimeout() {
- return hardTimeout;
- }
-
- /**
- * set hard timeout
- *
- * @param hardTimeout
- */
- public void setHardTimeout(short hardTimeout) {
- this.hardTimeout = hardTimeout;
- }
-
- /**
- * Gets a copy of the OFPMatch object for this FlowMod, changes to this
- * object do not modify the FlowMod
- *
- * @return
- */
- public OFPMatch getMatch() {
- return this.match;
- }
-
- /**
- * Set match
- *
- * @param match
- */
- public void setMatch(OFPMatch match) {
- this.match = match;
- updateLength();
- }
-
- private void updateLength() {
- int matchLength = (null == this.match) ? MATCH_DEFAULT_LENGTH : this.match.getLengthWithPadding();
- this.length = (short) (OFPFlowRemoved.MINIMUM_LENGTH_WITHOUT_MATCH + matchLength);
- }
-
- /**
- * Get priority
- *
- * @return
- */
- public short getPriority() {
- return this.priority;
- }
-
- /**
- * Set priority
- *
- * @param priority
- */
- public void setPriority(short priority) {
- this.priority = priority;
- }
-
- /**
- * @return the reason
- */
- public OFFlowRemovedReason getReason() {
- return reason;
- }
-
- /**
- * @param reason
- * the reason to set
- */
- public void setReason(OFFlowRemovedReason reason) {
- this.reason = reason;
- }
-
- /**
- * get table id
- *
- * @return
- */
- public byte getTableId() {
- return tableId;
- }
-
- /**
- * set table id
- *
- * @param tableId
- */
- public void setTableId(byte tableId) {
- this.tableId = tableId;
- }
-
- /**
- * @return the durationSeconds
- */
- public int getDurationSeconds() {
- return durationSeconds;
- }
-
- /**
- * @param durationSeconds
- * the durationSeconds to set
- */
- public void setDurationSeconds(int durationSeconds) {
- this.durationSeconds = durationSeconds;
- }
-
- /**
- * @return the durationNanoseconds
- */
- public int getDurationNanoseconds() {
- return durationNanoseconds;
- }
-
- /**
- * @param durationNanoseconds
- * the durationNanoseconds to set
- */
- public void setDurationNanoseconds(int durationNanoseconds) {
- this.durationNanoseconds = durationNanoseconds;
- }
-
- /**
- * @return the packetCount
- */
- public long getPacketCount() {
- return packetCount;
- }
-
- /**
- * @param packetCount
- * the packetCount to set
- */
- public void setPacketCount(long packetCount) {
- this.packetCount = packetCount;
- }
-
- /**
- * @return the byteCount
- */
- public long getByteCount() {
- return byteCount;
- }
-
- /**
- * @param byteCount
- * the byteCount to set
- */
- public void setByteCount(long byteCount) {
- this.byteCount = byteCount;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.cookie = data.getLong();
- this.priority = data.getShort();
- this.reason = OFFlowRemovedReason.values()[(0xff & data.get())];
- this.tableId = data.get();
- this.durationSeconds = data.getInt();
- this.durationNanoseconds = data.getInt();
- this.idleTimeout = data.getShort();
- this.hardTimeout = data.getShort();
- this.packetCount = data.getLong();
- this.byteCount = data.getLong();
- if (this.match == null)
- this.match = new OFPMatch();
- this.match.readFrom(data);
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putLong(cookie);
- data.putShort(priority);
- data.put((byte) this.reason.ordinal());
- data.put((byte) tableId);
- data.putInt(this.durationSeconds);
- data.putInt(this.durationNanoseconds);
- data.putShort(idleTimeout);
- data.putShort(hardTimeout);
- data.putLong(this.packetCount);
- data.putLong(this.byteCount);
- this.match.writeTo(data);
- }
-
- @Override
- public int hashCode() {
- final int prime = 271;
- int result = super.hashCode();
- result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
- result = prime * result + (int) (cookie ^ (cookie >>> 32));
- result = prime * result + durationNanoseconds;
- result = prime * result + durationSeconds;
- result = prime * result + idleTimeout;
- result = prime * result + hardTimeout;
- result = prime * result + ((match == null) ? 0 : match.hashCode());
- result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
- result = prime * result + priority;
- result = prime * result + tableId;
- result = prime * result + ((reason == null) ? 0 : reason.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPFlowRemoved)) {
- return false;
- }
- OFPFlowRemoved other = (OFPFlowRemoved) obj;
- if (byteCount != other.byteCount) {
- return false;
- }
- if (cookie != other.cookie) {
- return false;
- }
- if (durationNanoseconds != other.durationNanoseconds) {
- return false;
- }
- if (durationSeconds != other.durationSeconds) {
- return false;
- }
- if (idleTimeout != other.idleTimeout) {
- return false;
- }
- if (hardTimeout != other.hardTimeout) {
- return false;
- }
-
- if (match == null) {
- if (other.match != null) {
- return false;
- }
- } else if (!match.equals(other.match)) {
- return false;
- }
- if (packetCount != other.packetCount) {
- return false;
- }
- if (priority != other.priority) {
- return false;
- }
- if (tableId != other.tableId) {
- return false;
- }
- if (reason == null) {
- if (other.reason != null) {
- return false;
- }
- } else if (!reason.equals(other.reason)) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-/**
- * Represents an OFPT_GET_CONFIG_REPLY type message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPGetConfigReply extends OFPSwitchConfig {
- public OFPGetConfigReply() {
- super();
- this.type = OFPType.GET_CONFIG_REPLY;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an OFPT_GET_CONFIG_REQUEST type message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPGetConfigRequest extends OFPMessage {
- public OFPGetConfigRequest() {
- super();
- this.type = OFPType.GET_CONFIG_REQUEST;
- this.length = U16.t(OFPMessage.MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.action.OFPBucket;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_group_mod message
- *
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com)
- *
- */
-public class OFPGroupMod extends OFPMessage implements Cloneable {
- public static int MINIMUM_LENGTH = 16;
-
- public static final short OFPGC_ADD = 0; /* New group. */
- public static final short OFPGC_MODIFY = 1; /* Modify all matching groups. */
- public static final short OFPGC_DELETE = 2; /* Delete all matching groups. */
-
- public static final short OFPGT_ALL = 0; /* All (multicast/broadcast) group. */
- public static final short OFPGT_SELECT = 1; /* Select group. */
- public static final short OFPGT_INDIRECT = 2; /* Indirect group. */
- public static final short OFPGT_FF = 3; /* Fast failover group. */
-
- protected short groupCommand;
- protected byte groupType;
- protected int group_id;
- protected List<OFPBucket> buckets;
-
- public OFPGroupMod() {
- super();
- this.type = OFPType.GROUP_MOD;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- public short getGroupCommand() {
- return groupCommand;
- }
-
- public OFPGroupMod setGroupCommand(short groupCommand) {
- this.groupCommand = groupCommand;
- return this;
- }
-
- public byte getGroupType() {
- return groupType;
- }
-
- public OFPGroupMod setGroupType(byte groupType) {
- this.groupType = groupType;
- return this;
- }
-
- public int getGroup_id() {
- return group_id;
- }
-
- public OFPGroupMod setGroup_id(int group_id) {
- this.group_id = group_id;
- return this;
- }
-
- public List<OFPBucket> getBuckets() {
- return buckets;
- }
-
- /**
- * @param buckets
- * the buckets to set
- */
- public OFPGroupMod setBuckets(List<OFPBucket> buckets) {
- this.buckets = buckets;
- if (buckets == null) {
- this.setLengthU(MINIMUM_LENGTH);
- } else {
- this.setLengthU(MINIMUM_LENGTH + buckets.size() * OFPBucket.MINIMUM_LENGTH);
- }
- return this;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.groupCommand = data.getShort();
- this.groupType = data.get();
- data.get();
- this.group_id = data.getInt();
- if (this.buckets == null) {
- this.buckets = new ArrayList<OFPBucket>();
- } else {
- this.buckets.clear();
- }
- int bucketCount = (super.getLengthU() - 16) / OFPBucket.MINIMUM_LENGTH;
- OFPBucket bucket;
- for (int i = 0; i < bucketCount; ++i) {
- bucket = new OFPBucket();
- bucket.readFrom(data);
- this.buckets.add(bucket);
- }
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putShort(groupCommand);
- data.put(groupType);
- data.put((byte) 0);
- data.putInt(group_id);
- if (buckets != null) {
- for (OFPBucket bucket : buckets) {
- bucket.writeTo(data);
- }
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 227;
- int result = super.hashCode();
- result = prime * result + ((buckets == null) ? 0 : buckets.hashCode());
- result = prime * result + groupCommand;
- result = prime * result + groupType;
- result = prime * result + group_id;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPGroupMod)) {
- return false;
- }
- OFPGroupMod other = (OFPGroupMod) obj;
- if (buckets == null) {
- if (other.buckets != null) {
- return false;
- }
- } else if (!buckets.equals(other.buckets)) {
- return false;
- }
- if (groupCommand != other.groupCommand) {
- return false;
- }
- if (groupType != other.groupType) {
- return false;
- }
- if (group_id != other.group_id) {
- return false;
- }
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#clone()
- */
- @Override
- public OFPGroupMod clone() {
- try {
- OFPGroupMod groupMod = (OFPGroupMod) super.clone();
- List<OFPBucket> neoBuckets = new LinkedList<OFPBucket>();
- for (OFPBucket bucket : this.buckets)
- neoBuckets.add((OFPBucket) bucket.clone());
- groupMod.setBuckets(neoBuckets);
- return groupMod;
- } catch (CloneNotSupportedException e) {
- // Won't happen
- throw new RuntimeException(e);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "OFPGroupMod [ buckets=" + buckets + ", groupCommand=" + groupCommand + ", groupType=" + groupType
- + ", group_id=" + group_id + "]";
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_hello message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu) - Feb 8, 2010
- * @author AnilGujele
- */
-public class OFPHello extends OFPMessage {
- public static int MINIMUM_LENGTH = 8;
- private List<OFPHelloElemHeader> elements;
-
- /**
- * Construct a ofp_hello message
- */
- public OFPHello() {
- super();
- this.type = OFPType.HELLO;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * get hello elements
- *
- * @return
- */
- public List<OFPHelloElemHeader> getHelloElements() {
- return elements;
- }
-
- /**
- * set hello elements
- *
- * @param elements
- */
- public void setHelloElements(List<OFPHelloElemHeader> elements) {
- this.elements = elements;
- updateLength();
- }
-
- /**
- * update length
- */
- private void updateLength() {
- int newLength = OFPHello.MINIMUM_LENGTH;
- if (null != elements) {
- for (OFPHelloElemHeader elem : elements) {
- newLength += elem.getLengthU();
- }
- }
- this.length = (short) newLength;
- }
-
- /**
- * read OFPHello from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- int elementsLength = this.getLengthU() - OFPHello.MINIMUM_LENGTH;
- this.elements = readHelloElements(data, elementsLength);
-
- }
-
- /**
- * read hello element
- *
- * @param data
- * @param length
- * @return
- */
- private List<OFPHelloElemHeader> readHelloElements(IDataBuffer data, int length) {
- List<OFPHelloElemHeader> results = null;
- OFPHelloElemHeader tempElem = new OFPHelloElemHeader();
- OFPHelloElemHeader ofHelloElem;
- int end = data.position() + length;
-
- while (data.position() <= end) {
- if (data.remaining() < OFPHelloElemHeader.MINIMUM_LENGTH
- || (data.position() + OFPHelloElemHeader.MINIMUM_LENGTH) > end)
- return results;
-
- // to read element type
- data.mark();
- tempElem.readFrom(data);
- data.reset();
-
- if (tempElem.getLengthU() > data.remaining() || (data.position() + tempElem.getLengthU()) > end)
- return results;
-
- if (null == tempElem.getOFHelloElemType()) {
- // element is not supported, so forward the position
- data.position(data.position() + tempElem.getLengthU());
- continue;
- }
- // create instance of element type
- ofHelloElem = tempElem.getOFHelloElemType().newInstance();
- // read hello element from data
- ofHelloElem.readFrom(data);
- if (null == results) {
- results = new ArrayList<OFPHelloElemHeader>();
- }
- results.add(ofHelloElem);
- }
- return results;
- }
-
- /**
- * write OFPHello to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- if (null != elements) {
- for (OFPHelloElemHeader elem : elements) {
- elem.writeTo(data);
- }
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 764;
- int result = super.hashCode();
- result = prime * result + ((null == elements) ? 0 : elements.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPHello)) {
- return false;
- }
- OFPHello other = (OFPHello) obj;
- if (elements == null) {
- if (other.elements != null) {
- return false;
- }
- } else if (!elements.equals(other.elements)) {
- return false;
- }
-
- return true;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.io.Serializable;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents struct ofp_hello_elem_header
- *
- * @author AnilGujele
- *
- */
-public class OFPHelloElemHeader implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- public static final short MINIMUM_LENGTH = 4;
-
- protected OFPHelloElemType type;
- protected short length;
-
- /**
- * get the length
- *
- * @return
- */
- public short getLength() {
- return length;
- }
-
- /**
- * set the length
- *
- * @param length
- */
- public void setLength(short length) {
- this.length = length;
- }
-
- /**
- * get the unsigned length of instruction structure
- *
- * @return
- */
- public int getLengthU() {
- return U16.f(length);
- }
-
- /**
- * get the OFPHelloElemType
- *
- * @return
- */
- public OFPHelloElemType getOFHelloElemType() {
- return type;
- }
-
- /**
- * set the OFPHelloElemType
- *
- * @param type
- */
- public void setOFHelloElemType(OFPHelloElemType type) {
- this.type = type;
- }
-
- /**
- * read OFPHelloElemHeader object state from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- this.type = OFPHelloElemType.valueOf(data.getShort());
- this.length = data.getShort();
- }
-
- /**
- * write OFPHelloElemHeader object state to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- data.putShort(type.getTypeValue());
- data.putShort(this.length);
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 761;
- int result = 1;
- result = prime * result + length;
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPHelloElemHeader)) {
- return false;
- }
- OFPHelloElemHeader other = (OFPHelloElemHeader) obj;
- if (length != other.length) {
- return false;
- }
- if (type == null) {
- if (other.type != null) {
- return false;
- }
- } else if (!type.equals(other.type)) {
- return false;
- }
- return true;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Represents struct ofp_hello_elem_type
- *
- * @author AnilGujele
- *
- */
-public enum OFPHelloElemType {
- /* Bitmap of version supported. */
- VERSIONBITMAP((short) 1, new Instantiable<OFPHelloElemHeader>() {
- @Override
- public OFPHelloElemHeader instantiate() {
- return new OFPHelloElemVersionBitmap();
- }
- });
-
- private static Map<Short, OFPHelloElemType> mapping;
-
- private short type;
-
- private Instantiable<OFPHelloElemHeader> instantiable;
-
- /**
- *
- * @param type
- */
- OFPHelloElemType(short type, Instantiable<OFPHelloElemHeader> instantiable) {
- this.setTypeValue(type);
- OFPHelloElemType.addMapping(type, this);
- this.instantiable = instantiable;
- }
-
- /**
- * add mapping to store
- *
- * @param type
- * @param helloElementType
- */
- private static void addMapping(short type, OFPHelloElemType helloElementType) {
- if (null == mapping) {
- mapping = new HashMap<Short, OFPHelloElemType>();
- }
- mapping.put(type, helloElementType);
- }
-
- /**
- * get OFHelloElementType correspond to value type
- *
- * @param type
- * @return OFHelloElementType
- */
- public static OFPHelloElemType valueOf(short type) {
- return mapping.get(type);
- }
-
- /**
- * get HelloElement type value
- *
- * @return
- */
- public short getTypeValue() {
- return type;
- }
-
- /**
- * set HelloElement type value
- *
- * @param type
- */
- public void setTypeValue(short type) {
- this.type = type;
- }
-
- /**
- * Returns a new instance of the OFPHelloElemHeader represented by this
- * OFPHelloElemType
- *
- * @return the new object
- */
- public OFPHelloElemHeader newInstance() {
- return instantiable.instantiate();
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.Arrays;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents struct ofp_hello_elem_versionbitmap
- *
- *
- * @author AnilGujele
- *
- */
-public class OFPHelloElemVersionBitmap extends OFPHelloElemHeader {
- private static final short MINIMUM_LENGTH = 4;
- private static final int INT_SIZE = 4;
-
- private int[] bitmaps;
-
- /**
- * constructor
- */
- public OFPHelloElemVersionBitmap() {
- super.setOFHelloElemType(OFPHelloElemType.VERSIONBITMAP);
- super.setLength(MINIMUM_LENGTH);
- }
-
- /**
- * get bitmaps
- *
- * @return
- */
- public int[] getBitmaps() {
- return bitmaps;
- }
-
- /**
- * set bitmaps
- *
- * @param bitmaps
- */
- public void setBitmaps(int[] bitmaps) {
- this.bitmaps = bitmaps;
- updateLength();
- }
-
- private void updateLength() {
- int newLength = ((null == bitmaps) ? 0 : bitmaps.length * INT_SIZE);
- this.length = (short) (OFPHelloElemVersionBitmap.MINIMUM_LENGTH + newLength);
- }
-
- /**
- * read OFPHelloElemVersionBitmap from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- int bitmapLength = this.getLengthU() - OFPHelloElemVersionBitmap.MINIMUM_LENGTH;
- int end = data.position() + bitmapLength;
- bitmaps = new int[bitmapLength / INT_SIZE];
- for (int i = 0; ((data.position() + INT_SIZE) <= end); i++) {
- this.bitmaps[i] = data.getInt();
- }
-
- }
-
- /**
- * write OFPHelloElemVersionBitmap to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- if (null == bitmaps) {
- bitmaps = new int[0];
- }
- for (int bitmap : bitmaps) {
- data.putInt(bitmap);
- }
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 762;
- int result = super.hashCode();
- result = prime * result + Arrays.hashCode(bitmaps);
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPHelloElemVersionBitmap)) {
- return false;
- }
- OFPHelloElemVersionBitmap other = (OFPHelloElemVersionBitmap) obj;
- if (!Arrays.equals(bitmaps, other.bitmaps)) {
- return false;
- }
- return true;
- }
-
- /**
- * Returns a string representation of the hello element
- */
- public String toString() {
- return "OFPHelloElemVersionBitmap[" + "type=" + this.getOFHelloElemType() + ", length=" + this.getLength()
- + ", bitmaps=" + Arrays.toString(bitmaps) + "]";
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an ofp_match structure
- *
- * @author AnilGujele
- *
- */
-public class OFPMatch implements Cloneable, Serializable {
- /**
- * serialization id
- */
- private static final long serialVersionUID = 1L;
- private static final short MINIMUM_LENGTH = 4;
- /**
- * Match size should be multiple of eight, so padding will be done based on
- * length of match.
- */
- private static final int MULTIPLE_OF_EIGHT = 8;
-
- private OFPMatchType matchType;
- private short length;
- private Map<String, OXMField> fieldMap;
-
- /**
- * constructor
- */
- public OFPMatch() {
- matchType = OFPMatchType.OFPMT_OXM;
- setLength(MINIMUM_LENGTH); // all match fields are wild card
- fieldMap = new HashMap<String, OXMField>();
- }
-
- /**
- * add match field
- *
- * @param matchField
- */
- public void addMatchField(OXMField matchField) {
- fieldMap.put(matchField.getMatchField().name(), matchField);
-
- }
-
- /**
- * remove match field
- *
- * @param matchField
- */
- public void removeMatchField(OXMField matchField) {
- fieldMap.remove(matchField.getMatchField().name());
- }
-
- /**
- * get the length OFPMatch TLV
- *
- * @return
- */
- public short getLength() {
- length = OFPMatch.MINIMUM_LENGTH;
- for (Map.Entry<String, OXMField> entry : fieldMap.entrySet()) {
- length += entry.getValue().getLength();
- }
- return length;
- }
-
- /**
- * get the length OFPMatch TLV
- *
- * @return
- */
- public short getLengthWithPadding() {
- int matchLength = getLength();
- int paddingLength = ((matchLength % MULTIPLE_OF_EIGHT) == 0) ? 0
- : (MULTIPLE_OF_EIGHT - (matchLength % MULTIPLE_OF_EIGHT));
- length = (short) (matchLength + paddingLength);
- return length;
- }
-
- /**
- * set the length of OFPMatch TLV
- *
- * @param length
- */
- public void setLength(short length) {
- this.length = length;
- }
-
- /**
- * get the matchfield map
- *
- * @return
- */
- public Map<String, OXMField> getMatchFieldMap() {
- return fieldMap;
- }
-
- /**
- * set the matchfield map
- *
- * @param fieldMap
- */
- public void setMatchFieldMap(Map<String, OXMField> fieldMap) {
- this.fieldMap = fieldMap;
- }
-
- /**
- * Read this match from the specified DataBuffer
- *
- * @param data
- * - data to read to construct match object
- * @return true - reading is successful , false - failed to read as data is
- * not proper or prerequisite is not matched
- */
- public boolean readFrom(IDataBuffer data) {
- boolean result = false;
- this.matchType = OFPMatchType.valueOf(data.getShort());
- // check for valid match type
- // if not match then either match type is deprecated or not supported
- if (matchType == OFPMatchType.OFPMT_OXM) {
- int length = data.getShort();
- if (length >= MINIMUM_LENGTH) {
- // match size will be multiple of 8, so need to handle padding
- // if any
- int paddingLength = ((length % MULTIPLE_OF_EIGHT) == 0) ? 0
- : (MULTIPLE_OF_EIGHT - (length % MULTIPLE_OF_EIGHT));
- // length = length - MINIMUM_LENGTH - paddingLength;
- /* length of ofp_match, is excluding the padding */
- length = length - MINIMUM_LENGTH;
- // read match field
- while (length > 0) {
- OXMField oxmField = new OXMField();
- if (!oxmField.readFrom(data)) {
- // data is not valid, so log, move the data pointer and
- // return;
- byte[] junkData = new byte[length + paddingLength];
- data.get(junkData);
- return false;
- }
-
- length = length - oxmField.getLength();
- this.addMatchField(oxmField);
- this.length += oxmField.getLength();
- result = true;
-
- }
- // remove padding bytes
- byte[] pad = new byte[paddingLength];
- data.get(pad);
- // result = MatchUtil.hasPrerequisite(this);
- }
- }
- return result;
-
- }
-
- /**
- * Write this match binary format to the specified DataBuffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- // TBD - we should proceed if prerequisite matching
- // MatchUtil.hasPrerequisite(this);
- data.putShort(matchType.getMatchTypeValue());
- data.putShort(getLength());
- for (Map.Entry<String, OXMField> entry : fieldMap.entrySet()) {
- OXMField field = entry.getValue();
- field.writeTo(data);
- }
- // match size should be multiple of 8, so need to handle padding if any
- int paddingLength = ((getLength() % MULTIPLE_OF_EIGHT) == 0) ? 0
- : (MULTIPLE_OF_EIGHT - (getLength() % MULTIPLE_OF_EIGHT));
- // add padding bytes
- byte[] pad = new byte[paddingLength];
- data.put(pad);
-
- }
-
- /**
- * create the clone of this OFPMatch
- *
- */
- @Override
- public OFPMatch clone() {
- try {
- OFPMatch clonedOFMatch = (OFPMatch) super.clone();
- clonedOFMatch.fieldMap = new HashMap<String, OXMField>();
- for (Map.Entry<String, OXMField> entry : fieldMap.entrySet()) {
- clonedOFMatch.fieldMap.put(entry.getKey(), entry.getValue().clone());
- }
- return clonedOFMatch;
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * to get the object hashcode
- *
- * @return
- */
- public int hashCode() {
- final int prime = 722;
- int result = prime + this.getLength();
- result = prime * result + this.matchType.getMatchTypeValue();
- result = prime * result + this.fieldMap.hashCode();
- return result;
- }
-
- /**
- * to check object equality
- */
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (null == obj) {
- return false;
- }
- if (!(obj instanceof OFPMatch)) {
- return false;
- }
- OFPMatch other = (OFPMatch) obj;
- if (this.matchType != other.matchType) {
- return false;
- }
- if (this.getLength() != other.getLength()) {
- return false;
- }
-
- if (!this.fieldMap.equals(other.fieldMap)) {
- return false;
- }
-
- return true;
- }
-
- /**
- * String representation of Match object ex: OFPMatch[MatchType=OFPMT_OXM,
- * Length=12, Match Fields[Type=OPENFLOW_BASIC-IPV4_SRC, Length=8, Value=[1,
- * 2, 3, 4]]]
- */
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append("OFPMatch[");
- buffer.append("MatchType=").append(matchType);
- buffer.append(", Length=").append(getLength());
- buffer.append(", Match Fields[");
- int index = fieldMap.size();
- for (Map.Entry<String, OXMField> entry : fieldMap.entrySet()) {
- OXMField field = entry.getValue();
- buffer.append(field.toString());
- if (0 != --index) {
- buffer.append(",");
- }
- }
- buffer.append("]]");
- return buffer.toString();
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.beans.IntrospectionException;
-import java.beans.PropertyDescriptor;
-import java.beans.SimpleBeanInfo;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Extra info for how to treat OFPMatch as a JavaBean
- *
- * For some (inane!) reason, using chained setters in OFPMatch breaks a lot of
- * the JavaBean defaults.
- *
- * We don't really use OFPMatch as a java bean, but there are a lot of nice XML
- * utils that work for free if OFPMatch follows the java bean paradigm.
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- *
- */
-
-public class OFPMatchBeanInfo extends SimpleBeanInfo {
-
- @Override
- public PropertyDescriptor[] getPropertyDescriptors() {
- List<PropertyDescriptor> descs = new LinkedList<PropertyDescriptor>();
- Field[] fields = OFPMatch.class.getDeclaredFields();
- String name;
- for (int i = 0; i < fields.length; i++) {
- int mod = fields[i].getModifiers();
- if (Modifier.isFinal(mod) || // don't expose static or final fields
- Modifier.isStatic(mod))
- continue;
-
- name = fields[i].getName();
- Class<?> type = fields[i].getType();
-
- try {
- descs.add(new PropertyDescriptor(name, name2getter(OFPMatch.class, name), name2setter(OFPMatch.class,
- name, type)));
- } catch (IntrospectionException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
- return descs.toArray(new PropertyDescriptor[0]);
- }
-
- private Method name2setter(Class<OFPMatch> c, String name, Class<?> type) {
- String mName = "set" + toLeadingCaps(name);
- Method m = null;
- try {
- m = c.getMethod(mName, new Class[] { type });
- } catch (SecurityException e) {
-
- e.printStackTrace();
- throw new RuntimeException(e);
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- return m;
- }
-
- private Method name2getter(Class<OFPMatch> c, String name) {
- String mName = "get" + toLeadingCaps(name);
- Method m = null;
- try {
- m = c.getMethod(mName, new Class[] {});
- } catch (SecurityException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- return m;
- }
-
- private String toLeadingCaps(String s) {
- char[] array = s.toCharArray();
- array[0] = Character.toUpperCase(array[0]);
- return String.valueOf(array, 0, array.length);
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-/**
- * Represents enum ofp_match_type
- *
- * @author AnilGujele
- *
- */
-public enum OFPMatchType {
- OFPMT_STANDARD((short) 0), OFPMT_OXM((short) 1);
-
- private short type;
- private static OFPMatchType[] mapping;
-
- /**
- * constructor
- *
- * @param value
- */
- private OFPMatchType(short value) {
- type = value;
- addMapping(type, this);
-
- }
-
- /**
- * add mapping for match type
- *
- * @param index
- * - match type value is index
- * @param matchType
- * - match type instance is value
- */
- private static void addMapping(short index, OFPMatchType matchType) {
- if (null == mapping) {
- mapping = new OFPMatchType[2];
- }
- mapping[index] = matchType;
-
- }
-
- /**
- * get match type from value
- *
- * @param value
- * @return
- */
- public static OFPMatchType valueOf(short value) {
- return mapping[value];
- }
-
- /**
- * get match type value
- *
- * @return
- */
- public short getMatchTypeValue() {
- return type;
- }
-
- /**
- * set match type value
- *
- * @param type
- */
- public void setMatchTypeValue(short type) {
- this.type = type;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.io.Serializable;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-import org.openflow.codec.util.U32;
-import org.openflow.codec.util.U8;
-
-/**
- * The base class for all OpenFlow protocol messages. This class contains the
- * equivalent of the ofp_header which is present in all OpenFlow messages.
- *
- * @author David Erickson (daviderickson@cs.stanford.edu) - Feb 3, 2010
- * @author Rob Sherwood (rob.sherwood@stanford.edu) - Feb 3, 2010
- */
-public class OFPMessage implements Serializable {
- public static byte OFP_VERSION = 0x04;
- public static int MINIMUM_LENGTH = 8;
-
- protected byte version;
- protected OFPType type;
- protected short length;
- protected int xid;
-
- public OFPMessage() {
- this.version = OFP_VERSION;
- }
-
- /**
- * Get the length of this message
- *
- * @return
- */
- public short getLength() {
- return length;
- }
-
- /**
- * Get the length of this message, unsigned
- *
- * @return
- */
- public int getLengthU() {
- return U16.f(length);
- }
-
- /**
- * Set the length of this message
- *
- * @param length
- */
- public OFPMessage setLength(short length) {
- this.length = length;
- return this;
- }
-
- /**
- * Set the length of this message, unsigned
- *
- * @param length
- */
- public OFPMessage setLengthU(int length) {
- this.length = U16.t(length);
- return this;
- }
-
- /**
- * Get the type of this message
- *
- * @return
- */
- public OFPType getType() {
- return type;
- }
-
- /**
- * Set the type of this message
- *
- * @param type
- */
- public void setType(OFPType type) {
- this.type = type;
- }
-
- /**
- * Get the OpenFlow version of this message
- *
- * @return
- */
- public byte getVersion() {
- return version;
- }
-
- /**
- * Set the OpenFlow version of this message
- *
- * @param version
- */
- public void setVersion(byte version) {
- this.version = version;
- }
-
- /**
- * Get the transaction id of this message
- *
- * @return
- */
- public int getXid() {
- return xid;
- }
-
- /**
- * Set the transaction id of this message
- *
- * @param xid
- */
- public void setXid(int xid) {
- this.xid = xid;
- }
-
- /**
- * Read this message off the wire from the specified DataBuffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- this.version = data.get();
- this.type = OFPType.valueOf(data.get());
- this.length = data.getShort();
- this.xid = data.getInt();
- }
-
- /**
- * Write this message's binary format to the specified DataBuffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- data.put(version);
- data.put(type.getTypeValue());
- data.putShort(length);
- data.putInt(xid);
- }
-
- /**
- * Returns a summary of the message
- *
- * @return "ofmsg=v=$version;t=$type:l=$len:xid=$xid"
- */
- public String toString() {
- return "ofmsg" + ":v=" + U8.f(this.getVersion()) + ";t=" + this.getType() + ";l=" + this.getLengthU() + ";x="
- + U32.f(this.getXid());
- }
-
- @Override
- public int hashCode() {
- final int prime = 97;
- int result = 1;
- result = prime * result + length;
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- result = prime * result + version;
- result = prime * result + xid;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPMessage)) {
- return false;
- }
- OFPMessage other = (OFPMessage) obj;
- if (length != other.length) {
- return false;
- }
- if (type == null) {
- if (other.type != null) {
- return false;
- }
- } else if (!type.equals(other.type)) {
- return false;
- }
- if (version != other.version) {
- return false;
- }
- if (xid != other.xid) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.factory.OFPStatisticsFactory;
-import org.openflow.codec.protocol.factory.OFPStatisticsFactoryAware;
-import org.openflow.codec.protocol.statistics.OFPMultipartTypes;
-import org.openflow.codec.protocol.statistics.OFPStatistics;
-
-/**
- * Base class for Multipart requests/replies
- *
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 27, 2010
- * @author AnilGujele
- */
-public abstract class OFPMultipartMessageBase extends OFPMessage implements OFPStatisticsFactoryAware {
- public static int MINIMUM_LENGTH = 16;
-
- protected OFPStatisticsFactory statisticsFactory;
- protected OFPMultipartTypes multipartType;
- protected short flags;
- protected List<OFPStatistics> statistics;
-
- /**
- * @return the multipartType
- */
- public OFPMultipartTypes getMultipartType() {
- return multipartType;
- }
-
- /**
- * @param multipartType
- * the multipartType to set
- */
- public void setMultipartType(OFPMultipartTypes multipartType) {
- this.multipartType = multipartType;
- }
-
- /**
- * @return the flags
- */
- public short getFlags() {
- return flags;
- }
-
- /**
- * @param flags
- * the flags to set
- */
- public void setFlags(short flags) {
- this.flags = flags;
- }
-
- /**
- * @return the statistics
- */
- public List<OFPStatistics> getStatistics() {
- return statistics;
- }
-
- /**
- * @param statistics
- * the statistics to set
- */
- public void setStatistics(List<OFPStatistics> statistics) {
- this.statistics = statistics;
- }
-
- @Override
- public void setStatisticsFactory(OFPStatisticsFactory statisticsFactory) {
- this.statisticsFactory = statisticsFactory;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.multipartType = OFPMultipartTypes.valueOf(data.getShort(), this.getType());
- this.flags = data.getShort();
- data.getInt(); // pad
- if (this.statisticsFactory == null)
- throw new RuntimeException("OFPStatisticsFactory not set");
- this.statistics = statisticsFactory.parseStatistics(this.getType(), this.multipartType, data,
- super.getLengthU() - MINIMUM_LENGTH);
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putShort(this.multipartType.getTypeValue());
- data.putShort(this.flags);
- data.putInt(0); // pad
- if (this.statistics != null) {
- for (OFPStatistics statistic : this.statistics) {
- statistic.writeTo(data);
- }
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 317;
- int result = super.hashCode();
- result = prime * result + flags;
- result = prime * result + ((multipartType == null) ? 0 : multipartType.hashCode());
- result = prime * result + ((statistics == null) ? 0 : statistics.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPMultipartMessageBase)) {
- return false;
- }
- OFPMultipartMessageBase other = (OFPMultipartMessageBase) obj;
- if (flags != other.flags) {
- return false;
- }
- if (multipartType == null) {
- if (other.multipartType != null) {
- return false;
- }
- } else if (!multipartType.equals(other.multipartType)) {
- return false;
- }
- if (statistics == null) {
- if (other.statistics != null) {
- return false;
- }
- } else if (!statistics.equals(other.statistics)) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_multipart_reply message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPMultipartReply extends OFPMultipartMessageBase {
-
- /**
- * Represents an ofp_multipart_reply_flags
- *
- * @author AnilGujele
- *
- */
- public enum OFMultipartReplyFlags {
- REPLY_MORE(1 << 0);
-
- protected short type;
-
- OFMultipartReplyFlags(int type) {
- this.type = (short) type;
- }
-
- public short getTypeValue() {
- return type;
- }
- }
-
- public OFPMultipartReply() {
- super();
- this.type = OFPType.MULTIPART_REPLY;
- this.length = U16.t(OFPMultipartMessageBase.MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_multipart_request message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPMultipartRequest extends OFPMultipartMessageBase {
-
- /**
- * Represents an ofp_multipart_request_flags
- *
- * @author AnilGujele
- *
- */
- public enum OFMultipartRequestFlags {
- REQ_MORE(1 << 0);
-
- protected short type;
-
- OFMultipartRequestFlags(int type) {
- this.type = (short) type;
- }
-
- public short getTypeValue() {
- return type;
- }
- }
-
- public OFPMultipartRequest() {
- super();
- this.type = OFPType.MULTIPART_REQUEST;
- this.length = U16.t(OFPMultipartMessageBase.MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.Arrays;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-import org.openflow.codec.util.U8;
-
-/**
- * Represents an ofp_packet_in
- *
- * @author David Erickson (daviderickson@cs.stanford.edu) - Feb 8, 2010
- * @author AnilGujele
- */
-public class OFPPacketIn extends OFPMessage {
- public static int MINIMUM_LENGTH = 32;
- public static int MINIMUM_LENGTH_WITHOUT_MATCH = MINIMUM_LENGTH - 8;
-
- public enum OFPacketInReason {
- NO_MATCH, ACTION, INVALID_TTL
- }
-
- protected int bufferId;
- protected short totalLength;
- protected OFPacketInReason reason;
- protected byte tableId;
- protected long cookie;
- protected OFPMatch match;
- protected byte[] packetData;
-
- public OFPPacketIn() {
- super();
- this.type = OFPType.PACKET_IN;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * Get buffer_id
- *
- * @return
- */
- public int getBufferId() {
- return this.bufferId;
- }
-
- /**
- * Set buffer_id
- *
- * @param bufferId
- */
- public OFPPacketIn setBufferId(int bufferId) {
- this.bufferId = bufferId;
- return this;
- }
-
- /**
- * Returns the packet data
- *
- * @return
- */
- public byte[] getPacketData() {
- return this.packetData;
- }
-
- /**
- * Sets the packet data, and updates the length of this message
- *
- * @param packetData
- */
- public OFPPacketIn setPacketData(byte[] packetData) {
- this.packetData = packetData;
- updateLength();
- return this;
- }
-
- private void updateLength() {
- short matchLength = (null == match) ? 0 : match.getLengthWithPadding();
- int packetDataLength = (null == packetData) ? 0 : packetData.length;
- int len = OFPPacketIn.MINIMUM_LENGTH_WITHOUT_MATCH + matchLength + packetDataLength;
- this.length = (short) len;
- }
-
- /**
- * Get reason
- *
- * @return
- */
- public OFPacketInReason getReason() {
- return this.reason;
- }
-
- /**
- * Set reason
- *
- * @param reason
- */
- public OFPPacketIn setReason(OFPacketInReason reason) {
- this.reason = reason;
- return this;
- }
-
- /**
- * get table id
- *
- * @return
- */
- public byte getTableId() {
- return tableId;
- }
-
- /**
- * set table id
- *
- * @param tableId
- */
- public void setTableId(byte tableId) {
- this.tableId = tableId;
- }
-
- /**
- * get cookie
- *
- * @return
- */
- public long getCookie() {
- return cookie;
- }
-
- /**
- * set cookie
- *
- * @param cookie
- */
- public void setCookie(long cookie) {
- this.cookie = cookie;
- }
-
- /**
- * get match
- *
- * @return
- */
- public OFPMatch getMatch() {
- return match;
- }
-
- /**
- * set match
- *
- * @param match
- */
- public void setMatch(OFPMatch match) {
- this.match = match;
- updateLength();
- }
-
- /**
- * Get total_len
- *
- * @return
- */
- public short getTotalLength() {
- return this.totalLength;
- }
-
- /**
- * Set total_len
- *
- * @param totalLength
- */
- public OFPPacketIn setTotalLength(short totalLength) {
- this.totalLength = totalLength;
- return this;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.bufferId = data.getInt();
- this.totalLength = data.getShort();
- this.reason = OFPacketInReason.values()[U8.f(data.get())];
- this.tableId = data.get();
- this.cookie = data.getLong();
- this.match = new OFPMatch();
- match.readFrom(data);
- // TBD - how to handle the padding here
- data.getShort(); // pad
- this.packetData = new byte[getLengthU() - OFPPacketIn.MINIMUM_LENGTH_WITHOUT_MATCH
- - match.getLengthWithPadding()];
- data.get(this.packetData);
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(bufferId);
- data.putShort(totalLength);
- data.put((byte) reason.ordinal());
- data.put(tableId);
- data.putLong(cookie);
- if (null != match) {
- match.writeTo(data);
- }
- data.putShort((short) 0); // pad
- data.put(this.packetData);
- }
-
- @Override
- public int hashCode() {
- final int prime = 283;
- int result = super.hashCode();
- result = prime * result + bufferId;
- result = prime * result + tableId;
- result = prime * result + (int) (cookie ^ (cookie >>> 32));
- result = prime * result + ((null == match) ? 0 : match.hashCode());
- result = prime * result + Arrays.hashCode(packetData);
- result = prime * result + ((reason == null) ? 0 : reason.hashCode());
- result = prime * result + totalLength;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPPacketIn)) {
- return false;
- }
- OFPPacketIn other = (OFPPacketIn) obj;
- if (bufferId != other.bufferId) {
- return false;
- }
- if (tableId != other.tableId) {
- return false;
- }
- if (match == null) {
- if (other.match != null) {
- return false;
- }
- } else if (!match.equals(other.match)) {
- return false;
- }
- if (!Arrays.equals(packetData, other.packetData)) {
- return false;
- }
- if (reason == null) {
- if (other.reason != null) {
- return false;
- }
- } else if (!reason.equals(other.reason)) {
- return false;
- }
- if (totalLength != other.totalLength) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.action.OFPAction;
-import org.openflow.codec.protocol.factory.OFPActionFactory;
-import org.openflow.codec.protocol.factory.OFPActionFactoryAware;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_packet_out message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 12, 2010
- */
-public class OFPPacketOut extends OFPMessage implements OFPActionFactoryAware {
- public static int MINIMUM_LENGTH = 24;
- public static int BUFFER_ID_NONE = 0xffffffff;
-
- protected OFPActionFactory actionFactory;
- protected int bufferId;
- protected int inPort;
- protected short actionsLength;
- protected List<OFPAction> actions;
- protected byte[] packetData;
-
- public OFPPacketOut() {
- super();
- this.type = OFPType.PACKET_OUT;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * Get buffer_id
- *
- * @return
- */
- public int getBufferId() {
- return this.bufferId;
- }
-
- /**
- * Set buffer_id
- *
- * @param bufferId
- */
- public OFPPacketOut setBufferId(int bufferId) {
- this.bufferId = bufferId;
- return this;
- }
-
- /**
- * Returns the packet data
- *
- * @return
- */
- public byte[] getPacketData() {
- return this.packetData;
- }
-
- /**
- * Sets the packet data
- *
- * @param packetData
- */
- public OFPPacketOut setPacketData(byte[] packetData) {
- this.packetData = packetData;
- updateLength();
- return this;
- }
-
- private void updateLength() {
- short newLength = (short) ((packetData == null) ? 0 : packetData.length);
- this.length = newLength;
- }
-
- /**
- * Get in_port
- *
- * @return
- */
- public int getInPort() {
- return this.inPort;
- }
-
- /**
- * Set in_port
- *
- * @param inPort
- */
- public OFPPacketOut setInPort(int inPort) {
- this.inPort = inPort;
- return this;
- }
-
- /**
- * Set in_port. Convenience method using OFPPort enum.
- *
- * @param inPort
- */
- public OFPPacketOut setInPort(OFPPortNo inPort) {
- this.inPort = inPort.getValue();
- return this;
- }
-
- /**
- * Get actions_len
- *
- * @return
- */
- public short getActionsLength() {
- return this.actionsLength;
- }
-
- /**
- * Get actions_len, unsigned
- *
- * @return
- */
- public int getActionsLengthU() {
- return U16.f(this.actionsLength);
- }
-
- /**
- * Set actions_len
- *
- * @param actionsLength
- */
- public OFPPacketOut setActionsLength(short actionsLength) {
- this.actionsLength = actionsLength;
- return this;
- }
-
- /**
- * Returns the actions contained in this message
- *
- * @return a list of ordered OFPAction objects
- */
- public List<OFPAction> getActions() {
- return this.actions;
- }
-
- /**
- * Sets the list of actions on this message
- *
- * @param actions
- * a list of ordered OFPAction objects
- */
- public OFPPacketOut setActions(List<OFPAction> actions) {
- this.actions = actions;
- return this;
- }
-
- @Override
- public void setActionFactory(OFPActionFactory actionFactory) {
- this.actionFactory = actionFactory;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.bufferId = data.getInt();
- this.inPort = data.getInt();
- this.actionsLength = data.getShort();
- data.getInt(); // pad
- data.getShort(); // pad
- if (this.actionFactory == null)
- throw new RuntimeException("ActionFactory not set");
- this.actions = this.actionFactory.parseActions(data, getActionsLengthU());
- this.packetData = new byte[getLengthU() - MINIMUM_LENGTH - getActionsLengthU()];
- data.get(this.packetData);
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(bufferId);
- data.putInt(inPort);
- data.putShort(actionsLength);
- data.putInt(0); // pad
- data.putShort((short) 0); // pad
- for (OFPAction action : actions) {
- action.writeTo(data);
- }
- if (this.packetData != null)
- data.put(this.packetData);
- }
-
- @Override
- public int hashCode() {
- final int prime = 293;
- int result = super.hashCode();
- result = prime * result + ((actions == null) ? 0 : actions.hashCode());
- result = prime * result + actionsLength;
- result = prime * result + bufferId;
- result = prime * result + inPort;
- result = prime * result + Arrays.hashCode(packetData);
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPPacketOut)) {
- return false;
- }
- OFPPacketOut other = (OFPPacketOut) obj;
- if (actions == null) {
- if (other.actions != null) {
- return false;
- }
- } else if (!actions.equals(other.actions)) {
- return false;
- }
- if (actionsLength != other.actionsLength) {
- return false;
- }
- if (bufferId != other.bufferId) {
- return false;
- }
- if (inPort != other.inPort) {
- return false;
- }
- if (!Arrays.equals(packetData, other.packetData)) {
- return false;
- }
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "OFPPacketOut [actionFactory=" + actionFactory + ", actions=" + actions + ", actionsLength="
- + actionsLength + ", bufferId=0x" + Integer.toHexString(bufferId) + ", inPort=" + inPort
- + ", packetData=" + Arrays.toString(packetData) + "]";
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.io.Serializable;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-import java.util.Arrays;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.StringByteSerializer;
-
-/**
- * Represents an ofp_port structure
- *
- * @author AnilGujele
- */
-public class OFPPort implements Cloneable, Serializable {
- protected static int MINIMUM_LENGTH = 64;
- protected static int OFP_ETH_ALEN = 6;
-
- /**
- * represents ofp_port_config
- *
- */
- public enum OFPortConfig {
- OFPPC_PORT_DOWN(1 << 0), OFPPC_NO_RECV(1 << 2), OFPPC_NO_FWD(1 << 5), OFPPC_NO_PACKET_IN(1 << 6);
-
- protected int value;
-
- private OFPortConfig(int value) {
- this.value = value;
- }
-
- /**
- * @return the value
- */
- public int getValue() {
- return value;
- }
- }
-
- /**
- * represents ofp_port_state
- *
- */
- public enum OFPortState {
- OFPPS_LINK_DOWN(1 << 0), OFPPS_BLOCKED(1 << 1), OFPPS_LIVE(1 << 2);
-
- protected int value;
-
- private OFPortState(int value) {
- this.value = value;
- }
-
- /**
- * @return the value
- */
- public int getValue() {
- return value;
- }
- }
-
- /**
- * represents ofp_port_features
- *
- */
- public enum OFPortFeatures {
- OFPPF_10MB_HD(1 << 0), OFPPF_10MB_FD(1 << 1), OFPPF_100MB_HD(1 << 2), OFPPF_100MB_FD(1 << 3), OFPPF_1GB_HD(
- 1 << 4), OFPPF_1GB_FD(1 << 5), OFPPF_10GB_FD(1 << 6), OFPPF_40GB_FD(1 << 7), OFPPF_100GB_FD(1 << 8), OFPPF_1TB_FD(
- 1 << 9), OFPPF_OTHER(1 << 10), OFPPF_COPPER(1 << 11), OFPPF_FIBER(1 << 12), OFPPF_AUTONEG(1 << 13), OFPPF_PAUSE(
- 1 << 14), OFPPF_PAUSE_ASYM(1 << 15);
-
- protected int value;
-
- private OFPortFeatures(int value) {
- this.value = value;
- }
-
- /**
- * @return the value
- */
- public int getValue() {
- return value;
- }
- }
-
- protected int portNumber;
- protected byte[] hardwareAddress;
- protected String name;
- protected int config;
- protected int state;
- protected int currentFeatures;
- protected int advertisedFeatures;
- protected int supportedFeatures;
- protected int peerFeatures;
- private int currentSpeed;
- private int maxSpeed;
-
- /**
- * @return the portNumber
- */
- public int getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param portNumber
- * the portNumber to set
- */
- public void setPortNumber(short portNumber) {
- this.portNumber = portNumber;
- }
-
- /**
- * @return the hardwareAddress
- */
- public byte[] getHardwareAddress() {
- return hardwareAddress;
- }
-
- /**
- * @param hardwareAddress
- * the hardwareAddress to set
- */
- public void setHardwareAddress(byte[] hardwareAddress) {
- if (hardwareAddress.length != OFP_ETH_ALEN)
- throw new RuntimeException("Hardware address must have length " + OFP_ETH_ALEN);
- this.hardwareAddress = hardwareAddress;
- }
-
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- /**
- * @param name
- * the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * @return the config
- */
- public int getConfig() {
- return config;
- }
-
- /**
- * @param config
- * the config to set
- */
- public void setConfig(int config) {
- this.config = config;
- }
-
- /**
- * @return the state
- */
- public int getState() {
- return state;
- }
-
- /**
- * @param state
- * the state to set
- */
- public void setState(int state) {
- this.state = state;
- }
-
- /**
- * @return the currentFeatures
- */
- public int getCurrentFeatures() {
- return currentFeatures;
- }
-
- /**
- * @param currentFeatures
- * the currentFeatures to set
- */
- public void setCurrentFeatures(int currentFeatures) {
- this.currentFeatures = currentFeatures;
- }
-
- /**
- * @return the advertisedFeatures
- */
- public int getAdvertisedFeatures() {
- return advertisedFeatures;
- }
-
- /**
- * @param advertisedFeatures
- * the advertisedFeatures to set
- */
- public void setAdvertisedFeatures(int advertisedFeatures) {
- this.advertisedFeatures = advertisedFeatures;
- }
-
- /**
- * @return the supportedFeatures
- */
- public int getSupportedFeatures() {
- return supportedFeatures;
- }
-
- /**
- * @param supportedFeatures
- * the supportedFeatures to set
- */
- public void setSupportedFeatures(int supportedFeatures) {
- this.supportedFeatures = supportedFeatures;
- }
-
- /**
- * @return the peerFeatures
- */
- public int getPeerFeatures() {
- return peerFeatures;
- }
-
- /**
- * @param peerFeatures
- * the peerFeatures to set
- */
- public void setPeerFeatures(int peerFeatures) {
- this.peerFeatures = peerFeatures;
- }
-
- /**
- * Read this message from the specified DataBuffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- this.portNumber = data.getInt();
- data.getInt(); // pad
- if (this.hardwareAddress == null)
- this.hardwareAddress = new byte[OFP_ETH_ALEN];
- data.get(this.hardwareAddress);
- data.getShort(); // pad
- byte[] name = new byte[16];
- data.get(name);
- // find the first index of 0
- int index = 0;
- for (byte b : name) {
- if (0 == b)
- break;
- ++index;
- }
- this.name = new String(Arrays.copyOf(name, index), Charset.forName("ascii"));
- this.config = data.getInt();
- this.state = data.getInt();
- this.currentFeatures = data.getInt();
- this.advertisedFeatures = data.getInt();
- this.supportedFeatures = data.getInt();
- this.peerFeatures = data.getInt();
- this.currentSpeed = data.getInt();
- this.maxSpeed = data.getInt();
- }
-
- /**
- * Write this message's binary format to the specified DataBuffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- data.putInt(this.portNumber);
- data.putInt(0); // pad
- data.put(hardwareAddress);
- data.putShort((short) 0); // pad
- StringByteSerializer.writeTo(data, 16, name);
- data.putInt(this.config);
- data.putInt(this.state);
- data.putInt(this.currentFeatures);
- data.putInt(this.advertisedFeatures);
- data.putInt(this.supportedFeatures);
- data.putInt(this.peerFeatures);
- data.putInt(this.currentSpeed);
- data.putInt(this.maxSpeed);
- }
-
- @Override
- public int hashCode() {
- final int prime = 307;
- int result = 1;
- result = prime * result + advertisedFeatures;
- result = prime * result + config;
- result = prime * result + currentFeatures;
- result = prime * result + Arrays.hashCode(hardwareAddress);
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + peerFeatures;
- result = prime * result + portNumber;
- result = prime * result + state;
- result = prime * result + supportedFeatures;
- result = prime * result + currentSpeed;
- result = prime * result + maxSpeed;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPPort)) {
- return false;
- }
- OFPPort other = (OFPPort) obj;
- if (advertisedFeatures != other.advertisedFeatures) {
- return false;
- }
- if (config != other.config) {
- return false;
- }
- if (currentFeatures != other.currentFeatures) {
- return false;
- }
- if (!Arrays.equals(hardwareAddress, other.hardwareAddress)) {
- return false;
- }
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (peerFeatures != other.peerFeatures) {
- return false;
- }
- if (portNumber != other.portNumber) {
- return false;
- }
- if (state != other.state) {
- return false;
- }
- if (supportedFeatures != other.supportedFeatures) {
- return false;
- }
- if (currentSpeed != other.currentSpeed) {
- return false;
- }
- if (maxSpeed != other.maxSpeed) {
- return false;
- }
- return true;
- }
-
- public OFPPort cloneOFPort() {
- OFPPort p;
- try {
- p = (OFPPort) this.clone();
-
- } catch (CloneNotSupportedException e) {
- throw new AssertionError();
- }
- return p;
- }
-
- /**
- * get current speed in kbps
- *
- * @return
- */
- public int getCurrentSpeed() {
- return currentSpeed;
- }
-
- /**
- * set current speed in kbps ex: 10 Gb Ethernet port should have this field
- * set to 10000000 (instead of 10312500)
- *
- * @param currentSpeed
- */
- public void setCurrentSpeed(int currentSpeed) {
- this.currentSpeed = currentSpeed;
- }
-
- /**
- * get max speed in kbps
- *
- * @return
- */
- public int getMaxSpeed() {
- return maxSpeed;
- }
-
- /**
- * set current speed in kbps ex: 10 Gb Ethernet port should have this field
- * set to 10000000 (instead of 10312500)
- *
- * @param maxSpeed
- * -
- */
- public void setMaxSpeed(int maxSpeed) {
- this.maxSpeed = maxSpeed;
- }
-
- /**
- * get the length of structure
- *
- * @return
- */
- public int getLength() {
- return MINIMUM_LENGTH;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.Arrays;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_port_mod message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPPortMod extends OFPMessage {
- public static int MINIMUM_LENGTH = 40;
-
- protected int portNumber;
- protected byte[] hardwareAddress;
- protected int config;
- protected int mask;
- protected int advertise;
-
- public OFPPortMod() {
- super();
- this.type = OFPType.PORT_MOD;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * @return the portNumber
- */
- public int getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param portNumber
- * the portNumber to set
- */
- public void setPortNumber(int portNumber) {
- this.portNumber = portNumber;
- }
-
- /**
- * @return the hardwareAddress
- */
- public byte[] getHardwareAddress() {
- return hardwareAddress;
- }
-
- /**
- * @param hardwareAddress
- * the hardwareAddress to set
- */
- public void setHardwareAddress(byte[] hardwareAddress) {
- if (hardwareAddress.length != OFPPort.OFP_ETH_ALEN)
- throw new RuntimeException("Hardware address must have length " + OFPPort.OFP_ETH_ALEN);
- this.hardwareAddress = hardwareAddress;
- }
-
- /**
- * @return the config
- */
- public int getConfig() {
- return config;
- }
-
- /**
- * @param config
- * the config to set
- */
- public void setConfig(int config) {
- this.config = config;
- }
-
- /**
- * @return the mask
- */
- public int getMask() {
- return mask;
- }
-
- /**
- * @param mask
- * the mask to set
- */
- public void setMask(int mask) {
- this.mask = mask;
- }
-
- /**
- * @return the advertise
- */
- public int getAdvertise() {
- return advertise;
- }
-
- /**
- * @param advertise
- * the advertise to set
- */
- public void setAdvertise(int advertise) {
- this.advertise = advertise;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.portNumber = data.getInt();
- data.getInt(); // pad
- if (this.hardwareAddress == null)
- this.hardwareAddress = new byte[OFPPort.OFP_ETH_ALEN];
- data.get(this.hardwareAddress);
- data.getShort(); // pad
- this.config = data.getInt();
- this.mask = data.getInt();
- this.advertise = data.getInt();
- data.getShort(); // pad
- data.get(); // pad
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(this.portNumber);
- data.putInt(0); // pad
- data.put(this.hardwareAddress);
- data.putShort((short) 0); // pad
- data.putInt(this.config);
- data.putInt(this.mask);
- data.putInt(this.advertise);
- data.putShort((short) 0); // pad
- data.put((byte) 0); // pad
- }
-
- @Override
- public int hashCode() {
- final int prime = 311;
- int result = super.hashCode();
- result = prime * result + advertise;
- result = prime * result + config;
- result = prime * result + Arrays.hashCode(hardwareAddress);
- result = prime * result + mask;
- result = prime * result + portNumber;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPPortMod)) {
- return false;
- }
- OFPPortMod other = (OFPPortMod) obj;
- if (advertise != other.advertise) {
- return false;
- }
- if (config != other.config) {
- return false;
- }
- if (!Arrays.equals(hardwareAddress, other.hardwareAddress)) {
- return false;
- }
- if (mask != other.mask) {
- return false;
- }
- if (portNumber != other.portNumber) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-/**
- * Represents enum ofp_port_no
- *
- * @author AnilGujele
- *
- */
-public enum OFPPortNo {
- OFPP_MAX((int) 0xffffff00), OFPP_IN_PORT((int) 0xfffffff8), OFPP_TABLE((int) 0xfffffff9), OFPP_NORMAL(
- (int) 0xfffffffa), OFPP_FLOOD((int) 0xfffffffb), OFPP_ALL((int) 0xfffffffc), OFPP_CONTROLLER(
- (int) 0xfffffffd), OFPP_LOCAL((int) 0xfffffffe), OFPP_ANY((int) 0xffffffff);
-
- protected int value;
-
- private OFPPortNo(int value) {
- this.value = value;
- }
-
- /**
- * @return the value
- */
- public int getValue() {
- return value;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_port_status message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPPortStatus extends OFPMessage {
- public static int MINIMUM_LENGTH = 80;
-
- public enum OFPortReason {
- OFPPR_ADD, OFPPR_DELETE, OFPPR_MODIFY
- }
-
- protected byte reason;
- protected OFPPort desc;
-
- /**
- * @return the reason
- */
- public byte getReason() {
- return reason;
- }
-
- /**
- * @param reason
- * the reason to set
- */
- public void setReason(byte reason) {
- this.reason = reason;
- }
-
- /**
- * @return the desc
- */
- public OFPPort getDesc() {
- return desc;
- }
-
- /**
- * @param desc
- * the desc to set
- */
- public void setDesc(OFPPort desc) {
- this.desc = desc;
- }
-
- public OFPPortStatus() {
- super();
- this.type = OFPType.PORT_STATUS;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.reason = data.get();
- data.position(data.position() + 7); // skip 7 bytes of padding
- if (this.desc == null)
- this.desc = new OFPPort();
- this.desc.readFrom(data);
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.put(this.reason);
- for (int i = 0; i < 7; ++i)
- data.put((byte) 0);
- this.desc.writeTo(data);
- }
-
- @Override
- public int hashCode() {
- final int prime = 313;
- int result = super.hashCode();
- result = prime * result + ((desc == null) ? 0 : desc.hashCode());
- result = prime * result + reason;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPPortStatus)) {
- return false;
- }
- OFPPortStatus other = (OFPPortStatus) obj;
- if (desc == null) {
- if (other.desc != null) {
- return false;
- }
- } else if (!desc.equals(other.desc)) {
- return false;
- }
- if (reason != other.reason) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.factory.OFPQueuePropertyFactory;
-import org.openflow.codec.protocol.factory.OFPQueuePropertyFactoryAware;
-import org.openflow.codec.protocol.queue.OFPPacketQueue;
-import org.openflow.codec.util.U16;
-
-/**
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPQueueConfigReply extends OFPMessage implements Cloneable, OFPQueuePropertyFactoryAware {
- public static int MINIMUM_LENGTH = 16;
-
- protected OFPQueuePropertyFactory queuePropertyFactory;
-
- protected int port;
- protected List<OFPPacketQueue> queues;
-
- /**
- *
- */
- public OFPQueueConfigReply() {
- super();
- this.type = OFPType.QUEUE_CONFIG_REPLY;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * @return the port
- */
- public int getPort() {
- return port;
- }
-
- /**
- * @param port
- * the port to set
- */
- public OFPQueueConfigReply setPort(int port) {
- this.port = port;
- return this;
- }
-
- /**
- * @return the queues
- */
- public List<OFPPacketQueue> getQueues() {
- return queues;
- }
-
- /**
- * @param queues
- * the queues to set
- */
- public void setQueues(List<OFPPacketQueue> queues) {
- this.queues = queues;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.port = data.getInt();
- data.getInt(); // pad
- int remaining = this.getLengthU() - MINIMUM_LENGTH;
- if (data.remaining() < remaining)
- remaining = data.remaining();
- this.queues = new ArrayList<OFPPacketQueue>();
- while (remaining >= OFPPacketQueue.MINIMUM_LENGTH) {
- OFPPacketQueue queue = new OFPPacketQueue();
- queue.setQueuePropertyFactory(this.queuePropertyFactory);
- queue.readFrom(data);
- remaining -= U16.f(queue.getLength());
- this.queues.add(queue);
- }
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(this.port);
- data.putInt(0); // pad
- if (this.queues != null) {
- for (OFPPacketQueue queue : this.queues) {
- queue.writeTo(data);
- }
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 4549;
- int result = super.hashCode();
- result = prime * result + port;
- result = prime * result + ((queues == null) ? 0 : queues.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (!(obj instanceof OFPQueueConfigReply))
- return false;
- OFPQueueConfigReply other = (OFPQueueConfigReply) obj;
- if (port != other.port)
- return false;
- if (queues == null) {
- if (other.queues != null)
- return false;
- } else if (!queues.equals(other.queues))
- return false;
- return true;
- }
-
- @Override
- public void setQueuePropertyFactory(OFPQueuePropertyFactory queuePropertyFactory) {
- this.queuePropertyFactory = queuePropertyFactory;
- }
-
- @Override
- public OFPQueueConfigReply clone() {
- try {
- OFPQueueConfigReply clone = (OFPQueueConfigReply) super.clone();
- if (this.queues != null) {
- List<OFPPacketQueue> queues = new ArrayList<OFPPacketQueue>();
- for (OFPPacketQueue queue : this.queues) {
- queues.add(queue.clone());
- }
- clone.setQueues(queues);
- }
- return clone;
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public String toString() {
- return "OFPQueueConfigReply [port=" + port + ", queues=" + queues + ", xid=" + xid + "]";
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPQueueConfigRequest extends OFPMessage implements Cloneable {
- public static int MINIMUM_LENGTH = 16;
-
- protected int port;
-
- /**
- *
- */
- public OFPQueueConfigRequest() {
- super();
- this.type = OFPType.QUEUE_CONFIG_REQUEST;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * @return the port
- */
- public int getPort() {
- return port;
- }
-
- /**
- * @param port
- * the port to set
- */
- public void setPort(int port) {
- this.port = port;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.port = data.getInt();
- data.getInt(); // pad
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(this.port);
- data.putInt(0); // pad
- }
-
- @Override
- public int hashCode() {
- final int prime = 7211;
- int result = super.hashCode();
- result = prime * result + port;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (!(obj instanceof OFPQueueConfigRequest))
- return false;
- OFPQueueConfigRequest other = (OFPQueueConfigRequest) obj;
- if (port != other.port)
- return false;
- return true;
- }
-
- @Override
- public OFPQueueConfigRequest clone() {
- try {
- return (OFPQueueConfigRequest) super.clone();
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException(e);
- }
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-/**
- * Represents an OFPT_SET_CONFIG type message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPSetConfig extends OFPSwitchConfig {
- public OFPSetConfig() {
- super();
- this.type = OFPType.SET_CONFIG;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Base class representing ofp_switch_config based messages
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public abstract class OFPSwitchConfig extends OFPMessage {
- public static int MINIMUM_LENGTH = 12;
-
- public enum OFConfigFlags {
- OFPC_FRAG_NORMAL, OFPC_FRAG_DROP, OFPC_FRAG_REASM, OFPC_FRAG_MASK
- }
-
- protected short flags;
- protected short missSendLength;
-
- public OFPSwitchConfig() {
- super();
- super.setLengthU(MINIMUM_LENGTH);
- }
-
- /**
- * @return the flags
- */
- public short getFlags() {
- return flags;
- }
-
- /**
- * @param flags
- * the flags to set
- */
- public OFPSwitchConfig setFlags(short flags) {
- this.flags = flags;
- return this;
- }
-
- /**
- * @return the missSendLength
- */
- public short getMissSendLength() {
- return missSendLength;
- }
-
- /**
- * @param missSendLength
- * the missSendLength to set
- */
- public OFPSwitchConfig setMissSendLength(short missSendLength) {
- this.missSendLength = missSendLength;
- return this;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.flags = data.getShort();
- this.missSendLength = data.getShort();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putShort(this.flags);
- data.putShort(this.missSendLength);
- }
-
- @Override
- public int hashCode() {
- final int prime = 331;
- int result = super.hashCode();
- result = prime * result + flags;
- result = prime * result + missSendLength;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPSwitchConfig)) {
- return false;
- }
- OFPSwitchConfig other = (OFPSwitchConfig) obj;
- if (flags != other.flags) {
- return false;
- }
- if (missSendLength != other.missSendLength) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.io.Serializable;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents a features reply message struct ofp_switch_features
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- *
- */
-public class OFPSwitchFeaturesReply extends OFPMessage implements Serializable {
- public static int MINIMUM_LENGTH = 32;
-
- /**
- * Corresponds to bits on the capabilities field enum ofp_capabilities
- */
- public enum OFCapabilities {
- OFPC_FLOW_STATS(1 << 0), OFPC_TABLE_STATS(1 << 1), OFPC_PORT_STATS(1 << 2), OFPC_GROUP_STATS(1 << 3), OFPC_IP_REASM(
- 1 << 5), OFPC_QUEUE_STATS(1 << 6), OFPC_PORT_BLOCKED(1 << 8);
-
- protected int value;
-
- private OFCapabilities(int value) {
- this.value = value;
- }
-
- /**
- * @return the value
- */
- public int getValue() {
- return value;
- }
- }
-
- protected long datapathId;
- protected int buffers;
- protected byte tables;
- protected byte auxiliaryId;
- protected int capabilities;
- protected int reserved;
-
- public OFPSwitchFeaturesReply() {
- super();
- this.type = OFPType.FEATURES_REPLY;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * @return the datapathId
- */
- public long getDatapathId() {
- return datapathId;
- }
-
- /**
- * @param datapathId
- * the datapathId to set
- */
- public void setDatapathId(long datapathId) {
- this.datapathId = datapathId;
- }
-
- /**
- * @return the buffers
- */
- public int getBuffers() {
- return buffers;
- }
-
- /**
- * @param buffers
- * the buffers to set
- */
- public void setBuffers(int buffers) {
- this.buffers = buffers;
- }
-
- /**
- * @return the tables
- */
- public byte getTables() {
- return tables;
- }
-
- /**
- * @param tables
- * the tables to set
- */
- public void setTables(byte tables) {
- this.tables = tables;
- }
-
- /**
- * type of connection with switch.
- *
- * @return 0 - main connection , non zero - auxiliary connection
- */
- public byte getAuxiliaryId() {
- return auxiliaryId;
- }
-
- /**
- *
- * @param auxiliaryId
- */
- public void setAuxiliaryId(byte auxiliaryId) {
- this.auxiliaryId = auxiliaryId;
- }
-
- /**
- * @return the capabilities
- */
- public int getCapabilities() {
- return capabilities;
- }
-
- /**
- * @param capabilities
- * the capabilities to set
- */
- public void setCapabilities(int capabilities) {
- this.capabilities = capabilities;
- }
-
- public int getReserved() {
- return reserved;
- }
-
- public void setReserved(int reserved) {
- this.reserved = reserved;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.datapathId = data.getLong();
- this.buffers = data.getInt();
- this.tables = data.get();
- this.auxiliaryId = data.get();
- data.getShort(); // pad
- this.capabilities = data.getInt();
- this.reserved = data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putLong(this.datapathId);
- data.putInt(this.buffers);
- data.put(this.tables);
- data.put(this.auxiliaryId);
- data.putShort((short) 0); // pad
- data.putInt(this.capabilities);
- data.putInt(this.reserved);
- }
-
- @Override
- public int hashCode() {
- final int prime = 139;
- int result = super.hashCode();
- result = prime * result + auxiliaryId;
- result = prime * result + buffers;
- result = prime * result + capabilities;
- result = prime * result + reserved;
- result = prime * result + (int) (datapathId ^ (datapathId >>> 32));
- result = prime * result + tables;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPSwitchFeaturesReply)) {
- return false;
- }
- OFPSwitchFeaturesReply other = (OFPSwitchFeaturesReply) obj;
- if (auxiliaryId != other.auxiliaryId) {
- return false;
- }
- if (reserved != other.reserved) {
- return false;
- }
- if (buffers != other.buffers) {
- return false;
- }
- if (capabilities != other.capabilities) {
- return false;
- }
- if (datapathId != other.datapathId) {
- return false;
- }
- if (tables != other.tables) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.util.U16;
-
-/**
- * Represents a features request message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- *
- */
-public class OFPSwitchFeaturesRequest extends OFPMessage {
- public static int MINIMUM_LENGTH = 8;
-
- public OFPSwitchFeaturesRequest() {
- super();
- this.type = OFPType.FEATURES_REQUEST;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * Class representing message structure ofp_table_mod
- *
- * @author AnilGujele
- *
- */
-public class OFPTableMod extends OFPMessage {
-
- private static final long serialVersionUID = -5972069012765334899L;
-
- public static int MINIMUM_LENGTH = 16;
-
- // table number as per ofp_table
- enum OFTable {
- /* Last usable table number. */
- OFPTT_MAX(0xfe),
-
- /* Fake tables. */
- OFPTT_ALL(0xff);
-
- private int value;
-
- OFTable(int value) {
- this.value = value;
- }
-
- public short value() {
- return (short) this.value;
- }
- }
-
- // Flags to configure the table as per ofp_table_config
- public static final int OFPTC_DEPRECATED_MASK = 3;
-
- private byte tableId;
- private int config;
-
- /**
- * constructor
- */
- public OFPTableMod() {
- super();
- this.type = OFPType.TABLE_MOD;
- this.length = U16.t(MINIMUM_LENGTH);
-
- }
-
- /**
- * get table id
- *
- * @return
- */
- public byte getTableId() {
- return tableId;
- }
-
- /**
- * set table id OFPTT_ALL is for all the table OFPTT_MAX is Max table number
- * limit
- *
- * @param tableId
- */
- public void setTableId(byte tableId) {
-
- this.tableId = tableId;
- }
-
- /**
- *
- * @return
- */
- public int getConfig() {
- return config;
- }
-
- /**
- *
- * @param config
- */
- public void setConfig(int config) {
- this.config = config;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.tableId = data.get();
- data.getShort(); // pad
- data.get(); // pad
- this.config = data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.put(this.tableId);
- data.putShort((short) 0); // pad
- data.put((byte) 0); // pad
- data.putInt(this.config);
- }
-
- @Override
- public int hashCode() {
- final int prime = 811;
- int result = super.hashCode();
- result = prime * result + tableId;
- result = prime * result + config;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPTableMod)) {
- return false;
- }
- OFPTableMod other = (OFPTableMod) obj;
- if (tableId != other.tableId) {
- return false;
- }
- if (config != other.config) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.lang.reflect.Constructor;
-
-/**
- * List of OpenFlow types and mappings to wire protocol value and derived
- * classes
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- * @author David Erickson (daviderickson@cs.stanford.edu)
- *
- */
-public enum OFPType {
- HELLO(0, OFPHello.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPHello();
- }
- }), ERROR(1, OFPErrorMsg.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPErrorMsg();
- }
- }), ECHO_REQUEST(2, OFPEchoRequest.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPEchoRequest();
- }
- }), ECHO_REPLY(3, OFPEchoReply.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPEchoReply();
- }
- }), EXPERIMENTER(4, OFPExperimenterHeader.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPExperimenterHeader();
- }
- }), FEATURES_REQUEST(5, OFPSwitchFeaturesRequest.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPSwitchFeaturesRequest();
- }
- }), FEATURES_REPLY(6, OFPSwitchFeaturesReply.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPSwitchFeaturesReply();
- }
- }), GET_CONFIG_REQUEST(7, OFPGetConfigRequest.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPGetConfigRequest();
- }
- }), GET_CONFIG_REPLY(8, OFPGetConfigReply.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPGetConfigReply();
- }
- }), SET_CONFIG(9, OFPSetConfig.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPSetConfig();
- }
- }), PACKET_IN(10, OFPPacketIn.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPPacketIn();
- }
- }), FLOW_REMOVED(11, OFPFlowRemoved.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPFlowRemoved();
- }
- }), PORT_STATUS(12, OFPPortStatus.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPPortStatus();
- }
- }), PACKET_OUT(13, OFPPacketOut.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPPacketOut();
- }
- }), FLOW_MOD(14, OFPFlowMod.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPFlowMod();
- }
- }), GROUP_MOD(15, OFPGroupMod.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPGroupMod();
- }
- }),
-
- PORT_MOD(16, OFPPortMod.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPPortMod();
- }
- }),
-
- TABLE_MOD(17, OFPTableMod.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPTableMod();
- }
- }),
-
- MULTIPART_REQUEST(18, OFPMultipartRequest.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPMultipartRequest();
- }
- }), MULTIPART_REPLY(19, OFPMultipartReply.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPMultipartReply();
- }
- }), BARRIER_REQUEST(20, OFPBarrierRequest.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPBarrierRequest();
- }
- }), BARRIER_REPLY(21, OFPBarrierReply.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPBarrierReply();
- }
- }), QUEUE_CONFIG_REQUEST(22, OFPMessage.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPQueueConfigRequest();
- }
- }), QUEUE_CONFIG_REPLY(23, OFPMessage.class, new Instantiable<OFPMessage>() {
- @Override
- public OFPMessage instantiate() {
- return new OFPQueueConfigReply();
- }
- });
-
- static OFPType[] mapping;
-
- protected Class<? extends OFPMessage> clazz;
- protected Constructor<? extends OFPMessage> constructor;
- protected Instantiable<OFPMessage> instantiable;
- protected byte type;
-
- /**
- * Store some information about the OpenFlow type, including wire protocol
- * type number, length, and derived class
- *
- * @param type
- * Wire protocol number associated with this OFPType
- * @param requestClass
- * The Java class corresponding to this type of OpenFlow message
- * @param instantiator
- * An Instantiator<OFPMessage> implementation that creates an
- * instance of the specified OFPMessage
- */
- OFPType(int type, Class<? extends OFPMessage> clazz, Instantiable<OFPMessage> instantiator) {
- this.type = (byte) type;
- this.clazz = clazz;
- this.instantiable = instantiator;
- try {
- this.constructor = clazz.getConstructor(new Class[] {});
- } catch (Exception e) {
- throw new RuntimeException("Failure getting constructor for class: " + clazz, e);
- }
- OFPType.addMapping(this.type, this);
- }
-
- /**
- * Adds a mapping from type value to OFPType enum
- *
- * @param i
- * OpenFlow wire protocol type
- * @param t
- * type
- */
- static public void addMapping(byte i, OFPType t) {
- if (mapping == null)
- mapping = new OFPType[32];
- OFPType.mapping[i] = t;
- }
-
- /**
- * Remove a mapping from type value to OFPType enum
- *
- * @param i
- * OpenFlow wire protocol type
- */
- static public void removeMapping(byte i) {
- OFPType.mapping[i] = null;
- }
-
- /**
- * Given a wire protocol OpenFlow type number, return the OFPType associated
- * with it
- *
- * @param i
- * wire protocol number
- * @return OFPType enum type
- */
-
- static public OFPType valueOf(Byte i) {
- return OFPType.mapping[i];
- }
-
- /**
- * @return Returns the wire protocol value corresponding to this OFPType
- */
- public byte getTypeValue() {
- return this.type;
- }
-
- /**
- * @return return the OFPMessage subclass corresponding to this OFPType
- */
- public Class<? extends OFPMessage> toClass() {
- return clazz;
- }
-
- /**
- * Returns the no-argument Constructor of the implementation class for this
- * OFPType
- *
- * @return the constructor
- */
- public Constructor<? extends OFPMessage> getConstructor() {
- return constructor;
- }
-
- /**
- * Returns a new instance of the OFPMessage represented by this OFPType
- *
- * @return the new object
- */
- public OFPMessage newInstance() {
- return instantiable.instantiate();
- }
-
- /**
- * @return the instantiable
- */
- public Instantiable<OFPMessage> getInstantiable() {
- return instantiable;
- }
-
- /**
- * @param instantiable
- * the instantiable to set
- */
- public void setInstantiable(Instantiable<OFPMessage> instantiable) {
- this.instantiable = instantiable;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Enum to define OXM class type
- *
- * @author AnilGujele
- *
- */
-public enum OXMClass {
-
- NXM_0(0x0000), NXM_1(0x0001), OPENFLOW_BASIC(0x8000), EXPERIMENTER(0xFFFF);
-
- private static Map<Integer, OXMClass> valueMap;
-
- private int value;
-
- /**
- * constructor
- *
- * @param value
- */
- OXMClass(int value) {
- this.value = value;
- addMapping(value, this);
- }
-
- /**
- * add mapping for OXMClass
- *
- * @param value
- * @param type
- */
- private static void addMapping(int value, OXMClass type) {
- if (null == valueMap) {
- valueMap = new HashMap<Integer, OXMClass>();
- }
- valueMap.put(value, type);
- }
-
- /**
- * @return the value
- */
- public int getValue() {
- return value;
- }
-
- /**
- * get OXMClass for the specific value
- *
- * @param value
- * @return
- */
- public static OXMClass getOXMClass(int value) {
- return valueMap.get((int) value);
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * OXM Field in TLV format to handle Basic and Experimenter it has
- * implementation of ofp_oxm_experimenter_header
- *
- * @author AnilGujele
- *
- */
-public class OXMField implements Cloneable, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private static byte MINIMUM_LENGTH = 4;
-
- private OXMClass OXMClassType;
- private OFBMatchFields matchField;
- private boolean hasMask;
- private byte[] data;
- private byte length;
- private int experimenterId;
- private short experimenterField;
-
- /**
- * constructor
- */
- public OXMField() {
- data = new byte[0];
- length = MINIMUM_LENGTH;
- }
-
- /**
- * constructor with arguments
- *
- * @param classType
- * @param matchField
- * @param hasMask
- * @param data
- */
- public OXMField(OXMClass classType, OFBMatchFields matchField, boolean hasMask, byte[] data) {
- length = MINIMUM_LENGTH;
- this.setOXMClassType(classType);
- this.setMatchField(matchField);
- this.setHasMask(hasMask);
- this.setData(data);
- }
-
- /**
- * constructor with arguments, should use in case of experimenter
- */
- public OXMField(OXMClass classType, short expField, int expId) {
- length = MINIMUM_LENGTH;
- this.setOXMClassType(classType);
- this.setExperimenterField(expField);
- this.setExperimenterId(expId);
- // set default match field to avoid any exception in case of
- // experimenter
- this.setMatchField(OFBMatchFields.ICMPV4_TYPE);
- }
-
- /**
- * get the oxm match field class
- *
- * @return
- */
- public OXMClass getOXMClassType() {
- return OXMClassType;
- }
-
- /**
- * set the oxm match field class
- *
- * @param oXMClassType
- * - supported class type is OXMClass.OPENFLOW_BASIC
- */
- public void setOXMClassType(OXMClass oXMClassType) {
- OXMClassType = oXMClassType;
- }
-
- /**
- * get match field
- *
- * @return
- */
- public OFBMatchFields getMatchField() {
- return matchField;
- }
-
- /**
- * set match field
- *
- * @param matchField
- */
- public void setMatchField(OFBMatchFields matchField) {
- this.matchField = matchField;
- }
-
- /**
- * return the match field with has mask
- */
- public byte getMatchFieldValueWithHasMask() {
- byte value = matchField.getValue();
- // 7 left most bit is used for match field identification
- value = (byte) (value << 1);
- if (this.hasMask) {
- // set the last bit as 1
- value = (byte) (value | 1);
- }
- return value;
- }
-
- /**
- * whether match field value has mask
- *
- * @return
- */
- public boolean isHasMask() {
- return hasMask;
- }
-
- /**
- * set the has mask
- *
- * @param hasMask
- */
- public void setHasMask(boolean hasMask) {
- this.hasMask = hasMask;
-
- }
-
- /**
- * get match field payload
- *
- * @return
- */
- public byte[] getData() {
- return data;
- }
-
- /**
- * set value for match field payload
- *
- * @param data
- */
- public void setData(byte[] data) {
- if (null == data) {
- this.data = new byte[0];
- } else {
- this.data = data;
- }
- }
-
- /**
- * to get the total length of match field (or TLV) including header in bytes
- *
- * @return
- */
- public byte getLength() {
- // Type + Lenghth + Value
- return (byte) (length + data.length);
- }
-
- /**
- * Read this field from the specified DataBuffer
- *
- * @param data
- * - data to read to construct match object
- * @return true - reading is successful , false - failed to read as data is
- * not proper
- */
- public boolean readFrom(IDataBuffer data) {
-
- boolean result = false;
- // read match field class type
- int classType = U16.f(data.getShort());
- // check for supported class type
- if (classType == OXMClass.OPENFLOW_BASIC.getValue()) {
- // read match field including hasMask
- byte field = data.get();
- boolean hasMask = ((field & 1) == 1);
- /*
- * TBD - if mask is set, then data length will be double, so driver
- * need to handle masking to set the field value or plugin or App
- * will handle
- */
- field = (byte) (field >>> 1);
- OFBMatchFields matchField = OFBMatchFields.valueOf(field);
- // read length of value
- byte dataLength = data.get();
- // if data is negative number, then return
- if (dataLength < 0) {
- return result;
- }
- if (null != matchField) {
-
- int matchFieldDefineSize = matchField.getLengthInBytes();
- int dataLenghtSize = hasMask ? dataLength / 2 : dataLength;
- byte[] dataValue = new byte[dataLength];
- data.get(dataValue);
- boolean isMaskingValid = hasMask ? (matchField.isHasMask() == hasMask) : true;
- // check if field is as per the open flow spec 1.3, if not then
- // only moving the data pointer is enough
- // datalength can be zero in case only header is required.
- if (0 != dataLenghtSize && (dataLenghtSize == matchFieldDefineSize) && isMaskingValid) {
-
- this.setOXMClassType(OXMClass.getOXMClass(classType));
- this.setMatchField(matchField);
- this.setHasMask(hasMask);
- this.setData(dataValue);
-
- }
- } else {
- // unknown match field, better to log and move the pointer
- // read data
- byte[] dataValue = new byte[dataLength];
- data.get(dataValue);
- }
- result = true;
-
- } else if (classType == OXMClass.EXPERIMENTER.getValue()) {
- this.setExperimenterField(data.getShort());
- this.setExperimenterId(data.getInt());
- }
-
- return result;
-
- }
-
- /**
- * Write this match binary format to the specified DataBuffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- data.putShort(U16.t(this.getOXMClassType().getValue()));
- if (this.getOXMClassType().equals(OXMClass.OPENFLOW_BASIC)) {
- data.put(this.getMatchFieldValueWithHasMask());
- data.put((byte) this.getData().length); // actual length of data
- data.put(this.getData());
- } else if (this.getOXMClassType().equals(OXMClass.EXPERIMENTER)) {
- data.putShort(this.getExperimenterField());
- data.putInt(this.getExperimenterId());
-
- }
- }
-
- /**
- * create the clone of this OXMTLVField
- *
- */
- @Override
- public OXMField clone() {
- try {
- OXMField field = (OXMField) super.clone();
- field.data = this.data.clone();
- return field;
-
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * to get the object hashcode
- *
- * @return
- */
- public int hashCode() {
- final int prime = 721;
- int result = prime + ((data == null) ? 0 : Arrays.hashCode(data));
- result = prime * result + this.getLength();
- result = prime * result + this.matchField.getValue();
- result = prime * result + this.getOXMClassType().getValue();
- result = prime * result + this.getExperimenterField();
- result = prime * result + this.getExperimenterId();
- return result;
- }
-
- /**
- * to check object equality
- */
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (null == obj) {
- return false;
- }
- if (!(obj instanceof OXMField)) {
- return false;
- }
- OXMField other = (OXMField) obj;
- if (0 != this.matchField.compareTo(other.matchField)) {
- return false;
- }
- if (0 != this.OXMClassType.compareTo(other.OXMClassType)) {
- return false;
- }
- if (!(this.isHasMask() == other.isHasMask())) {
- return false;
- }
- if (this.getLength() != other.getLength()) {
- return false;
- }
- if (this.getExperimenterField() != other.getExperimenterField()) {
- return false;
- }
- if (this.getExperimenterId() != other.getExperimenterId()) {
- return false;
- }
-
- if (!Arrays.equals(this.getData(), other.getData())) {
- return false;
- }
- return true;
- }
-
- /**
- * String representation of OXMTLVField Object ex:
- * Type=OPENFLOW_BASIC-IPV4_SRC, Length=8, Value=[1, 2, 3, 4]
- */
-
- public String toString() {
- StringBuffer buffer = new StringBuffer(30);
- buffer.append("Type=").append(this.getOXMClassType().name());
- buffer.append("-").append(this.matchField.name());
- buffer.append(", Length=").append(this.getLength());
- buffer.append(", Value=").append(Arrays.toString(data));
- return buffer.toString();
- }
-
- /**
- * read OXMField header from data till specified length
- *
- * @param data
- * @param length
- * @return
- */
- public static List<OXMField> readOXMFieldHeader(IDataBuffer data, int length) {
- List<OXMField> oxmList = new ArrayList<OXMField>();
- int end = data.position() + length;
- while (data.position() < end) {
- // read match field class type
- int classType = U16.f(data.getShort());
- // read match field including hasMask
- byte field = data.get();
- boolean hasMask = ((field & 1) == 1);
- field = (byte) (field >>> 1);
- OFBMatchFields matchField = OFBMatchFields.valueOf(field);
- // check for supported class type
- if (classType == OXMClass.OPENFLOW_BASIC.getValue()) {
- OXMField oxmfield = new OXMField(OXMClass.OPENFLOW_BASIC, matchField, hasMask, new byte[0]);
- oxmList.add(oxmfield);
- } else if (classType == OXMClass.EXPERIMENTER.getValue()) {
- OXMField oxmfield = new OXMField(OXMClass.OPENFLOW_BASIC, data.getShort(), data.getInt());
- oxmList.add(oxmfield);
- }
- data.get(); // ignore length field in header.
- }
-
- return oxmList;
- }
-
- /**
- * write oxmfield header in data buffer
- *
- * @param data
- * @param oxmList
- */
- public static void writeOXMFieldHeader(IDataBuffer data, List<OXMField> oxmList) {
- for (OXMField field : oxmList) {
- OXMClass clazz = field.getOXMClassType();
- if (clazz.getValue() == OXMClass.OPENFLOW_BASIC.getValue()) {
- data.putShort(U16.t(OXMClass.OPENFLOW_BASIC.getValue()));
- data.put(field.getMatchFieldValueWithHasMask());
- data.put(field.getLength());
- } else if (clazz.getValue() == OXMClass.EXPERIMENTER.getValue()) {
- data.putShort(U16.t(OXMClass.EXPERIMENTER.getValue()));
- data.putShort(field.getExperimenterField());
- data.putInt(field.getExperimenterId());
- }
-
- }
- }
-
- /**
- * get the total length in bytes for the OXMField List
- *
- * @param list
- * @return
- */
- public static int getTotalLength(List<OXMField> list) {
- int result = 0;
- for (OXMField field : list) {
- if (field.getOXMClassType().equals(OXMClass.OPENFLOW_BASIC)) {
- result = result + OXMField.MINIMUM_LENGTH;
- } else if (field.getOXMClassType().equals(OXMClass.EXPERIMENTER)) {
- // for experimenter, header is 8 byte
- result = result + OXMField.MINIMUM_LENGTH * 2;
- }
- }
- return result;
-
- }
-
- /**
- *
- * @return
- */
- public int getExperimenterId() {
- return experimenterId;
- }
-
- /**
- *
- * @param experimenterId
- */
- public void setExperimenterId(int experimenterId) {
- this.experimenterId = experimenterId;
- }
-
- public short getExperimenterField() {
- return experimenterField;
- }
-
- public void setExperimenterField(short experimenterField) {
- this.experimenterField = experimenterField;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.action;
-
-import java.io.Serializable;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * The base class for all OpenFlow Actions.
- *
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-public class OFPAction implements Cloneable, Serializable {
- /**
- * Note the true minimum length for this header is 8 including a pad to 64
- * bit alignment, however as this base class is used for demuxing an
- * incoming Action, it is only necessary to read the first 4 bytes. All
- * Actions extending this class are responsible for reading/writing the
- * first 8 bytes, including the pad if necessary.
- */
- public static int MINIMUM_LENGTH = 4;
- public static int OFFSET_LENGTH = 2;
- public static int OFFSET_TYPE = 0;
-
- protected OFPActionType type;
- protected short length;
-
- /**
- * Get the length of this message
- *
- * @return
- */
- public short getLength() {
- return length;
- }
-
- /**
- * Get the length of this message, unsigned
- *
- * @return
- */
- public int getLengthU() {
- return U16.f(length);
- }
-
- /**
- * Set the length of this message
- *
- * @param length
- */
- public OFPAction setLength(short length) {
- this.length = length;
- return this;
- }
-
- /**
- * Get the type of this message
- *
- * @return OFPActionType enum
- */
- public OFPActionType getType() {
- return this.type;
- }
-
- /**
- * Set the type of this message
- *
- * @param type
- */
- public void setType(OFPActionType type) {
- this.type = type;
- }
-
- /**
- * Returns a summary of the message
- *
- * @return "ofmsg=v=$version;t=$type:l=$len:xid=$xid"
- */
- public String toString() {
- return "ofaction" + ";t=" + this.getType() + ";l=" + this.getLength();
- }
-
- /**
- * Given the output from toString(), create a new OFPAction
- *
- * @param val
- * @return
- */
- public static OFPAction fromString(String val) {
- String tokens[] = val.split(";");
- if (!tokens[0].equals("ofaction"))
- throw new IllegalArgumentException("expected 'ofaction' but got '" + tokens[0] + "'");
- String type_tokens[] = tokens[1].split("=");
- String len_tokens[] = tokens[2].split("=");
- OFPAction action = new OFPAction();
- action.setLength(Short.valueOf(len_tokens[1]));
- action.setType(OFPActionType.valueOf(type_tokens[1]));
- return action;
- }
-
- public void readFrom(IDataBuffer data) {
- this.type = OFPActionType.valueOf(data.getShort());
- this.length = data.getShort();
- // Note missing PAD, see MINIMUM_LENGTH comment for details
- }
-
- public void writeTo(IDataBuffer data) {
- data.putShort(type.getTypeValue());
- data.putShort(length);
- // Note missing PAD, see MINIMUM_LENGTH comment for details
- }
-
- @Override
- public int hashCode() {
- final int prime = 347;
- int result = 1;
- result = prime * result + length;
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPAction)) {
- return false;
- }
- OFPAction other = (OFPAction) obj;
- if (length != other.length) {
- return false;
- }
- if (type == null) {
- if (other.type != null) {
- return false;
- }
- } else if (!type.equals(other.type)) {
- return false;
- }
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#clone()
- */
- @Override
- public OFPAction clone() throws CloneNotSupportedException {
- return (OFPAction) super.clone();
- }
-
-}
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - July 20, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an action OFPAT_COPY_TTL_IN
- */
-public class OFPActionCopyTimeToLiveIn extends OFPAction {
- public static int MINIMUM_LENGTH = 8;
-
- public OFPActionCopyTimeToLiveIn() {
- super();
- super.setType(OFPActionType.COPY_TTL_IN);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- // PAD
- data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- // PAD
- data.putInt(0);
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - July 20, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an action OFPAT_COPY_TTL_OUT
- */
-public class OFPActionCopyTimeToLiveOut extends OFPAction {
- public static int MINIMUM_LENGTH = 8;
-
- public OFPActionCopyTimeToLiveOut() {
- super();
- super.setType(OFPActionType.COPY_TTL_OUT);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- // PAD
- data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- // PAD
- data.putInt(0);
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - July 20, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an action type OFPAT_DEC_MPLS_TTL
- */
-public class OFPActionDecMplsTimeToLive extends OFPAction {
- public static int MINIMUM_LENGTH = 8;
-
- public OFPActionDecMplsTimeToLive() {
- super();
- super.setType(OFPActionType.DEC_MPLS_TTL);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- // PAD
- data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- // PAD
- data.putInt(0);
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - July 20, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an action type OFPAT_DEC_NW_TTL
- */
-public class OFPActionDecNetworkTimeToLive extends OFPAction {
- public static int MINIMUM_LENGTH = 8;
-
- public OFPActionDecNetworkTimeToLive() {
- super();
- super.setType(OFPActionType.DEC_NW_TTL);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- // PAD
- data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- // PAD
- data.putInt(0);
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - Jul 20, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an ofp_action_experimenter_header
- */
-public class OFPActionExperimenterHeader extends OFPAction {
- public static int MINIMUM_LENGTH = 8;
-
- protected int experimenter;
-
- public OFPActionExperimenterHeader() {
- super.setType(OFPActionType.EXPERIMENTER);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- /**
- * @return the experimenter
- */
- public int getExperimenter() {
- return experimenter;
- }
-
- /**
- * @param experimenter
- * the experimenter to set
- */
- public void setExperimenter(int experimenter) {
- this.experimenter = experimenter;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.experimenter = data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(this.experimenter);
- }
-
- @Override
- public int hashCode() {
- final int prime = 397;
- int result = super.hashCode();
- result = prime * result + experimenter;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPActionExperimenterHeader)) {
- return false;
- }
- OFPActionExperimenterHeader other = (OFPActionExperimenterHeader) obj;
- if (experimenter != other.experimenter) {
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - Jul 20, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an ofp_action_group
- */
-public class OFPActionGroup extends OFPAction {
- public static int MINIMUM_LENGTH = 8;
-
- protected int groupId;
-
- public OFPActionGroup() {
- super.setType(OFPActionType.GROUP);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- /**
- * @return the groupId
- */
- public int getGroupId() {
- return groupId;
- }
-
- /**
- * @param groupId
- * the groupId to set
- */
- public void setGroupId(int groupId) {
- this.groupId = groupId;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.groupId = data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(this.groupId);
- }
-
- @Override
- public int hashCode() {
- final int prime = 353;
- int result = super.hashCode();
- result = prime * result + groupId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPActionGroup)) {
- return false;
- }
- OFPActionGroup other = (OFPActionGroup) obj;
- if (groupId != other.groupId) {
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - July 20, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an action struct ofp_action_mpls_ttl
- */
-public class OFPActionMplsTimeToLive extends OFPAction {
- public static int MINIMUM_LENGTH = 8;
-
- protected byte mplsTimeToLive;
-
- public OFPActionMplsTimeToLive() {
- super.setType(OFPActionType.SET_MPLS_TTL);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- /**
- * @return the mplsTimeToLive
- */
- public short getMplsTimeToLive() {
- return mplsTimeToLive;
- }
-
- /**
- * @param mplsTimeToLive
- * the mplsTimeToLive to set
- */
- public void setMplsTimeToLive(byte mplsTtl) {
- this.mplsTimeToLive = mplsTtl;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.mplsTimeToLive = data.get();
- data.getShort();
- data.get();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putShort(this.mplsTimeToLive);
- data.putShort((short) 0);
- data.put((byte) 0);
- }
-
- @Override
- public int hashCode() {
- final int prime = 359;
- int result = super.hashCode();
- result = prime * result + mplsTimeToLive;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPActionMplsTimeToLive)) {
- return false;
- }
- OFPActionMplsTimeToLive other = (OFPActionMplsTimeToLive) obj;
- if (mplsTimeToLive != other.mplsTimeToLive) {
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - July 20, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an action struct ofp_action_nw_ttl
- */
-public class OFPActionNetworkTimeToLive extends OFPAction {
- public static int MINIMUM_LENGTH = 8;
-
- protected byte networkTimeToLive;
-
- public OFPActionNetworkTimeToLive() {
- super.setType(OFPActionType.SET_NW_TTL);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- /**
- * @return the networkTimeToLive
- */
- public short getNetworkTimeToLive() {
- return networkTimeToLive;
- }
-
- /**
- * @param networkTimeToLive
- * the networkTimeToLive to set
- */
- public void setNetworkTimeToLive(byte networkTtl) {
- this.networkTimeToLive = networkTtl;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.networkTimeToLive = data.get();
- data.getShort();
- data.get();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putShort(this.networkTimeToLive);
- data.putShort((short) 0);
- data.put((byte) 0);
- }
-
- @Override
- public int hashCode() {
- final int prime = 373;
- int result = super.hashCode();
- result = prime * result + networkTimeToLive;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPActionNetworkTimeToLive)) {
- return false;
- }
- OFPActionNetworkTimeToLive other = (OFPActionNetworkTimeToLive) obj;
- if (networkTimeToLive != other.networkTimeToLive) {
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - July 20, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U32;
-
-/**
- * Represents an action struct ofp_action_output
- */
-public class OFPActionOutput extends OFPAction implements Cloneable {
- public static int MINIMUM_LENGTH = 16;
-
- public enum OFControllerMaxLength {
-
- OFPCML_MAX((short) 0xffe5), OFPCML_NO_BUFFER((short) 0xffff);
-
- protected short value;
-
- private OFControllerMaxLength(short value) {
- this.value = value;
- }
-
- /**
- * @return the value
- */
- public short getValue() {
- return value;
- }
- }
-
- protected int port;
- protected short maxLength;
-
- public OFPActionOutput() {
- super.setType(OFPActionType.OUTPUT);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- public OFPActionOutput(int port, short maxLength) {
- super();
- super.setType(OFPActionType.OUTPUT);
- super.setLength((short) MINIMUM_LENGTH);
- this.port = port;
- this.maxLength = maxLength;
- }
-
- /**
- * Get the output port
- *
- * @return
- */
- public int getPort() {
- return this.port;
- }
-
- /**
- * Set the output port
- *
- * @param port
- */
- public OFPActionOutput setPort(int port) {
- this.port = port;
- return this;
- }
-
- /**
- * Get the max length to send to the controller
- *
- * @return
- */
- public short getMaxLength() {
- return this.maxLength;
- }
-
- /**
- * Set the max length to send to the controller
- *
- * @param maxLength
- */
- public OFPActionOutput setMaxLength(short maxLength) {
- this.maxLength = maxLength;
- return this;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.port = data.getInt();
- this.maxLength = data.getShort();
- data.getShort();
- data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(port);
- data.putShort(maxLength);
- data.putShort((short) 0);
- data.putInt(0);
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 367;
- int result = super.hashCode();
- result = prime * result + maxLength;
- result = prime * result + port;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPActionOutput)) {
- return false;
- }
- OFPActionOutput other = (OFPActionOutput) obj;
- if (maxLength != other.maxLength) {
- return false;
- }
- if (port != other.port) {
- return false;
- }
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "OFPActionOutput [maxLength=" + maxLength + ", port=" + U32.f(port) + ", length=" + length + ", type="
- + type + "]";
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - July 20, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an action struct ofp_action_pop_mpls
- */
-public class OFPActionPopMpls extends OFPAction {
- public static int MINIMUM_LENGTH = 8;
-
- protected short etherType;
-
- /**
- * @return the etherType
- */
- public short getEtherType() {
- return etherType;
- }
-
- /**
- * @param etherType
- * the etherType to set
- */
- public void setEtherType(short etherType) {
- this.etherType = etherType;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.etherType = data.getShort();
- data.getShort();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putShort(this.etherType);
- data.putShort((short) 0);
- }
-
- @Override
- public int hashCode() {
- final int prime = 379;
- int result = super.hashCode();
- result = prime * result + etherType;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPActionPopMpls)) {
- return false;
- }
- OFPActionPopMpls other = (OFPActionPopMpls) obj;
- if (etherType != other.etherType) {
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - July 20, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an action type OFPAT_POP_PBB
- */
-public class OFPActionPopPbb extends OFPAction {
- public static int MINIMUM_LENGTH = 8;
-
- public OFPActionPopPbb() {
- super();
- super.setType(OFPActionType.POP_PBB);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- // PAD
- data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- // PAD
- data.putInt(0);
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - July 20, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an action type OFPAT_POP_VLAN
- */
-public class OFPActionPopVLAN extends OFPAction {
- public static int MINIMUM_LENGTH = 8;
-
- public OFPActionPopVLAN() {
- super();
- super.setType(OFPActionType.POP_VLAN);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- // PAD
- data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- // PAD
- data.putInt(0);
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - July 20, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an action struct ofp_action_push
- */
-public class OFPActionPush extends OFPAction {
- public static int MINIMUM_LENGTH = 8;
-
- protected short etherType;
-
- /**
- * @return the etherType
- */
- public short getEtherType() {
- return etherType;
- }
-
- /**
- * @param etherType
- * the etherType to set
- */
- public void setEtherType(short etherType) {
- this.etherType = etherType;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.etherType = data.getShort();
- data.getShort();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putShort(this.etherType);
- data.putShort((short) 0);
- }
-
- @Override
- public int hashCode() {
- final int prime = 389;
- int result = super.hashCode();
- result = prime * result + etherType;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPActionPush)) {
- return false;
- }
- OFPActionPush other = (OFPActionPush) obj;
- if (etherType != other.etherType) {
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
+++ /dev/null
-package org.openflow.codec.protocol.action;
-
-/**
- * Represents an action type OFPAT_PUSH_MPLS
- *
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com)
- */
-public class OFPActionPushMpls extends OFPActionPush {
- public OFPActionPushMpls() {
- super();
- super.setType(OFPActionType.PUSH_MPLS);
- super.setLength((short) OFPActionPushMpls.MINIMUM_LENGTH);
- }
-}
\ No newline at end of file
+++ /dev/null
-package org.openflow.codec.protocol.action;
-
-/**
- * Represents an action type OFPAT_PUSH_PBB
- *
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com)
- */
-public class OFPActionPushPbb extends OFPActionPush {
- public OFPActionPushPbb() {
- super();
- super.setType(OFPActionType.PUSH_PBB);
- super.setLength((short) OFPActionPushPbb.MINIMUM_LENGTH);
- }
-}
\ No newline at end of file
+++ /dev/null
-package org.openflow.codec.protocol.action;
-
-/**
- * Represents an action type OFPAT_PUSH_VLAN
- *
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com)
- */
-public class OFPActionPushVLAN extends OFPActionPush {
- public OFPActionPushVLAN() {
- super();
- super.setType(OFPActionType.PUSH_VLAN);
- super.setLength((short) OFPActionPushVLAN.MINIMUM_LENGTH);
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - July 21, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFBMatchFields;
-import org.openflow.codec.protocol.OXMClass;
-import org.openflow.codec.protocol.OXMField;
-
-/**
- * Represents an action struct ofp_action_set_field
- */
-public class OFPActionSetField extends OFPAction {
- public static int MINIMUM_LENGTH = 8;
-
- // OXM TLV
- OXMField oxmtlvField;
-
- // Contructors
- public OFPActionSetField() {
- super.setType(OFPActionType.SET_FIELD);
- super.setLength((short) MINIMUM_LENGTH);
- oxmtlvField = new OXMField();
- }
-
- public OFPActionSetField(OXMClass classType, OFBMatchFields matchField, boolean hasMask, byte[] data) {
- oxmtlvField = new OXMField(classType, matchField, hasMask, data);
- }
-
- // Get Set Methods
- public OXMClass getOXMClassType() {
- return this.oxmtlvField.getOXMClassType();
- }
-
- public void setOXMClassType(OXMClass OXMClassType) {
- this.oxmtlvField.setOXMClassType(OXMClassType);
- }
-
- public OFBMatchFields getMatchField() {
- return this.oxmtlvField.getMatchField();
- }
-
- public void setMatchField(OFBMatchFields matchField) {
- this.oxmtlvField.setMatchField(matchField);
- }
-
- public boolean isHasMask() {
- return this.oxmtlvField.isHasMask();
- }
-
- public void setHasMask(boolean hasMask) {
- this.oxmtlvField.setHasMask(hasMask);
- }
-
- /**
- * to get the total length of match field (or TLV) including header in bytes
- *
- * @return
- */
- public byte getFieldLength() {
- // Type + Lenghth + Value
- return this.oxmtlvField.getLength();
- }
-
- public byte[] getData() {
- return this.oxmtlvField.getData();
- }
-
- public void setData(byte[] data) {
- this.oxmtlvField.setData(data);
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- if (oxmtlvField == null)
- oxmtlvField = new OXMField();
- oxmtlvField.readFrom(data);
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- oxmtlvField.writeTo(data);
- }
-
- @Override
- public int hashCode() {
- final int prime = 353;
- int result = super.hashCode();
- result = prime * result + (oxmtlvField == null ? 0 : oxmtlvField.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPActionSetField)) {
- return false;
- }
- OFPActionSetField other = (OFPActionSetField) obj;
- if (this.oxmtlvField.getMatchField() != other.oxmtlvField.getMatchField()) {
- return false;
- }
- return true;
- }
-
-}
\ No newline at end of file
+++ /dev/null
-/**
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - July 20, 2013
- */
-package org.openflow.codec.protocol.action;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an action struct ofp_action_set_queue
- */
-public class OFPActionSetQueue extends OFPAction {
- public static int MINIMUM_LENGTH = 8;
-
- protected int queueId;
-
- public OFPActionSetQueue() {
- super.setType(OFPActionType.SET_QUEUE);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- /**
- * @return the queueIdentifier
- */
- public int getVirtualLanIdentifier() {
- return queueId;
- }
-
- /**
- * @param queueIdentifier
- * the queueIdentifier to set
- */
- public void setQueueIdentifier(int queueIdentifier) {
- this.queueId = queueIdentifier;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.queueId = data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(this.queueId);
- }
-
- @Override
- public int hashCode() {
- final int prime = 349;
- int result = super.hashCode();
- result = prime * result + queueId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPActionSetQueue)) {
- return false;
- }
- OFPActionSetQueue other = (OFPActionSetQueue) obj;
- if (queueId != other.queueId) {
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
- *
- */
-package org.openflow.codec.protocol.action;
-
-import java.io.Serializable;
-import java.lang.reflect.Constructor;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.openflow.codec.protocol.Instantiable;
-
-/**
- * List of OpenFlow Action types and mappings to wire protocol value and derived
- * classes
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com)
- */
-public enum OFPActionType implements Serializable {
- OUTPUT(0, OFPActionOutput.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionOutput();
- }
- }), COPY_TTL_OUT(11, OFPActionCopyTimeToLiveOut.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionCopyTimeToLiveOut();
- }
- }), COPY_TTL_IN(12, OFPActionCopyTimeToLiveIn.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionCopyTimeToLiveIn();
- }
- }), SET_MPLS_TTL(15, OFPActionMplsTimeToLive.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionMplsTimeToLive();
- }
- }), DEC_MPLS_TTL(16, OFPActionDecMplsTimeToLive.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionDecMplsTimeToLive();
- }
- }), PUSH_VLAN(17, OFPActionPushVLAN.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionPushVLAN();
- }
- }), POP_VLAN(18, OFPActionPopVLAN.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionPopVLAN();
- }
- }), PUSH_MPLS(19, OFPActionPushMpls.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionPushMpls();
- }
- }), POP_MPLS(20, OFPActionPopMpls.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionPopMpls();
- }
- }), SET_QUEUE(21, OFPActionSetQueue.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionSetQueue();
- }
- }), GROUP(22, OFPActionGroup.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionGroup();
- }
- }), SET_NW_TTL(23, OFPActionNetworkTimeToLive.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionNetworkTimeToLive();
- }
- }), DEC_NW_TTL(24, OFPActionDecNetworkTimeToLive.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionDecNetworkTimeToLive();
- }
- }), SET_FIELD(25, OFPActionSetField.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionSetField();
- }
- }), PUSH_PBB(26, OFPActionPushPbb.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionPushPbb();
- }
- }), POP_PBB(27, OFPActionPopPbb.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionPopPbb();
- }
- }),
-
- EXPERIMENTER(0xffff, OFPActionExperimenterHeader.class, new Instantiable<OFPAction>() {
- @Override
- public OFPAction instantiate() {
- return new OFPActionExperimenterHeader();
- }
- });
-
- protected static HashMap<Short, OFPActionType> mapping;
-
- protected Class<? extends OFPAction> clazz;
- protected Constructor<? extends OFPAction> constructor;
- protected Instantiable<OFPAction> instantiable;
- protected int minLen;
- protected short type;
-
- /**
- * Store some information about the OpenFlow Action type, including wire
- * protocol type number, length, and derrived class
- *
- * @param type
- * Wire protocol number associated with this OFPType
- * @param clazz
- * The Java class corresponding to this type of OpenFlow Action
- * @param instantiable
- * the instantiable for the OFPAction this type represents
- */
- OFPActionType(int type, Class<? extends OFPAction> clazz, Instantiable<OFPAction> instantiable) {
- this.type = (short) type;
- this.clazz = clazz;
- this.instantiable = instantiable;
- try {
- this.constructor = clazz.getConstructor(new Class[] {});
- } catch (Exception e) {
- throw new RuntimeException("Failure getting constructor for class: " + clazz, e);
- }
- OFPActionType.addMapping(this.type, this);
- }
-
- /**
- * Adds a mapping from type value to OFPActionType enum
- *
- * @param i
- * OpenFlow wire protocol Action type value
- * @param t
- * type
- */
- static public void addMapping(short i, OFPActionType t) {
- if (mapping == null)
- mapping = new HashMap<Short, OFPActionType>();
- // bring higher mappings down to the edge of our map
- if (i < 0)
- i = (short) (30 + i);
- mapping.put(i, t);
- }
-
- /**
- * Given a wire protocol OpenFlow type number, return the OFPType associated
- * with it
- *
- * @param i
- * wire protocol number
- * @return OFPType enum type
- */
-
- static public OFPActionType valueOf(short i) {
- if (i < 0)
- i = (short) (30 + i);
- return OFPActionType.mapping.get(i);
- }
-
- /**
- * @return Returns the wire protocol value corresponding to this
- * OFPActionType
- */
- public short getTypeValue() {
- return this.type;
- }
-
- /**
- * @return return the OFPAction subclass corresponding to this OFPActionType
- */
- public Class<? extends OFPAction> toClass() {
- return clazz;
- }
-
- /**
- * Returns the no-argument Constructor of the implementation class for this
- * OFPActionType
- *
- * @return the constructor
- */
- public Constructor<? extends OFPAction> getConstructor() {
- return constructor;
- }
-
- /**
- * Returns a new instance of the OFPAction represented by this OFPActionType
- *
- * @return the new object
- */
- public OFPAction newInstance() {
- return instantiable.instantiate();
- }
-
- /**
- * @return the instantiable
- */
- public Instantiable<OFPAction> getInstantiable() {
- return instantiable;
- }
-
- /**
- * @param instantiable
- * the instantiable to set
- */
- public void setInstantiable(Instantiable<OFPAction> instantiable) {
- this.instantiable = instantiable;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.action;
-
-import java.io.Serializable;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.factory.OFPActionFactory;
-import org.openflow.codec.protocol.factory.OFPActionFactoryAware;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_bucket structure
- *
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com)
- *
- */
-public class OFPBucket implements OFPActionFactoryAware, Cloneable, Serializable {
- public static int MINIMUM_LENGTH = 16;
-
- protected OFPActionFactory actionFactory;
- protected short length;
- protected short weight;
- protected int watch_port;
- protected int watch_group;
- protected List<OFPAction> actions;
-
- public OFPBucket() {
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * Get the length of this message
- *
- * @return
- */
- public short getLength() {
- return length;
- }
-
- /**
- * Get the length of this message, unsigned
- *
- * @return
- */
- public int getLengthU() {
- return U16.f(length);
- }
-
- /**
- * Set the length of this message
- *
- * @param length
- */
- public OFPBucket setLength(short length) {
- this.length = length;
- return this;
- }
-
- public short getWeight() {
- return weight;
- }
-
- public OFPBucket setWeight(short weight) {
- this.weight = weight;
- return this;
- }
-
- public int getWatch_port() {
- return watch_port;
- }
-
- public OFPBucket setWatch_port(int watch_port) {
- this.watch_port = watch_port;
- return this;
- }
-
- public int getWatch_group() {
- return watch_group;
- }
-
- public OFPBucket setWatch_group(int watch_group) {
- this.watch_group = watch_group;
- return this;
- }
-
- public List<OFPAction> getActions() {
- return actions;
- }
-
- public OFPBucket setActions(List<OFPAction> actions) {
- this.actions = actions;
- return this;
- }
-
- /**
- * Returns a summary of the message
- *
- * @return "ofmsg=v=$version;t=$type:l=$len:xid=$xid"
- */
- public String toString() {
- return "ofbucket" + ";length=" + this.getLength() + ";length=" + this.getWeight() + ";length="
- + this.getWatch_port() + ";length=" + this.getWatch_group();
- }
-
- /**
- * Given the output from toString(), create a new OFPBucket
- *
- * @param val
- * @return
- */
- public static OFPBucket fromString(String val) {
- String tokens[] = val.split(";");
- if (!tokens[0].equals("ofbucket"))
- throw new IllegalArgumentException("expected 'ofbucket' but got '" + tokens[0] + "'");
- String type_tokens[] = tokens[1].split("=");
- String len_tokens[] = tokens[2].split("=");
- OFPBucket bucket = new OFPBucket();
- bucket.setLength(Short.valueOf(len_tokens[1]));
- return bucket;
- }
-
- public void readFrom(IDataBuffer data) {
- this.length = data.getShort();
- this.weight = data.getShort();
- this.watch_port = data.getInt();
- this.watch_group = data.getInt();
- data.getInt();
- if (this.actionFactory == null)
- throw new RuntimeException("OFPActionFactory not set");
- this.actions = this.actionFactory.parseActions(data, getLengthU() - MINIMUM_LENGTH);
- }
-
- public void writeTo(IDataBuffer data) {
- data.putShort(length);
- data.putShort(weight);
- data.putInt(watch_port);
- data.putInt(watch_group);
- data.putInt(0);
- if (actions != null) {
- for (OFPAction action : actions) {
- action.writeTo(data);
- }
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 347;
- int result = 1;
- result = prime * result + ((actions == null) ? 0 : actions.hashCode());
- result = prime * result + length;
- result = prime * result + weight;
- result = prime * result + watch_port;
- result = prime * result + watch_group;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPBucket)) {
- return false;
- }
- OFPBucket other = (OFPBucket) obj;
- if (actions == null) {
- if (other.actions != null) {
- return false;
- }
- } else if (!actions.equals(other.actions)) {
- return false;
- }
- if (length != other.length) {
- return false;
- }
- if (weight != other.weight) {
- return false;
- }
- if (watch_port != other.watch_port) {
- return false;
- }
- if (watch_group != other.watch_group) {
- return false;
- }
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#clone()
- */
- @Override
- public OFPBucket clone() throws CloneNotSupportedException {
- return (OFPBucket) super.clone();
- }
-
- @Override
- public void setActionFactory(OFPActionFactory actionFactory) {
- this.actionFactory = actionFactory;
-
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.action;
-
-import java.io.Serializable;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an ofp_bucket_counter structure
- *
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com)
- *
- */
-public class OFPBucketCounter implements Cloneable, Serializable {
- public static int MINIMUM_LENGTH = 16;
-
- protected long packet_count;
- protected long byte_count;
-
- public OFPBucketCounter() {
-
- }
-
- public long getPacket_count() {
- return packet_count;
- }
-
- public OFPBucketCounter setPacket_count(long packet_count) {
- this.packet_count = packet_count;
- return this;
- }
-
- public long getByte_count() {
- return byte_count;
- }
-
- public OFPBucketCounter setByte_count(long byte_count) {
- this.byte_count = byte_count;
- return this;
- }
-
- public String toString() {
- return "ofbucketcounter" + ";packet_count=" + this.getPacket_count() + ";byte_count=" + this.getByte_count();
- }
-
- /**
- * Given the output from toString(), create a new OFPBucketCounter
- *
- * @param val
- * @return
- */
- public static OFPBucketCounter fromString(String val) {
- String tokens[] = val.split(";");
- if (!tokens[0].equals("ofbucket"))
- throw new IllegalArgumentException("expected 'ofbucketcounter' but got '" + tokens[0] + "'");
- String packet_token[] = tokens[1].split("=");
- String byte_token[] = tokens[2].split("=");
- OFPBucketCounter bucketCounter = new OFPBucketCounter();
- bucketCounter.setPacket_count(Long.valueOf(packet_token[1]));
- bucketCounter.setByte_count(Long.valueOf(byte_token[2]));
- return bucketCounter;
- }
-
- public void readFrom(IDataBuffer data) {
- this.packet_count = data.getLong();
- this.byte_count = data.getLong();
- }
-
- public void writeTo(IDataBuffer data) {
- data.putLong(packet_count);
- data.putLong(byte_count);
- }
-
- @Override
- public int hashCode() {
- final int prime = 347;
- int result = 1;
- result = prime * result + (int) (packet_count ^ (packet_count >>> 32));
- result = prime * result + (int) (byte_count ^ (byte_count >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPBucketCounter)) {
- return false;
- }
- OFPBucketCounter other = (OFPBucketCounter) obj;
- if (packet_count != other.packet_count) {
- return false;
- }
- if (byte_count != other.byte_count) {
- return false;
- }
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#clone()
- */
- @Override
- public OFPBucketCounter clone() throws CloneNotSupportedException {
- return (OFPBucketCounter) super.clone();
- }
-
-}
+++ /dev/null
-/**
- *
- */
-package org.openflow.codec.protocol.action;
-
-import java.io.Serializable;
-
-/**
- * List of OpenFlow Group types and mappings to wire protocol value and derived
- * classes
- *
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com)
- */
-public enum OFPGroupType implements Serializable {
-
- OFPGT_ALL((short) 0), /* All (multicast/broadcast) group. */
- OFPGT_SELECT((short) 1), /* Select group. */
- OFPGT_INDIRECT((short) 2), /* Indirect group. */
- OFPGT_FF((short) 3); /* Fast failover group. */
-
- protected short value;
-
- private OFPGroupType(short value) {
- this.value = value;
- }
-
- /**
- * @return the value
- */
- public short getValue() {
- return value;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.factory;
-
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.action.OFPAction;
-import org.openflow.codec.protocol.action.OFPActionType;
-
-/**
- * The interface to factories used for retrieving OFPAction instances. All
- * methods are expected to be thread-safe.
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public interface OFPActionFactory {
- /**
- * Retrieves an OFPAction instance corresponding to the specified
- * OFPActionType
- *
- * @param t
- * the type of the OFPAction to be retrieved
- * @return an OFPAction instance
- */
- public OFPAction getAction(OFPActionType t);
-
- /**
- * Attempts to parse and return all OFActions contained in the given
- * DataBuffer, beginning at the DataBuffer's position, and ending at
- * position+length.
- *
- * @param data
- * the DataBuffer to parse for OpenFlow actions
- * @param length
- * the number of Bytes to examine for OpenFlow actions
- * @return a list of OFPAction instances
- */
- public List<OFPAction> parseActions(IDataBuffer data, int length);
-
- /**
- * Attempts to parse and return all OFActions contained in the given
- * DataBuffer, beginning at the DataBuffer's position, and ending at
- * position+length.
- *
- * @param data
- * the DataBuffer to parse for OpenFlow actions
- * @param length
- * the number of Bytes to examine for OpenFlow actions
- * @param limit
- * the maximum number of messages to return, 0 means no limit
- * @return a list of OFPAction instances
- */
- public List<OFPAction> parseActions(IDataBuffer data, int length, int limit);
-}
+++ /dev/null
-package org.openflow.codec.protocol.factory;
-
-/**
- * Objects implementing this interface are expected to be instantiated with an
- * instance of an OFPActionFactory
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public interface OFPActionFactoryAware {
- /**
- * Sets the OFPActionFactory
- *
- * @param actionFactory
- */
- public void setActionFactory(OFPActionFactory actionFactory);
-}
+++ /dev/null
-package org.openflow.codec.protocol.factory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPMessage;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.protocol.action.OFPAction;
-import org.openflow.codec.protocol.action.OFPActionType;
-import org.openflow.codec.protocol.instruction.OFPInstruction;
-import org.openflow.codec.protocol.instruction.OFPInstructionType;
-import org.openflow.codec.protocol.queue.OFPQueueProperty;
-import org.openflow.codec.protocol.queue.OFPQueuePropertyType;
-import org.openflow.codec.protocol.statistics.OFPExtStatistics;
-import org.openflow.codec.protocol.statistics.OFPMultipartTypes;
-import org.openflow.codec.protocol.statistics.OFPStatistics;
-
-/**
- * A basic OpenFlow factory that supports naive creation of both Messages and
- * Actions.
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- *
- */
-public class OFPBasicFactoryImpl implements OFPMessageFactory, OFPActionFactory, OFPQueuePropertyFactory,
- OFPStatisticsFactory, OFPInstructionFactory {
- @Override
- public OFPMessage getMessage(OFPType t) {
- return t.newInstance();
- }
-
- @Override
- public List<OFPMessage> parseMessages(IDataBuffer data) {
- return parseMessages(data, 0);
- }
-
- @Override
- public List<OFPMessage> parseMessages(IDataBuffer data, int limit) {
- List<OFPMessage> results = new ArrayList<OFPMessage>();
- OFPMessage demux = new OFPMessage();
- OFPMessage ofm;
-
- while (limit == 0 || results.size() <= limit) {
- if (data.remaining() < OFPMessage.MINIMUM_LENGTH)
- return results;
-
- data.mark();
- demux.readFrom(data);
- data.reset();
-
- if (demux.getLengthU() > data.remaining())
- return results;
-
- ofm = getMessage(demux.getType());
- if (ofm instanceof OFPActionFactoryAware) {
- ((OFPActionFactoryAware) ofm).setActionFactory(this);
- }
- if (ofm instanceof OFPInstructionFactoryAware) {
- ((OFPInstructionFactoryAware) ofm).setInstructionFactory(this);
- }
- if (ofm instanceof OFPMessageFactoryAware) {
- ((OFPMessageFactoryAware) ofm).setMessageFactory(this);
- }
- if (ofm instanceof OFPQueuePropertyFactoryAware) {
- ((OFPQueuePropertyFactoryAware) ofm).setQueuePropertyFactory(this);
- }
- if (ofm instanceof OFPStatisticsFactoryAware) {
- ((OFPStatisticsFactoryAware) ofm).setStatisticsFactory(this);
- }
- ofm.readFrom(data);
- if (OFPMessage.class.equals(ofm.getClass())) {
- // advance the position for un-implemented messages
- data.position(data.position() + (ofm.getLengthU() - OFPMessage.MINIMUM_LENGTH));
- }
- results.add(ofm);
- }
-
- return results;
- }
-
- @Override
- public OFPAction getAction(OFPActionType t) {
- return t.newInstance();
- }
-
- @Override
- public List<OFPAction> parseActions(IDataBuffer data, int length) {
- return parseActions(data, length, 0);
- }
-
- @Override
- public List<OFPAction> parseActions(IDataBuffer data, int length, int limit) {
- List<OFPAction> results = new ArrayList<OFPAction>();
- OFPAction demux = new OFPAction();
- OFPAction ofa;
- int end = data.position() + length;
-
- while (limit == 0 || results.size() <= limit) {
- if (data.remaining() < OFPAction.MINIMUM_LENGTH || (data.position() + OFPAction.MINIMUM_LENGTH) > end)
- return results;
-
- data.mark();
- demux.readFrom(data);
- data.reset();
-
- if (demux.getLengthU() > data.remaining() || (data.position() + demux.getLengthU()) > end)
- return results;
-
- ofa = getAction(demux.getType());
- ofa.readFrom(data);
- if (OFPAction.class.equals(ofa.getClass())) {
- // advance the position for un-implemented messages
- data.position(data.position() + (ofa.getLengthU() - OFPAction.MINIMUM_LENGTH));
- }
- results.add(ofa);
- }
-
- return results;
- }
-
- @Override
- public OFPActionFactory getActionFactory() {
- return this;
- }
-
- @Override
- public OFPStatistics getStatistics(OFPType t, OFPMultipartTypes st) {
- return st.newInstance(t);
- }
-
- @Override
- public List<OFPStatistics> parseStatistics(OFPType t, OFPMultipartTypes st, IDataBuffer data, int length) {
- return parseStatistics(t, st, data, length, 0);
- }
-
- /**
- * @param t
- * OFPMessage type: should be one of stats_request or stats_reply
- * @param st
- * statistics type of this message, e.g., DESC, TABLE
- * @param data
- * buffer to read from
- * @param length
- * length of statistics
- * @param limit
- * number of statistics to grab; 0 == all
- *
- * @return list of statistics
- */
-
- @Override
- public List<OFPStatistics> parseStatistics(OFPType t, OFPMultipartTypes st, IDataBuffer data, int length, int limit) {
- List<OFPStatistics> results = new ArrayList<OFPStatistics>();
- OFPStatistics statistics = getStatistics(t, st);
-
- int start = data.position();
- int count = 0;
-
- while (limit == 0 || results.size() <= limit) {
- // set the length in case of OFPExtStatistics
- if (statistics instanceof OFPExtStatistics)
- ((OFPExtStatistics) statistics).setLength(length);
-
- /**
- * can't use data.remaining() here, b/c there could be other data
- * buffered past this message
- */
- if ((length - count) >= statistics.getLength()) {
- if (statistics instanceof OFPActionFactoryAware)
- ((OFPActionFactoryAware) statistics).setActionFactory(this);
- statistics.readFrom(data);
- results.add(statistics);
- count += statistics.getLength();
- statistics = getStatistics(t, st);
- } else {
- if (count < length) {
- /**
- * Nasty case: partial/incomplete statistic found even
- * though we have a full message. Found when NOX sent
- * agg_stats request with wrong agg statistics length (52
- * instead of 56)
- *
- * just throw the rest away, or we will break framing
- */
- data.position(start + length);
- }
- return results;
- }
- }
- return results; // empty; no statistics at all
- }
-
- @Override
- public OFPQueueProperty getQueueProperty(OFPQueuePropertyType t) {
- return t.newInstance();
- }
-
- @Override
- public List<OFPQueueProperty> parseQueueProperties(IDataBuffer data, int length) {
- return parseQueueProperties(data, length, 0);
- }
-
- @Override
- public List<OFPQueueProperty> parseQueueProperties(IDataBuffer data, int length, int limit) {
- List<OFPQueueProperty> results = new ArrayList<OFPQueueProperty>();
- OFPQueueProperty demux = new OFPQueueProperty();
- OFPQueueProperty ofqp;
- int end = data.position() + length;
-
- while (limit == 0 || results.size() <= limit) {
- if (data.remaining() < OFPQueueProperty.MINIMUM_LENGTH
- || (data.position() + OFPQueueProperty.MINIMUM_LENGTH) > end)
- return results;
-
- data.mark();
- demux.readFrom(data);
- data.reset();
-
- if (demux.getLengthU() > data.remaining() || (data.position() + demux.getLengthU()) > end)
- return results;
-
- ofqp = getQueueProperty(demux.getType());
- ofqp.readFrom(data);
- if (OFPQueueProperty.class.equals(ofqp.getClass())) {
- // advance the position for un-implemented messages
- data.position(data.position() + (ofqp.getLengthU() - OFPQueueProperty.MINIMUM_LENGTH));
- }
- results.add(ofqp);
- }
-
- return results;
- }
-
- @Override
- public OFPInstruction getInstruction(OFPInstructionType type) {
-
- return type.newInstance();
- }
-
- @Override
- public List<OFPInstruction> parseInstructions(IDataBuffer data, int length) {
- return this.parseInstructions(data, length, 0);
- }
-
- @Override
- public List<OFPInstruction> parseInstructions(IDataBuffer data, int length, int limit) {
- List<OFPInstruction> results = new ArrayList<OFPInstruction>();
- OFPInstruction demux = new OFPInstruction();
- OFPInstruction ofInstruction;
- int end = data.position() + length;
-
- while (limit == 0 || results.size() <= limit) {
- if (data.remaining() < OFPInstruction.MINIMUM_LENGTH
- || (data.position() + OFPInstruction.MINIMUM_LENGTH) > end)
- return results;
-
- data.mark();
- demux.readFrom(data);
- data.reset();
-
- if (demux.getLengthU() > data.remaining() || (data.position() + demux.getLengthU()) > end) {
- return results;
- }
- // get instruction type
- ofInstruction = getInstruction(demux.getOFInstructionType());
- // set action factory
- if (ofInstruction instanceof OFPActionFactoryAware) {
- ((OFPActionFactoryAware) ofInstruction).setActionFactory(this);
- }
- ofInstruction.readFrom(data);
- // TBD - about commented part
- // if (OFPInstruction.class.equals(ofInstruction.getClass())) {
- // // advance the position for un-implemented messages
- // data.position(data.position()+(ofInstruction.getLengthU() -
- // OFPInstruction.MINIMUM_LENGTH));
- // }
- results.add(ofInstruction);
- }
-
- return results;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.factory;
-
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.instruction.OFPInstruction;
-import org.openflow.codec.protocol.instruction.OFPInstructionType;
-
-/**
- * The interface to factories used for retrieving OFPInstruction instances. All
- * methods are expected to be thread-safe.
- *
- * @author AnilGujele
- */
-public interface OFPInstructionFactory {
- /**
- * Retrieves an OFPInstruction instance corresponding to the specified
- * OFPInstructionType
- *
- * @param t
- * the type of the OFPInstruction to be retrieved
- * @return an OFPInstruction instance
- */
- public OFPInstruction getInstruction(OFPInstructionType t);
-
- /**
- * Attempts to parse and return all OFInstructions contained in the given
- * DataBuffer, beginning at the DataBuffer's position, and ending at
- * position+length.
- *
- * @param data
- * the DataBuffer to parse for OpenFlow Instructions
- * @param length
- * the number of Bytes to examine for OpenFlow Instructions
- * @return a list of OFPInstruction instances
- */
- public List<OFPInstruction> parseInstructions(IDataBuffer data, int length);
-
- /**
- * Attempts to parse and return number of specified OFInstructions contained
- * in the given DataBuffer, beginning at the DataBuffer's position, and
- * ending at position+length.
- *
- * @param data
- * the DataBuffer to parse for OpenFlow Instructions
- * @param length
- * the number of Bytes to examine for OpenFlow Instructions
- * @param limit
- * the maximum number of messages to return, 0 means no limit
- * @return a list of OFPInstruction instances
- */
- public List<OFPInstruction> parseInstructions(IDataBuffer data, int length, int limit);
-}
+++ /dev/null
-package org.openflow.codec.protocol.factory;
-
-/**
- * Objects implementing this interface are expected to be instantiated with an
- * instance of an OFPInstructionFactory
- *
- * @author AnilGujele
- */
-public interface OFPInstructionFactoryAware {
- /**
- * Sets the OFPInstructionFactory
- *
- * @param instructionFactory
- */
- public void setInstructionFactory(OFPInstructionFactory instructionFactory);
-}
+++ /dev/null
-package org.openflow.codec.protocol.factory;
-
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPMessage;
-import org.openflow.codec.protocol.OFPType;
-
-/**
- * The interface to factories used for retrieving OFPMessage instances. All
- * methods are expected to be thread-safe.
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public interface OFPMessageFactory {
- /**
- * Retrieves an OFPMessage instance corresponding to the specified OFPType
- *
- * @param t
- * the type of the OFPMessage to be retrieved
- * @return an OFPMessage instance
- */
- public OFPMessage getMessage(OFPType t);
-
- /**
- * Attempts to parse and return all OFMessages contained in the given
- * DataBuffer, beginning at the DataBuffer's position, and ending at the
- * DataBuffer's limit.
- *
- * @param data
- * the DataBuffer to parse for an OpenFlow message
- * @return a list of OFPMessage instances
- */
- public List<OFPMessage> parseMessages(IDataBuffer data);
-
- /**
- * Attempts to parse and return all OFMessages contained in the given
- * DataBuffer, beginning at the DataBuffer's position, and ending at the
- * DataBuffer's limit.
- *
- * @param data
- * the DataBuffer to parse for an OpenFlow message
- * @param limit
- * the maximum number of messages to return, 0 means no limit
- * @return a list of OFPMessage instances
- */
- public List<OFPMessage> parseMessages(IDataBuffer data, int limit);
-
- /**
- * Retrieves an OFPActionFactory
- *
- * @return an OFPActionFactory
- */
- public OFPActionFactory getActionFactory();
-}
+++ /dev/null
-/**
- *
- */
-package org.openflow.codec.protocol.factory;
-
-/**
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- *
- */
-public interface OFPMessageFactoryAware {
-
- /**
- * Sets the message factory for this object
- *
- * @param factory
- */
- void setMessageFactory(OFPMessageFactory factory);
-}
+++ /dev/null
-package org.openflow.codec.protocol.factory;
-
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.queue.OFPQueueProperty;
-import org.openflow.codec.protocol.queue.OFPQueuePropertyType;
-
-/**
- * The interface to factories used for retrieving OFPQueueProperty instances.
- * All methods are expected to be thread-safe.
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public interface OFPQueuePropertyFactory {
- /**
- * Retrieves an OFPQueueProperty instance corresponding to the specified
- * OFPQueuePropertyType
- *
- * @param t
- * the type of the OFPQueueProperty to be retrieved
- * @return an OFPQueueProperty instance
- */
- public OFPQueueProperty getQueueProperty(OFPQueuePropertyType t);
-
- /**
- * Attempts to parse and return all OFQueueProperties contained in the given
- * DataBuffer, beginning at the DataBuffer's position, and ending at
- * position+length.
- *
- * @param data
- * the DataBuffer to parse for OpenFlow OFQueueProperties
- * @param length
- * the number of Bytes to examine for OpenFlow OFQueueProperties
- * @return a list of OFPQueueProperty instances
- */
- public List<OFPQueueProperty> parseQueueProperties(IDataBuffer data, int length);
-
- /**
- * Attempts to parse and return all OFQueueProperties contained in the given
- * DataBuffer, beginning at the DataBuffer's position, and ending at
- * position+length.
- *
- * @param data
- * the DataBuffer to parse for OpenFlow OFQueueProperties
- * @param length
- * the number of Bytes to examine for OpenFlow OFQueueProperties
- * @param limit
- * the maximum number of OFQueueProperties to return, 0 means no
- * limit
- * @return a list of OFPQueueProperty instances
- */
- public List<OFPQueueProperty> parseQueueProperties(IDataBuffer data, int length, int limit);
-}
+++ /dev/null
-package org.openflow.codec.protocol.factory;
-
-/**
- * Objects implementing this interface are expected to be instantiated with an
- * instance of an OFPQueuePropertyFactory
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public interface OFPQueuePropertyFactoryAware {
- /**
- * Sets the OFPQueuePropertyFactory
- *
- * @param queuePropertyFactory
- */
- public void setQueuePropertyFactory(OFPQueuePropertyFactory queuePropertyFactory);
-}
+++ /dev/null
-package org.openflow.codec.protocol.factory;
-
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.protocol.statistics.OFPMultipartTypes;
-import org.openflow.codec.protocol.statistics.OFPStatistics;
-
-/**
- * The interface to factories used for retrieving OFPStatistics instances. All
- * methods are expected to be thread-safe.
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public interface OFPStatisticsFactory {
- /**
- * Retrieves an OFPStatistics instance corresponding to the specified
- * OFStatisticsType
- *
- * @param t
- * the type of the containing OFPMessage, only accepts statistics
- * request or reply
- * @param st
- * the type of the OFPStatistics to be retrieved
- * @return an OFPStatistics instance
- */
- public OFPStatistics getStatistics(OFPType t, OFPMultipartTypes st);
-
- /**
- * Attempts to parse and return all OFPStatistics contained in the given
- * DataBuffer, beginning at the DataBuffer's position, and ending at
- * position+length.
- *
- * @param t
- * the type of the containing OFPMessage, only accepts statistics
- * request or reply
- * @param st
- * the type of the OFPStatistics to be retrieved
- * @param data
- * the DataBuffer to parse for OpenFlow Statistics
- * @param length
- * the number of Bytes to examine for OpenFlow Statistics
- * @return a list of OFPStatistics instances
- */
- public List<OFPStatistics> parseStatistics(OFPType t, OFPMultipartTypes st, IDataBuffer data, int length);
-
- /**
- * Attempts to parse and return all OFPStatistics contained in the given
- * DataBuffer, beginning at the DataBuffer's position, and ending at
- * position+length.
- *
- * @param t
- * the type of the containing OFPMessage, only accepts statistics
- * request or reply
- * @param st
- * the type of the OFPStatistics to be retrieved
- * @param data
- * the DataBuffer to parse for OpenFlow Statistics
- * @param length
- * the number of Bytes to examine for OpenFlow Statistics
- * @param limit
- * the maximum number of messages to return, 0 means no limit
- * @return a list of OFPStatistics instances
- */
- public List<OFPStatistics> parseStatistics(OFPType t, OFPMultipartTypes st, IDataBuffer data, int length, int limit);
-}
+++ /dev/null
-package org.openflow.codec.protocol.factory;
-
-/**
- * Objects implementing this interface are expected to be instantiated with an
- * instance of an OFPStatisticsFactory
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public interface OFPStatisticsFactoryAware {
- /**
- * Sets the OFPStatisticsFactory
- *
- * @param statisticsFactory
- */
- public void setStatisticsFactory(OFPStatisticsFactory statisticsFactory);
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-import java.io.Serializable;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * correspond to struct ofp_instruction openflow structure Instruction header
- * that is common to all instructions. The length field includes the header and
- * any padding used to make the instruction 64-bit aligned.
- *
- * @author AnilGujele
- *
- */
-public class OFPInstruction implements Cloneable, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- public static final short MINIMUM_LENGTH = 4;
-
- protected short length;
- protected OFPInstructionType type;
-
- /**
- * get the length of instruction structure
- *
- * @return
- */
- public short getLength() {
- return length;
- }
-
- /**
- * set the length of instruction structure
- *
- * @param length
- */
- public void setLength(short length) {
- this.length = length;
- }
-
- /**
- * get the unsigned length of instruction structure
- *
- * @return
- */
- public int getLengthU() {
- return U16.f(length);
- }
-
- /**
- * get the OFInstrutionType
- *
- * @return
- */
- public OFPInstructionType getOFInstructionType() {
- return type;
- }
-
- /**
- * set the OFPInstructionType
- *
- * @param type
- */
- public void setOFInstructionType(OFPInstructionType type) {
- this.type = type;
- }
-
- /**
- * read OFPInstruction object state from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- this.type = OFPInstructionType.valueOf(data.getShort());
- this.length = data.getShort();
- }
-
- /**
- * write OFPInstruction object state to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- data.putShort(type.getTypeValue());
- data.putShort(this.length);
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 741;
- int result = 1;
- result = prime * result + length;
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPInstruction)) {
- return false;
- }
- OFPInstruction other = (OFPInstruction) obj;
- if (length != other.length) {
- return false;
- }
- if (type == null) {
- if (other.type != null) {
- return false;
- }
- } else if (!type.equals(other.type)) {
- return false;
- }
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#clone()
- */
- @Override
- public OFPInstruction clone() throws CloneNotSupportedException {
- return (OFPInstruction) super.clone();
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.action.OFPAction;
-import org.openflow.codec.protocol.factory.OFPActionFactory;
-import org.openflow.codec.protocol.factory.OFPActionFactoryAware;
-import org.openflow.codec.util.U16;
-
-/**
- * base class for instruction structure WRITE/APPLY/CLEAR_ACTIONS correspond to
- * struct ofp_instruction_actions
- *
- * @author AnilGujele
- *
- */
-public abstract class OFPInstructionActions extends OFPInstruction implements OFPActionFactoryAware {
-
- private final static short MINIMUM_LENGTH = 8;
- private List<OFPAction> actions;
- private OFPActionFactory actionFactory;
-
- /**
- * constructor
- */
- public OFPInstructionActions() {
- actions = new ArrayList<OFPAction>();
- this.setLength(MINIMUM_LENGTH);
-
- }
-
- /**
- * read OFPInstruction from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- data.getInt(); // pad
- if (null == actionFactory) {
- throw new RuntimeException("OFPActionFactory is not set.");
- }
- int actionDataLength = U16.f(this.getLength()) - MINIMUM_LENGTH;
- // read actions
- actions = actionFactory.parseActions(data, actionDataLength);
-
- }
-
- /**
- * write OFPInstruction to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(0); // pad
- // write action
- for (OFPAction ofAction : actions) {
- ofAction.writeTo(data);
- }
- }
-
- /**
- * get actions in this instruction
- *
- * @return
- */
- public List<OFPAction> getActions() {
- return actions;
- }
-
- /**
- * set actions in this instructions.
- *
- * @param actions
- */
-
- public void setActions(List<OFPAction> actions) {
- this.actions = actions;
- updateLength();
- }
-
- /**
- * get the length of instruction actions
- *
- * @return
- */
- private void updateLength() {
- length = MINIMUM_LENGTH;
- for (OFPAction ofAction : actions) {
- length += ofAction.getLengthU();
- }
- }
-
- @Override
- public void setActionFactory(OFPActionFactory actionFactory) {
- this.actionFactory = actionFactory;
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 742;
- int result = super.hashCode();
- result = prime * result + actions.hashCode();
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPInstructionActions)) {
- return false;
- }
- OFPInstructionActions other = (OFPInstructionActions) obj;
- if (!this.actions.equals(other.actions)) {
- return false;
- }
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#clone()
- */
- @Override
- public OFPInstructionActions clone() throws CloneNotSupportedException {
- OFPInstructionActions clone = (OFPInstructionActions) super.clone();
- clone.actions = new ArrayList<OFPAction>();
- for (OFPAction action : this.actions) {
- clone.actions.add(action.clone());
- }
-
- return clone;
- }
-
- /**
- * Returns a string representation of the instruction
- */
- public String toString() {
- return "OFPInstruction[" + "type=" + this.getOFInstructionType() + ", length=" + this.getLength()
- + ", actions=" + actions.toString() + "]";
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-/**
- * apply_actions instruction class
- *
- * @author AnilGujele
- *
- */
-public class OFPInstructionApplyActions extends OFPInstructionActions {
-
- public OFPInstructionApplyActions() {
- super();
- super.setOFInstructionType(OFPInstructionType.APPLY_ACTIONS);
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * clear_actions instruction class Note:For the Clear-Actions instruction, the
- * structure does not contain any actions.
- *
- * @author AnilGujele
- *
- */
-public class OFPInstructionClearActions extends OFPInstruction {
- private static final long serialVersionUID = 1L;
-
- private final static short MINIMUM_LENGTH = 8;
-
- public OFPInstructionClearActions() {
- super();
- super.setLength(MINIMUM_LENGTH);
- super.setOFInstructionType(OFPInstructionType.CLEAR_ACTIONS);
- }
-
- /**
- * read OFPInstruction from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- data.getInt(); // pad
-
- }
-
- /**
- * write OFPInstruction to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(0); // pad
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Instruction structure correspond to struct ofp_instruction_experimenter
- *
- * @author AnilGujele
- *
- */
-public class OFPInstructionExperimenter extends OFPInstruction {
- private static final short MINIMUM_LENGTH = 8;
-
- private int experimenterId;
-
- /**
- * constructor
- */
- public OFPInstructionExperimenter() {
- super.setOFInstructionType(OFPInstructionType.EXPERIMENTER);
- super.setLength(MINIMUM_LENGTH);
- }
-
- /**
- * get experimenter id
- *
- * @return
- */
- public int getExperimenterId() {
- return experimenterId;
- }
-
- /**
- * set experimenter id
- *
- * @param experimenterId
- */
- public void setExperimenterId(int experimenterId) {
- this.experimenterId = experimenterId;
- }
-
- /**
- * read OFPInstruction from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.experimenterId = data.getInt();
-
- }
-
- /**
- * write OFPInstruction to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(this.experimenterId);
- }
-
- @Override
- public int hashCode() {
- final int prime = 744;
- int result = super.hashCode();
- result = prime * result + this.experimenterId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPInstructionExperimenter)) {
- return false;
- }
- OFPInstructionExperimenter other = (OFPInstructionExperimenter) obj;
- if (this.experimenterId != other.experimenterId) {
- return false;
- }
- return true;
- }
-
- /**
- * Returns a string representation of the instruction
- */
- public String toString() {
- return "OFPInstruction[" + "type=" + this.getOFInstructionType() + ", length=" + this.getLength()
- + ", experimenterId=" + experimenterId + "]";
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Instruction structure for GOTO_Table correspond to struct
- * ofp_instruction_goto_table
- *
- * @author AnilGujele
- *
- */
-public class OFPInstructionGoToTable extends OFPInstruction {
- private static final short MINIMUM_LENGTH = 8;
-
- private byte tableId;
-
- /**
- * constructor
- */
- public OFPInstructionGoToTable() {
- super.setOFInstructionType(OFPInstructionType.GOTO_TABLE);
- super.setLength(MINIMUM_LENGTH);
- }
-
- /**
- * get table id
- *
- * @return
- */
- public byte getTableId() {
- return tableId;
- }
-
- /**
- * set table id
- *
- * @param tableId
- */
- public void setTableId(byte tableId) {
- this.tableId = tableId;
- }
-
- /**
- * read OFPInstruction from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.tableId = data.get();
- data.get(); // pad
- data.getShort(); // pad
-
- }
-
- /**
- * write OFPInstruction to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.put(this.tableId);
- data.put((byte) 0);
- data.putShort((short) 0);
- }
-
- @Override
- public int hashCode() {
- final int prime = 743;
- int result = super.hashCode();
- result = prime * result + this.tableId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPInstructionGoToTable)) {
- return false;
- }
- OFPInstructionGoToTable other = (OFPInstructionGoToTable) obj;
- if (this.tableId != other.tableId) {
- return false;
- }
- return true;
- }
-
- /**
- * Returns a string representation of the instruction
- */
- public String toString() {
- return "OFPInstruction[" + "type=" + this.getOFInstructionType() + ", length=" + this.getLength()
- + ", tableId=" + tableId + "]";
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents meter instruction struct ofp_instruction_meter
- *
- * @author AnilGujele
- *
- */
-public class OFPInstructionMeter extends OFPInstruction {
- private static final short MINIMUM_LENGTH = 8;
-
- private int meterId;
-
- /**
- * constructor
- */
- public OFPInstructionMeter() {
- super.setOFInstructionType(OFPInstructionType.METER);
- super.setLength(MINIMUM_LENGTH);
- }
-
- /**
- * get meter id
- *
- * @return
- */
- public int getMeterId() {
- return meterId;
- }
-
- /**
- * set meter id
- *
- * @param meterId
- */
- public void setMeterId(int meterId) {
- this.meterId = meterId;
- }
-
- /**
- * read OFPInstruction from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.meterId = data.getInt();
-
- }
-
- /**
- * write OFPInstruction to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(this.meterId);
- }
-
- @Override
- public int hashCode() {
- final int prime = 745;
- int result = super.hashCode();
- result = prime * result + this.meterId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPInstructionMeter)) {
- return false;
- }
- OFPInstructionMeter other = (OFPInstructionMeter) obj;
- if (this.meterId != other.meterId) {
- return false;
- }
- return true;
- }
-
- /**
- * Returns a string representation of the instruction
- */
- public String toString() {
- return "OFPInstruction[" + "type=" + this.getOFInstructionType() + ", length=" + this.getLength()
- + ", meterId=" + meterId + "]";
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.openflow.codec.protocol.Instantiable;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents struct ofp_instruction_type
- *
- * @author AnilGujele
- *
- */
-public enum OFPInstructionType {
- /* Setup the next table in the lookup pipeline */
- GOTO_TABLE(1, new Instantiable<OFPInstruction>() {
- @Override
- public OFPInstruction instantiate() {
- return new OFPInstructionGoToTable();
- }
- }),
- /* Setup the metadata field for use later in pipeline */
- WRITE_METADATA(2, new Instantiable<OFPInstruction>() {
- @Override
- public OFPInstruction instantiate() {
- return new OFPInstructionWriteMetaData();
- }
- }),
- /* Write the action(s) onto the datapath action set */
- WRITE_ACTIONS(3, new Instantiable<OFPInstruction>() {
- @Override
- public OFPInstruction instantiate() {
- return new OFPInstructionWriteActions();
- }
- }),
- /* Applies the action(s) immediately */
- APPLY_ACTIONS(4, new Instantiable<OFPInstruction>() {
- @Override
- public OFPInstruction instantiate() {
- return new OFPInstructionApplyActions();
- }
- }),
- /* Clears all actions from the datapath action set */
- CLEAR_ACTIONS(5, new Instantiable<OFPInstruction>() {
- @Override
- public OFPInstruction instantiate() {
- return new OFPInstructionClearActions();
- }
- }),
- /* Apply meter (rate limiter) */
- METER(6, new Instantiable<OFPInstruction>() {
- @Override
- public OFPInstruction instantiate() {
- return new OFPInstructionMeter();
- }
- }),
- /* Experimenter instruction */
- EXPERIMENTER(0xFFFF, new Instantiable<OFPInstruction>() {
- @Override
- public OFPInstruction instantiate() {
- return new OFPInstructionExperimenter();
- }
- });
-
- private static Map<Integer, OFPInstructionType> mapping;
-
- private short type;
-
- private Instantiable<OFPInstruction> instantiable;
-
- /**
- *
- * @param type
- */
- OFPInstructionType(int type, Instantiable<OFPInstruction> instantiable) {
- this.setTypeValue((short) type);
- OFPInstructionType.addMapping(type, this);
- this.instantiable = instantiable;
- }
-
- /**
- * add mapping to store
- *
- * @param type
- * @param instructionType
- */
- private static void addMapping(int type, OFPInstructionType instructionType) {
- if (null == mapping) {
- mapping = new HashMap<Integer, OFPInstructionType>();
- }
- mapping.put(type, instructionType);
- }
-
- /**
- * get OFPInstructionType correspond to value type
- *
- * @param type
- * @return OFPInstructionType
- */
- public static OFPInstructionType valueOf(short type) {
- return mapping.get(U16.f(type));
- }
-
- /**
- * get instruction type value
- *
- * @return
- */
- public short getTypeValue() {
- return type;
- }
-
- /**
- * set instruction type value
- *
- * @param type
- */
- public void setTypeValue(short type) {
- this.type = type;
- }
-
- /**
- * Returns a new instance of the OFPAction represented by this OFPActionType
- *
- * @return the new object
- */
- public OFPInstruction newInstance() {
- return instantiable.instantiate();
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-/**
- * Represents write_actions instruction class
- *
- * @author AnilGujele
- *
- */
-public class OFPInstructionWriteActions extends OFPInstructionActions {
-
- public OFPInstructionWriteActions() {
- super();
- super.setOFInstructionType(OFPInstructionType.WRITE_ACTIONS);
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents WRITE_METADATA action and its corresponding struct
- * ofp_instruction_write_metadata
- *
- * @author AnilGujele
- *
- */
-public class OFPInstructionWriteMetaData extends OFPInstruction {
- public static final short MINIMUM_LENGTH = 24;
-
- private long metadata;
- private long metadataMask;
-
- /**
- * constructor
- */
- public OFPInstructionWriteMetaData() {
- super.setOFInstructionType(OFPInstructionType.WRITE_METADATA);
- super.setLength(MINIMUM_LENGTH);
- }
-
- /**
- * read OFPInstruction from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- data.getInt(); // pad
- this.metadata = data.getLong();
- this.metadataMask = data.getLong();
- }
-
- /**
- * write OFPInstruction to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(0);
- data.putLong(this.metadata);
- data.putLong(this.metadataMask);
- }
-
- /**
- * get metadata
- *
- * @return
- */
- public long getMetadata() {
- return metadata;
- }
-
- /**
- * set metadata
- *
- * @param metadata
- */
- public void setMetadata(long metadata) {
- this.metadata = metadata;
- }
-
- /**
- * get metadata mask
- *
- * @return
- */
- public long getMetadataMask() {
- return metadataMask;
- }
-
- /**
- * set metadata mask
- *
- * @param metadataMask
- */
- public void setMetadataMask(long metadataMask) {
- this.metadataMask = metadataMask;
- }
-
- @Override
- public int hashCode() {
- final int prime = 746;
- long result = super.hashCode();
- result = prime * result + this.metadata;
- result = prime * result + this.metadataMask;
- return (int) result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPInstructionWriteMetaData)) {
- return false;
- }
- OFPInstructionWriteMetaData other = (OFPInstructionWriteMetaData) obj;
- if (this.metadata != other.metadata) {
- return false;
- }
- if (this.metadataMask != other.metadataMask) {
- return false;
- }
- return true;
- }
-
- /**
- * Returns a string representation of the instruction
- */
- public String toString() {
- return "OFPInstruction[" + "type=" + this.getOFInstructionType() + ", length=" + this.getLength()
- + ", metadata=" + metadata + ", metadataMask=" + metadataMask + "]";
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.queue;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.factory.OFPQueuePropertyFactory;
-import org.openflow.codec.protocol.factory.OFPQueuePropertyFactoryAware;
-import org.openflow.codec.util.U16;
-
-/**
- * Corresponds to the struct ofp_packet_queue OpenFlow structure
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPPacketQueue implements Cloneable, OFPQueuePropertyFactoryAware {
- public static int MINIMUM_LENGTH = 16;
-
- protected OFPQueuePropertyFactory queuePropertyFactory;
-
- protected int queueId;
- private int port;
- protected short length;
- protected List<OFPQueueProperty> properties;
-
- /**
- * @return the queueId
- */
- public int getQueueId() {
- return queueId;
- }
-
- /**
- * @param queueId
- * the queueId to set
- */
- public OFPPacketQueue setQueueId(int queueId) {
- this.queueId = queueId;
- return this;
- }
-
- /**
- * @return the length
- */
- public short getLength() {
- return length;
- }
-
- /**
- * @param length
- * the length to set
- */
- public void setLength(short length) {
- this.length = length;
- }
-
- /**
- * @return the properties
- */
- public List<OFPQueueProperty> getProperties() {
- return properties;
- }
-
- /**
- * @param properties
- * the properties to set
- */
- public OFPPacketQueue setProperties(List<OFPQueueProperty> properties) {
- this.properties = properties;
- return this;
- }
-
- public void readFrom(IDataBuffer data) {
- this.queueId = data.getInt();
- this.port = data.getInt();
- this.length = data.getShort();
- data.getInt(); // pad
- data.getShort(); // pad
-
- if (this.queuePropertyFactory == null)
- throw new RuntimeException("OFPQueuePropertyFactory not set");
- this.properties = queuePropertyFactory.parseQueueProperties(data, U16.f(this.length) - MINIMUM_LENGTH);
- }
-
- public void writeTo(IDataBuffer data) {
- data.putInt(this.queueId);
- data.putInt(this.port);
- data.putShort(this.length);
- data.putInt(0); // pad
- data.putShort((short) 0); // pad
- if (this.properties != null) {
- for (OFPQueueProperty queueProperty : this.properties) {
- queueProperty.writeTo(data);
- }
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 6367;
- int result = 1;
- result = prime * result + length;
- result = prime * result + ((properties == null) ? 0 : properties.hashCode());
- result = prime * result + queueId;
- result = prime * result + port;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof OFPPacketQueue))
- return false;
- OFPPacketQueue other = (OFPPacketQueue) obj;
- if (length != other.length)
- return false;
- if (properties == null) {
- if (other.properties != null)
- return false;
- } else if (!properties.equals(other.properties))
- return false;
- if (queueId != other.queueId)
- return false;
- if (port != other.port)
- return false;
-
- return true;
- }
-
- @Override
- public OFPPacketQueue clone() {
- try {
- OFPPacketQueue clone = (OFPPacketQueue) super.clone();
- if (this.properties != null) {
- List<OFPQueueProperty> queueProps = new ArrayList<OFPQueueProperty>();
- for (OFPQueueProperty prop : this.properties) {
- queueProps.add(prop.clone());
- }
- clone.setProperties(queueProps);
- }
- return clone;
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public void setQueuePropertyFactory(OFPQueuePropertyFactory queuePropertyFactory) {
- this.queuePropertyFactory = queuePropertyFactory;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "OFPPacketQueue [queueId=" + queueId + ", port=" + port + ", properties=" + properties + "]";
- }
-
- public int getPort() {
- return port;
- }
-
- public void setPort(int port) {
- this.port = port;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.queue;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * Corresponds to the struct ofp_queue_prop_header OpenFlow structure
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPQueueProperty implements Cloneable {
- public static int MINIMUM_LENGTH = 8;
-
- protected OFPQueuePropertyType type;
- protected short length;
-
- /**
- * @return the type
- */
- public OFPQueuePropertyType getType() {
- return type;
- }
-
- /**
- * @param type
- * the type to set
- */
- public void setType(OFPQueuePropertyType type) {
- this.type = type;
- }
-
- /**
- * @return the length
- */
- public short getLength() {
- return length;
- }
-
- /**
- * Returns the unsigned length
- *
- * @return the length
- */
- public int getLengthU() {
- return U16.f(length);
- }
-
- /**
- * @param length
- * the length to set
- */
- public void setLength(short length) {
- this.length = length;
- }
-
- public void readFrom(IDataBuffer data) {
- this.type = OFPQueuePropertyType.valueOf(data.getShort());
- this.length = data.getShort();
- data.getInt(); // pad
- }
-
- public void writeTo(IDataBuffer data) {
- data.putShort(this.type.getTypeValue());
- data.putShort(this.length);
- data.putInt(0); // pad
- }
-
- @Override
- public int hashCode() {
- final int prime = 2777;
- int result = 1;
- result = prime * result + length;
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof OFPQueueProperty))
- return false;
- OFPQueueProperty other = (OFPQueueProperty) obj;
- if (length != other.length)
- return false;
- if (type != other.type)
- return false;
- return true;
- }
-
- @Override
- protected OFPQueueProperty clone() {
- try {
- return (OFPQueueProperty) super.clone();
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException(e);
- }
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.queue;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * Corresponds to the struct ofp_queue_prop_experimenter OpenFlow structure
- *
- * @author AnilGujele
- */
-public class OFPQueuePropertyExperimenter extends OFPQueueProperty {
- public static int MINIMUM_LENGTH = 16;
-
- private int experimenterId;
- private byte[] dataArr;
-
- /**
- * constructor
- */
- public OFPQueuePropertyExperimenter() {
- super();
- this.type = OFPQueuePropertyType.EXPERIMENTER;
- this.length = U16.t(MINIMUM_LENGTH);
- this.dataArr = new byte[0];
- }
-
- /**
- * @return the rate
- */
- public int experimenterId() {
- return experimenterId;
- }
-
- /**
- * @param rate
- * the rate to set
- */
- public OFPQueuePropertyExperimenter setExperimenterId(int experimenterId) {
- this.experimenterId = experimenterId;
- return this;
- }
-
- /**
- * get the data
- *
- * @return
- */
- public byte[] getData() {
- return dataArr;
- }
-
- /**
- * set the data
- *
- * @param data
- */
- public void setData(byte[] data) {
- this.dataArr = data;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.experimenterId = data.getInt();
- data.getInt(); // pad
- int dataLength = length - MINIMUM_LENGTH;
- dataArr = new byte[dataLength];
- data.get(dataArr);
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- this.setLength((short) (length + dataArr.length));
- super.writeTo(data);
- data.putInt(this.experimenterId);
- data.putInt(0); // pad
- data.put(dataArr);
- }
-
- @Override
- public int hashCode() {
- final int prime = 3259;
- int result = super.hashCode();
- result = prime * result + experimenterId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (!(obj instanceof OFPQueuePropertyExperimenter))
- return false;
- OFPQueuePropertyExperimenter other = (OFPQueuePropertyExperimenter) obj;
- if (experimenterId != other.experimenterId)
- return false;
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "OFPQueuePropertyExperimenter [type=" + type + ", experimenterId=" + experimenterId + "]";
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.queue;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * Corresponds to the struct ofp_queue_prop_max_rate OpenFlow structure
- *
- * @author AnilGujele
- */
-public class OFPQueuePropertyMaxRate extends OFPQueueProperty {
- public static int MINIMUM_LENGTH = 16;
-
- protected short rate;
-
- /**
- * constructor
- */
- public OFPQueuePropertyMaxRate() {
- super();
- this.type = OFPQueuePropertyType.MAX_RATE;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * @return the rate
- */
- public short getRate() {
- return rate;
- }
-
- /**
- * @param rate
- * the rate to set
- */
- public OFPQueuePropertyMaxRate setRate(short rate) {
- this.rate = rate;
- return this;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.rate = data.getShort();
- data.getInt(); // pad
- data.getShort(); // pad
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putShort(this.rate);
- data.putInt(0); // pad
- data.putShort((short) 0); // pad
- }
-
- @Override
- public int hashCode() {
- final int prime = 3259;
- int result = super.hashCode();
- result = prime * result + rate;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (!(obj instanceof OFPQueuePropertyMaxRate))
- return false;
- OFPQueuePropertyMaxRate other = (OFPQueuePropertyMaxRate) obj;
- if (rate != other.rate)
- return false;
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "OFPQueuePropertyMaxRate [type=" + type + ", rate=" + U16.f(rate) + "]";
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.queue;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * Corresponds to the struct ofp_queue_prop_min_rate OpenFlow structure
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPQueuePropertyMinRate extends OFPQueueProperty {
- public static int MINIMUM_LENGTH = 16;
-
- protected short rate;
-
- /**
- *
- */
- public OFPQueuePropertyMinRate() {
- super();
- this.type = OFPQueuePropertyType.MIN_RATE;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * @return the rate
- */
- public short getRate() {
- return rate;
- }
-
- /**
- * @param rate
- * the rate to set
- */
- public OFPQueuePropertyMinRate setRate(short rate) {
- this.rate = rate;
- return this;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.rate = data.getShort();
- data.getInt(); // pad
- data.getShort(); // pad
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putShort(this.rate);
- data.putInt(0); // pad
- data.putShort((short) 0); // pad
- }
-
- @Override
- public int hashCode() {
- final int prime = 3259;
- int result = super.hashCode();
- result = prime * result + rate;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (!(obj instanceof OFPQueuePropertyMinRate))
- return false;
- OFPQueuePropertyMinRate other = (OFPQueuePropertyMinRate) obj;
- if (rate != other.rate)
- return false;
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "OFPQueuePropertyMinRate [type=" + type + ", rate=" + U16.f(rate) + "]";
- }
-
-}
+++ /dev/null
-/**
- *
- */
-package org.openflow.codec.protocol.queue;
-
-import java.lang.reflect.Constructor;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.openflow.codec.protocol.Instantiable;
-import org.openflow.codec.util.U16;
-
-/**
- * List of OpenFlow Queue Property types and mappings to wire protocol value and
- * derived classes
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPQueuePropertyType {
-
- public static OFPQueuePropertyType MIN_RATE = new OFPQueuePropertyType(1, "MIN_RATE",
- OFPQueuePropertyMinRate.class, new Instantiable<OFPQueueProperty>() {
- @Override
- public OFPQueueProperty instantiate() {
- return new OFPQueuePropertyMinRate();
- }
- });
- public static OFPQueuePropertyType MAX_RATE = new OFPQueuePropertyType(2, "MAX_RATE",
- OFPQueuePropertyMaxRate.class, new Instantiable<OFPQueueProperty>() {
- @Override
- public OFPQueueProperty instantiate() {
- return new OFPQueuePropertyMaxRate();
- }
- });
- public static OFPQueuePropertyType EXPERIMENTER = new OFPQueuePropertyType(0xffff, "EXPERIMENTER",
- OFPQueuePropertyExperimenter.class, new Instantiable<OFPQueueProperty>() {
- @Override
- public OFPQueueProperty instantiate() {
- return new OFPQueuePropertyExperimenter();
- }
- });
-
- protected static Map<Integer, OFPQueuePropertyType> mapping;
-
- protected Class<? extends OFPQueueProperty> clazz;
- protected Constructor<? extends OFPQueueProperty> constructor;
- protected Instantiable<OFPQueueProperty> instantiable;
- protected int minLen;
- protected String name;
- protected short type;
-
- /**
- * Store some information about the OpenFlow Queue Property type, including
- * wire protocol type number, length, and derived class
- *
- * @param type
- * Wire protocol number associated with this OFPQueuePropertyType
- * @param name
- * The name of this type
- * @param clazz
- * The Java class corresponding to this type of OpenFlow Queue
- * Property
- * @param instantiable
- * the instantiable for the OFPQueueProperty this type represents
- */
- OFPQueuePropertyType(int type, String name, Class<? extends OFPQueueProperty> clazz,
- Instantiable<OFPQueueProperty> instantiable) {
- this.type = (short) type;
- this.name = name;
- this.clazz = clazz;
- this.instantiable = instantiable;
- try {
- this.constructor = clazz.getConstructor(new Class[] {});
- } catch (Exception e) {
- throw new RuntimeException("Failure getting constructor for class: " + clazz, e);
- }
- OFPQueuePropertyType.addMapping(type, this);
- }
-
- /**
- * Adds a mapping from type value to OFPQueuePropertyType enum
- *
- * @param i
- * OpenFlow wire protocol Action type value
- * @param t
- * type
- */
- static public void addMapping(int i, OFPQueuePropertyType t) {
- if (mapping == null)
- mapping = new HashMap<Integer, OFPQueuePropertyType>();
- OFPQueuePropertyType.mapping.put(i, t);
- }
-
- /**
- * Given a wire protocol OpenFlow type number, return the OFPType associated
- * with it
- *
- * @param i
- * wire protocol number
- * @return OFPType enum type
- */
-
- static public OFPQueuePropertyType valueOf(short i) {
- return OFPQueuePropertyType.mapping.get(U16.f(i));
- }
-
- /**
- * @return Returns the wire protocol value corresponding to this
- * OFPQueuePropertyType
- */
- public short getTypeValue() {
- return this.type;
- }
-
- /**
- * @return return the OFPQueueProperty subclass corresponding to this
- * OFPQueuePropertyType
- */
- public Class<? extends OFPQueueProperty> toClass() {
- return clazz;
- }
-
- /**
- * Returns the no-argument Constructor of the implementation class for this
- * OFPQueuePropertyType
- *
- * @return the constructor
- */
- public Constructor<? extends OFPQueueProperty> getConstructor() {
- return constructor;
- }
-
- /**
- * Returns a new instance of the OFPQueueProperty represented by this
- * OFPQueuePropertyType
- *
- * @return the new object
- */
- public OFPQueueProperty newInstance() {
- return instantiable.instantiate();
- }
-
- /**
- * @return the instantiable
- */
- public Instantiable<OFPQueueProperty> getInstantiable() {
- return instantiable;
- }
-
- /**
- * @param instantiable
- * the instantiable to set
- */
- public void setInstantiable(Instantiable<OFPQueueProperty> instantiable) {
- this.instantiable = instantiable;
- }
-
- public String getName() {
- return this.name;
- }
-
- @Override
- public String toString() {
- return this.name;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an ofp_aggregate_stats_reply structure
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPAggregateStatisticsReply implements OFPStatistics {
- protected long packetCount;
- protected long byteCount;
- protected int flowCount;
-
- /**
- * @return the packetCount
- */
- public long getPacketCount() {
- return packetCount;
- }
-
- /**
- * @param packetCount
- * the packetCount to set
- */
- public void setPacketCount(long packetCount) {
- this.packetCount = packetCount;
- }
-
- /**
- * @return the byteCount
- */
- public long getByteCount() {
- return byteCount;
- }
-
- /**
- * @param byteCount
- * the byteCount to set
- */
- public void setByteCount(long byteCount) {
- this.byteCount = byteCount;
- }
-
- /**
- * @return the flowCount
- */
- public int getFlowCount() {
- return flowCount;
- }
-
- /**
- * @param flowCount
- * the flowCount to set
- */
- public void setFlowCount(int flowCount) {
- this.flowCount = flowCount;
- }
-
- @Override
- public int getLength() {
- return 24;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- this.packetCount = data.getLong();
- this.byteCount = data.getLong();
- this.flowCount = data.getInt();
- data.getInt(); // pad
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- data.putLong(this.packetCount);
- data.putLong(this.byteCount);
- data.putInt(this.flowCount);
- data.putInt(0); // pad
- }
-
- @Override
- public int hashCode() {
- final int prime = 397;
- int result = 1;
- result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
- result = prime * result + flowCount;
- result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPAggregateStatisticsReply)) {
- return false;
- }
- OFPAggregateStatisticsReply other = (OFPAggregateStatisticsReply) obj;
- if (byteCount != other.byteCount) {
- return false;
- }
- if (flowCount != other.flowCount) {
- return false;
- }
- if (packetCount != other.packetCount) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPMatch;
-
-/**
- * Represents an ofp_aggregate_stats_request structure
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author AnilGujele
- */
-public class OFPAggregateStatisticsRequest implements OFPStatistics {
- private final static int MINIMUM_LENGTH = 40;
-
- protected byte tableId;
- protected int outPort;
- private int outGroup;
- private long cookie;
- private long cookieMask;
- protected OFPMatch match;
-
- /**
- * @return the match
- */
- public OFPMatch getMatch() {
- return match;
- }
-
- /**
- * @param match
- * the match to set
- */
- public void setMatch(OFPMatch match) {
- this.match = match;
- }
-
- /**
- * @return the tableId
- */
- public byte getTableId() {
- return tableId;
- }
-
- /**
- * @param tableId
- * the tableId to set
- */
- public void setTableId(byte tableId) {
- this.tableId = tableId;
- }
-
- /**
- * @return the outPort
- */
- public int getOutPort() {
- return outPort;
- }
-
- /**
- * @param outPort
- * the outPort to set
- */
- public void setOutPort(int outPort) {
- this.outPort = outPort;
- }
-
- /**
- * get the output group
- *
- * @return
- */
- public int getOutGroup() {
- return outGroup;
- }
-
- /**
- * set output group
- *
- * @param outGroup
- */
- public void setOutGroup(int outGroup) {
- this.outGroup = outGroup;
- }
-
- /**
- * get the cookie
- *
- * @return
- */
- public long getCookie() {
- return cookie;
- }
-
- /**
- * set cookie
- *
- * @param cookie
- */
- public void setCookie(long cookie) {
- this.cookie = cookie;
- }
-
- /**
- * get the cookie mask
- *
- * @return
- */
- public long getCookieMask() {
- return cookieMask;
- }
-
- /**
- * set mask for cookie
- *
- * @param cookieMask
- */
- public void setCookieMask(long cookieMask) {
- this.cookieMask = cookieMask;
- }
-
- @Override
- public int getLength() {
- return MINIMUM_LENGTH;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- this.tableId = data.get();
- data.get(); // pad
- data.getShort(); // pad
- this.outPort = data.getInt();
- this.outGroup = data.getInt();
- data.getInt(); // pad
- this.cookie = data.getLong();
- this.cookieMask = data.getLong();
- if (this.match == null)
- this.match = new OFPMatch();
- this.match.readFrom(data);
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- data.put(this.tableId);
- data.put((byte) 0); // pad
- data.putShort((short) 0); // pad
- data.putInt(this.outPort);
- data.putInt(this.outGroup);
- data.putInt(0); // pad
- data.putLong(cookie);
- data.putLong(cookieMask);
- this.match.writeTo(data);
- }
-
- @Override
- public int hashCode() {
- final int prime = 401;
- int result = 1;
- result = prime * result + ((match == null) ? 0 : match.hashCode());
- result = prime * result + (int) (cookie ^ (cookie >>> 32));
- result = prime * result + (int) (cookieMask ^ (cookieMask >>> 32));
- result = prime * result + outPort;
- result = prime * result + outGroup;
- result = prime * result + tableId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPAggregateStatisticsRequest)) {
- return false;
- }
- OFPAggregateStatisticsRequest other = (OFPAggregateStatisticsRequest) obj;
- if (tableId != other.tableId) {
- return false;
- }
- if (outPort != other.outPort) {
- return false;
- }
- if (getOutGroup() != other.getOutGroup()) {
- return false;
- }
- if (getCookie() != other.getCookie()) {
- return false;
- }
- if (getCookieMask() != other.getCookieMask()) {
- return false;
- }
- if (match == null) {
- if (other.match != null) {
- return false;
- }
- } else if (!match.equals(other.match)) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import java.io.Serializable;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.StringByteSerializer;
-
-/**
- * Represents an ofp_desc structure
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPDescriptionStatistics implements OFPStatistics, Serializable {
- public static int DESCRIPTION_STRING_LENGTH = 256;
- public static int SERIAL_NUMBER_LENGTH = 32;
-
- protected String manufacturerDescription;
- protected String hardwareDescription;
- protected String softwareDescription;
- protected String serialNumber;
- protected String datapathDescription;
-
- /**
- * @return the manufacturerDescription
- */
- public String getManufacturerDescription() {
- return manufacturerDescription;
- }
-
- /**
- * @param manufacturerDescription
- * the manufacturerDescription to set
- */
- public void setManufacturerDescription(String manufacturerDescription) {
- this.manufacturerDescription = manufacturerDescription;
- }
-
- /**
- * @return the hardwareDescription
- */
- public String getHardwareDescription() {
- return hardwareDescription;
- }
-
- /**
- * @param hardwareDescription
- * the hardwareDescription to set
- */
- public void setHardwareDescription(String hardwareDescription) {
- this.hardwareDescription = hardwareDescription;
- }
-
- /**
- * @return the softwareDescription
- */
- public String getSoftwareDescription() {
- return softwareDescription;
- }
-
- /**
- * @param softwareDescription
- * the softwareDescription to set
- */
- public void setSoftwareDescription(String softwareDescription) {
- this.softwareDescription = softwareDescription;
- }
-
- /**
- * @return the serialNumber
- */
- public String getSerialNumber() {
- if (serialNumber.equals("None"))
- return "";
- return serialNumber;
- }
-
- /**
- * @param serialNumber
- * the serialNumber to set
- */
- public void setSerialNumber(String serialNumber) {
- this.serialNumber = serialNumber;
- }
-
- /**
- * @return the datapathDescription
- */
- public String getDatapathDescription() {
- return datapathDescription;
- }
-
- /**
- * @param datapathDescription
- * the datapathDescription to set
- */
- public void setDatapathDescription(String datapathDescription) {
- this.datapathDescription = datapathDescription;
- }
-
- @Override
- public int getLength() {
- return 1056;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- this.manufacturerDescription = StringByteSerializer.readFrom(data, DESCRIPTION_STRING_LENGTH);
- this.hardwareDescription = StringByteSerializer.readFrom(data, DESCRIPTION_STRING_LENGTH);
- this.softwareDescription = StringByteSerializer.readFrom(data, DESCRIPTION_STRING_LENGTH);
- this.serialNumber = StringByteSerializer.readFrom(data, SERIAL_NUMBER_LENGTH);
- this.datapathDescription = StringByteSerializer.readFrom(data, DESCRIPTION_STRING_LENGTH);
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH, this.manufacturerDescription);
- StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH, this.hardwareDescription);
- StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH, this.softwareDescription);
- StringByteSerializer.writeTo(data, SERIAL_NUMBER_LENGTH, this.serialNumber);
- StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH, this.datapathDescription);
- }
-
- @Override
- public int hashCode() {
- final int prime = 409;
- int result = 1;
- result = prime * result + ((datapathDescription == null) ? 0 : datapathDescription.hashCode());
- result = prime * result + ((hardwareDescription == null) ? 0 : hardwareDescription.hashCode());
- result = prime * result + ((manufacturerDescription == null) ? 0 : manufacturerDescription.hashCode());
- result = prime * result + ((serialNumber == null) ? 0 : serialNumber.hashCode());
- result = prime * result + ((softwareDescription == null) ? 0 : softwareDescription.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPDescriptionStatistics)) {
- return false;
- }
- OFPDescriptionStatistics other = (OFPDescriptionStatistics) obj;
- if (datapathDescription == null) {
- if (other.datapathDescription != null) {
- return false;
- }
- } else if (!datapathDescription.equals(other.datapathDescription)) {
- return false;
- }
- if (hardwareDescription == null) {
- if (other.hardwareDescription != null) {
- return false;
- }
- } else if (!hardwareDescription.equals(other.hardwareDescription)) {
- return false;
- }
- if (manufacturerDescription == null) {
- if (other.manufacturerDescription != null) {
- return false;
- }
- } else if (!manufacturerDescription.equals(other.manufacturerDescription)) {
- return false;
- }
- if (serialNumber == null) {
- if (other.serialNumber != null) {
- return false;
- }
- } else if (!serialNumber.equals(other.serialNumber)) {
- return false;
- }
- if (softwareDescription == null) {
- if (other.softwareDescription != null) {
- return false;
- }
- } else if (!softwareDescription.equals(other.softwareDescription)) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import java.util.Arrays;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents ofp_experimenter_multipart_header
- *
- * @author AnilGujele
- */
-public class OFPExperimenterMultipartHeader implements OFPExtStatistics {
- public static int MINIMUM_LENGTH = 8;
-
- private int experimenter;
- private int expType;
- private byte[] data;
-
- // non-message field
- private int length;
-
- /**
- * constructor
- */
- public OFPExperimenterMultipartHeader() {
- this.length = MINIMUM_LENGTH;
- }
-
- /**
- * get experimenter id
- *
- * @return
- */
- public int getExperimenter() {
- return experimenter;
- }
-
- /**
- * set experimenter id
- *
- * @param experimenter
- */
- public void setExperimenter(int experimenter) {
- this.experimenter = experimenter;
- }
-
- /**
- * get experimenter type
- *
- * @return
- */
- public int getExpType() {
- return expType;
- }
-
- /**
- * set experimenter type
- *
- * @param expType
- */
- public void setExpType(int expType) {
- this.expType = expType;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- this.experimenter = data.getInt();
- this.expType = data.getInt();
- if (this.length > MINIMUM_LENGTH) {
- this.data = new byte[this.length - MINIMUM_LENGTH];
- data.get(this.data);
- updateLength();
- }
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- data.putInt(this.experimenter);
- data.putInt(this.expType);
- if (this.data != null)
- data.put(this.data);
- }
-
- /**
- * @return the data
- */
- public byte[] getData() {
- return data;
- }
-
- /**
- * @param data
- * the data to set
- */
- public void setData(byte[] data) {
- this.data = data;
- updateLength();
- }
-
- /**
- * update length
- */
- private void updateLength() {
- int dataLength = (null == data) ? 0 : data.length;
- this.length = OFPExperimenterMultipartHeader.MINIMUM_LENGTH + dataLength;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 337;
- int result = 0;
- result = prime * result + Arrays.hashCode(data);
- result = prime * result + experimenter;
- result = prime * result + expType;
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (null == obj)
- return false;
- if (!(obj instanceof OFPExperimenterMultipartHeader))
- return false;
- OFPExperimenterMultipartHeader other = (OFPExperimenterMultipartHeader) obj;
- if (experimenter != other.experimenter)
- return false;
- if (expType != other.expType)
- return false;
- if (!Arrays.equals(data, other.data))
- return false;
- return true;
- }
-
- @Override
- public int getLength() {
- return length;
- }
-
- @Override
- public void setLength(int length) {
- this.length = length;
-
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-/**
- * OFPStatistics interface is extended to have operation to set the length.
- *
- * @see org.openflow.codec.protocol.statistics.OFPExperimenterMultipartHeader
- *
- * @author AnilGujele
- */
-public interface OFPExtStatistics extends OFPStatistics {
- /**
- * set the length of Multipart in bytes
- *
- * @param length
- * - the length
- */
- public void setLength(int length);
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import java.io.Serializable;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPMatch;
-import org.openflow.codec.protocol.factory.OFPInstructionFactory;
-import org.openflow.codec.protocol.factory.OFPInstructionFactoryAware;
-import org.openflow.codec.protocol.instruction.OFPInstruction;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_flow_stats structure
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author AnilGujele
- */
-public class OFPFlowStatisticsReply implements OFPStatistics, OFPInstructionFactoryAware, Serializable {
- public static final int MINIMUM_LENGTH = 56;
- private static final int MIN_LENGTH_WITHOUT_MATCH = MINIMUM_LENGTH - 8;
-
- protected transient OFPInstructionFactory instructionFactory;
- protected short length = (short) MINIMUM_LENGTH;
- protected byte tableId;
- protected int durationSeconds;
- protected int durationNanoseconds;
- protected short priority;
- protected short idleTimeout;
- protected short hardTimeout;
- protected short flags;
- protected long cookie;
- protected long packetCount;
- protected long byteCount;
- protected OFPMatch match;
- private List<OFPInstruction> instructions;
-
- /**
- * @return the tableId
- */
- public byte getTableId() {
- return tableId;
- }
-
- /**
- * @param tableId
- * the tableId to set
- */
- public void setTableId(byte tableId) {
- this.tableId = tableId;
- }
-
- /**
- * @return the match
- */
- public OFPMatch getMatch() {
- return match;
- }
-
- /**
- * @param match
- * the match to set
- */
- public void setMatch(OFPMatch match) {
- this.match = match;
- }
-
- /**
- *
- * @return
- */
- public List<OFPInstruction> getInstructions() {
- return instructions;
- }
-
- /**
- *
- * @param instructions
- */
- public void setInstructions(List<OFPInstruction> instructions) {
- this.instructions = instructions;
- }
-
- /**
- * @return the durationSeconds
- */
- public int getDurationSeconds() {
- return durationSeconds;
- }
-
- /**
- * @param durationSeconds
- * the durationSeconds to set
- */
- public void setDurationSeconds(int durationSeconds) {
- this.durationSeconds = durationSeconds;
- }
-
- /**
- * @return the durationNanoseconds
- */
- public int getDurationNanoseconds() {
- return durationNanoseconds;
- }
-
- /**
- * @param durationNanoseconds
- * the durationNanoseconds to set
- */
- public void setDurationNanoseconds(int durationNanoseconds) {
- this.durationNanoseconds = durationNanoseconds;
- }
-
- /**
- * @return the priority
- */
- public short getPriority() {
- return priority;
- }
-
- /**
- * @param priority
- * the priority to set
- */
- public void setPriority(short priority) {
- this.priority = priority;
- }
-
- /**
- * @return the idleTimeout
- */
- public short getIdleTimeout() {
- return idleTimeout;
- }
-
- /**
- * @param idleTimeout
- * the idleTimeout to set
- */
- public void setIdleTimeout(short idleTimeout) {
- this.idleTimeout = idleTimeout;
- }
-
- /**
- * @return the hardTimeout
- */
- public short getHardTimeout() {
- return hardTimeout;
- }
-
- /**
- * @param hardTimeout
- * the hardTimeout to set
- */
- public void setHardTimeout(short hardTimeout) {
- this.hardTimeout = hardTimeout;
- }
-
- /**
- *
- * @return
- */
- public short getFlags() {
- return flags;
- }
-
- /**
- *
- * @param flags
- */
- public void setFlags(short flags) {
- this.flags = flags;
- }
-
- /**
- * @return the cookie
- */
- public long getCookie() {
- return cookie;
- }
-
- /**
- * @param cookie
- * the cookie to set
- */
- public void setCookie(long cookie) {
- this.cookie = cookie;
- }
-
- /**
- * @return the packetCount
- */
- public long getPacketCount() {
- return packetCount;
- }
-
- /**
- * @param packetCount
- * the packetCount to set
- */
- public void setPacketCount(long packetCount) {
- this.packetCount = packetCount;
- }
-
- /**
- * @return the byteCount
- */
- public long getByteCount() {
- return byteCount;
- }
-
- /**
- * @param byteCount
- * the byteCount to set
- */
- public void setByteCount(long byteCount) {
- this.byteCount = byteCount;
- }
-
- /**
- * @param length
- * the length to set
- */
- public void setLength(short length) {
- this.length = length;
- }
-
- @Override
- public int getLength() {
- return U16.f(length);
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- this.length = data.getShort();
- this.tableId = data.get();
- data.get(); // pad
- this.durationSeconds = data.getInt();
- this.durationNanoseconds = data.getInt();
- this.priority = data.getShort();
- this.idleTimeout = data.getShort();
- this.hardTimeout = data.getShort();
- this.flags = data.getShort();
- data.getInt(); // pad
- this.cookie = data.getLong();
- this.packetCount = data.getLong();
- this.byteCount = data.getLong();
- if (this.match == null)
- this.match = new OFPMatch();
- this.match.readFrom(data);
- if (null == this.instructionFactory)
- throw new RuntimeException("OFPInstructionFactory is not set");
- int instrLength = getLength() - MIN_LENGTH_WITHOUT_MATCH - match.getLengthWithPadding();
- this.instructions = this.instructionFactory.parseInstructions(data, instrLength);
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- data.putShort(this.length);
- data.put(this.tableId);
- data.put((byte) 0); // pad
- data.putInt(this.durationSeconds);
- data.putInt(this.durationNanoseconds);
- data.putShort(this.priority);
- data.putShort(this.idleTimeout);
- data.putShort(this.hardTimeout);
- data.putShort(this.flags);
- data.putInt(0); // pad
- data.putLong(this.cookie);
- data.putLong(this.packetCount);
- data.putLong(this.byteCount);
- this.match.writeTo(data);
- if (instructions != null) {
- for (OFPInstruction instr : instructions) {
- instr.writeTo(data);
- }
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 419;
- int result = 1;
- result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
- result = prime * result + (int) (cookie ^ (cookie >>> 32));
- result = prime * result + durationNanoseconds;
- result = prime * result + durationSeconds;
- result = prime * result + flags;
- result = prime * result + hardTimeout;
- result = prime * result + idleTimeout;
- result = prime * result + length;
- result = prime * result + ((match == null) ? 0 : match.hashCode());
- result = prime * result + ((instructions == null) ? 0 : instructions.hashCode());
- result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
- result = prime * result + priority;
- result = prime * result + tableId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPFlowStatisticsReply)) {
- return false;
- }
- OFPFlowStatisticsReply other = (OFPFlowStatisticsReply) obj;
- if (byteCount != other.byteCount) {
- return false;
- }
- if (cookie != other.cookie) {
- return false;
- }
- if (durationNanoseconds != other.durationNanoseconds) {
- return false;
- }
- if (durationSeconds != other.durationSeconds) {
- return false;
- }
- if (flags != other.flags) {
- return false;
- }
- if (hardTimeout != other.hardTimeout) {
- return false;
- }
- if (idleTimeout != other.idleTimeout) {
- return false;
- }
- if (length != other.length) {
- return false;
- }
- if (match == null) {
- if (other.match != null) {
- return false;
- }
- } else if (!match.equals(other.match)) {
- return false;
- }
- if (instructions == null) {
- if (other.instructions != null) {
- return false;
- }
- } else if (!instructions.equals(other.instructions)) {
- return false;
- }
- if (packetCount != other.packetCount) {
- return false;
- }
- if (priority != other.priority) {
- return false;
- }
- if (tableId != other.tableId) {
- return false;
- }
- return true;
- }
-
- @Override
- public void setInstructionFactory(OFPInstructionFactory instructionFactory) {
- this.instructionFactory = instructionFactory;
-
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import java.io.Serializable;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPMatch;
-
-/**
- * Represents an ofp_flow_stats_request structure
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author AnilGujele
- */
-public class OFPFlowStatisticsRequest implements OFPStatistics, Serializable {
- private static final int MINIMUM_LENGTH = 40;
-
- protected byte tableId;
- protected int outPort;
- private int outGroup;
- private long cookie;
- private long cookieMask;
- protected OFPMatch match;
-
- /**
- * @return the match
- */
- public OFPMatch getMatch() {
- return match;
- }
-
- /**
- * @param match
- * the match to set
- */
- public void setMatch(OFPMatch match) {
- this.match = match;
- }
-
- /**
- * @return the tableId
- */
- public byte getTableId() {
- return tableId;
- }
-
- /**
- * @param tableId
- * the tableId to set
- */
- public void setTableId(byte tableId) {
- this.tableId = tableId;
- }
-
- /**
- * @return the outPort
- */
- public int getOutPort() {
- return outPort;
- }
-
- /**
- * @param outPort
- * the outPort to set
- */
- public void setOutPort(int outPort) {
- this.outPort = outPort;
- }
-
- /**
- *
- * @return
- */
- public int getOutGroup() {
- return outGroup;
- }
-
- /**
- *
- * @param outGroup
- */
-
- public void setOutGroup(int outGroup) {
- this.outGroup = outGroup;
- }
-
- /**
- *
- * @return
- */
- public long getCookie() {
- return cookie;
- }
-
- /**
- *
- * @param cookie
- */
- public void setCookie(long cookie) {
- this.cookie = cookie;
- }
-
- /**
- *
- * @return
- */
- public long getCookieMask() {
- return cookieMask;
- }
-
- /**
- *
- * @param cookieMask
- */
- public void setCookieMask(long cookieMask) {
- this.cookieMask = cookieMask;
- }
-
- @Override
- public int getLength() {
- return MINIMUM_LENGTH;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
-
- this.tableId = data.get();
- data.get(); // pad
- data.getShort(); // pad
- this.outPort = data.getInt();
- this.setOutGroup(data.getInt());
- data.getInt(); // pad
- this.setCookie(data.getLong());
- this.setCookieMask(data.getLong());
- if (this.match == null)
- this.match = new OFPMatch();
- this.match.readFrom(data);
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- data.put(this.tableId);
- data.put((byte) 0);
- data.putShort((short) 0);
- data.putInt(this.outPort);
- data.putInt(this.getOutGroup());
- data.putInt(0);
- data.putLong(this.getCookie());
- data.putLong(this.getCookieMask());
- this.match.writeTo(data);
- }
-
- @Override
- public int hashCode() {
- final int prime = 421;
- int result = 1;
- result = prime * result + ((match == null) ? 0 : match.hashCode());
- result = prime * result + (int) (cookie ^ (cookie >>> 32));
- result = prime * result + (int) (cookieMask ^ (cookieMask >>> 32));
- result = prime * result + outPort;
- result = prime * result + outGroup;
- result = prime * result + tableId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPFlowStatisticsRequest)) {
- return false;
- }
- OFPFlowStatisticsRequest other = (OFPFlowStatisticsRequest) obj;
- if (tableId != other.tableId) {
- return false;
- }
- if (outPort != other.outPort) {
- return false;
- }
- if (getOutGroup() != other.getOutGroup()) {
- return false;
- }
- if (getCookie() != other.getCookie()) {
- return false;
- }
- if (getCookieMask() != other.getCookieMask()) {
- return false;
- }
- if (match == null) {
- if (other.match != null) {
- return false;
- }
- } else if (!match.equals(other.match)) {
- return false;
- }
-
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.action.OFPBucketCounter;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_group_stats structure
- *
- * @author Yugandhar Sarraju (ysarraju@in.ibm.com)
- */
-public class OFPGroupStatisticsReply implements OFPStatistics, Serializable {
- public static int MINIMUM_LENGTH = 40;
-
- protected short length = (short) MINIMUM_LENGTH;
- protected int group_id;
- protected int ref_count;
- protected long packet_count;
- protected long byte_count;
- protected int duration_sec;
- protected int duration_nsec;
- protected List<OFPBucketCounter> bucket_stats;
-
- public void setLength(short length) {
- this.length = length;
- }
-
- @Override
- public int getLength() {
- return U16.f(length);
- }
-
- public int getGroup_id() {
- return group_id;
- }
-
- public void setGroup_id(int group_id) {
- this.group_id = group_id;
- }
-
- public int getRef_count() {
- return ref_count;
- }
-
- public void setRef_count(int ref_count) {
- this.ref_count = ref_count;
- }
-
- public long getPacket_count() {
- return packet_count;
- }
-
- public void setPacket_count(long packet_count) {
- this.packet_count = packet_count;
- }
-
- public long getByte_count() {
- return byte_count;
- }
-
- public void setByte_count(long byte_count) {
- this.byte_count = byte_count;
- }
-
- public int getDuration_sec() {
- return duration_sec;
- }
-
- public void setDuration_sec(int duration_sec) {
- this.duration_sec = duration_sec;
- }
-
- public int getDuration_nsec() {
- return duration_nsec;
- }
-
- public void setDuration_nsec(int duration_nsec) {
- this.duration_nsec = duration_nsec;
- }
-
- public List<OFPBucketCounter> getBucket_stats() {
- return bucket_stats;
- }
-
- public void setBucket_stats(List<OFPBucketCounter> bucket_stats) {
- this.bucket_stats = bucket_stats;
- if (bucket_stats == null) {
- this.setLength((short) MINIMUM_LENGTH);
- } else {
- this.setLength((short) (MINIMUM_LENGTH + bucket_stats.size() * OFPBucketCounter.MINIMUM_LENGTH));
- }
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- this.length = data.getShort();
- data.getShort();
- this.group_id = data.getInt();
- this.ref_count = data.getInt();
- data.getInt();
- this.packet_count = data.getLong();
- this.byte_count = data.getLong();
- this.duration_sec = data.getInt();
- this.duration_nsec = data.getInt();
- if (this.bucket_stats == null) {
- this.bucket_stats = new ArrayList<OFPBucketCounter>();
- } else {
- this.bucket_stats.clear();
- }
- int bucketCounterCount = (this.getLength() - 38) / OFPBucketCounter.MINIMUM_LENGTH;
- OFPBucketCounter bucketCounter;
- for (int i = 0; i < bucketCounterCount; ++i) {
- bucketCounter = new OFPBucketCounter();
- bucketCounter.readFrom(data);
- this.bucket_stats.add(bucketCounter);
- }
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- data.putShort(length);
- data.putShort((short) 0);
- data.putInt(group_id);
- data.putInt(ref_count);
- data.putInt(0);
- data.putLong(packet_count);
- data.putLong(byte_count);
- data.putInt(duration_sec);
- data.putInt(duration_nsec);
- if (bucket_stats != null) {
- for (OFPBucketCounter bucketCounter : bucket_stats) {
- bucketCounter.writeTo(data);
- }
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 419;
- int result = 1;
- result = prime * result + ((bucket_stats == null) ? 0 : bucket_stats.hashCode());
- result = prime * result + length;
- result = prime * result + group_id;
- result = prime * result + ref_count;
- result = prime * result + (int) (packet_count ^ (packet_count >>> 32));
- result = prime * result + (int) (byte_count ^ (byte_count >>> 32));
- result = prime * result + duration_sec;
- result = prime * result + duration_nsec;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPGroupStatisticsReply)) {
- return false;
- }
- OFPGroupStatisticsReply other = (OFPGroupStatisticsReply) obj;
- if (bucket_stats == null) {
- if (other.bucket_stats != null) {
- return false;
- }
- } else if (!bucket_stats.equals(other.bucket_stats)) {
- return false;
- }
- if (length != other.length) {
- return false;
- }
- if (group_id != other.group_id) {
- return false;
- }
- if (ref_count != other.ref_count) {
- return false;
- }
- if (packet_count != other.packet_count) {
- return false;
- }
- if (byte_count != other.byte_count) {
- return false;
- }
- if (duration_sec != other.duration_sec) {
- return false;
- }
- if (duration_nsec != other.duration_nsec) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import java.lang.reflect.Constructor;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.openflow.codec.protocol.Instantiable;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents an ofp_multipart_types enum
- *
- * @author AnilGujele
- *
- */
-public enum OFPMultipartTypes {
- DESC(0, OFPDescriptionStatistics.class, OFPDescriptionStatistics.class, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPDescriptionStatistics();
- }
- }, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPDescriptionStatistics();
- }
- }), FLOW(1, OFPFlowStatisticsRequest.class, OFPFlowStatisticsReply.class, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPFlowStatisticsRequest();
- }
- }, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPFlowStatisticsReply();
- }
- }), AGGREGATE(2, OFPAggregateStatisticsRequest.class, OFPAggregateStatisticsReply.class,
- new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPAggregateStatisticsRequest();
- }
- }, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPAggregateStatisticsReply();
- }
- }), TABLE(3, OFPTableStatistics.class, OFPTableStatistics.class, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPTableStatistics();
- }
- }, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPTableStatistics();
- }
- }), PORT_STATS(4, OFPPortStatisticsRequest.class, OFPPortStatisticsReply.class, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPPortStatisticsRequest();
- }
- }, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPPortStatisticsReply();
- }
- }), QUEUE(5, OFPQueueStatisticsRequest.class, OFPQueueStatisticsReply.class, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPQueueStatisticsRequest();
- }
- }, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPQueueStatisticsReply();
- }
- }), TABLE_FEATURES(12, OFPTableFeatures.class, OFPTableFeatures.class, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPTableFeatures();
- }
- }, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPTableFeatures();
- }
- }), PORT_DESC(13, OFPPortDescriptionStatistics.class, OFPPortDescriptionStatistics.class,
- new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPPortDescriptionStatistics();
- }
- }, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPPortDescriptionStatistics();
- }
- }),
-
- EXPERIMENTER(0xffff, OFPExperimenterMultipartHeader.class, OFPExperimenterMultipartHeader.class,
- new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPExperimenterMultipartHeader();
- }
- }, new Instantiable<OFPStatistics>() {
- @Override
- public OFPStatistics instantiate() {
- return new OFPExperimenterMultipartHeader();
- }
- });
-
- private static Map<Integer, OFPMultipartTypes> requestMapping;
- private static Map<Integer, OFPMultipartTypes> replyMapping;
-
- private Class<? extends OFPStatistics> requestClass;
- private Constructor<? extends OFPStatistics> requestConstructor;
- private Instantiable<OFPStatistics> requestInstantiable;
- private Class<? extends OFPStatistics> replyClass;
- private Constructor<? extends OFPStatistics> replyConstructor;
- private Instantiable<OFPStatistics> replyInstantiable;
- private int type;
-
- /**
- * Store some information about the OpenFlow Statistic type, including wire
- * protocol type number, and derived class
- *
- * @param type
- * Wire protocol number associated with this OFPMultipartType
- * @param requestClass
- * The Multipart Java class to return when the containing OFPType
- * is MULTIPART_REQUEST
- * @param replyClass
- * The Multipart Java class to return when the containing OFPType
- * is MULTIPART_REPLY
- */
- OFPMultipartTypes(int type, Class<? extends OFPStatistics> requestClass, Class<? extends OFPStatistics> replyClass,
- Instantiable<OFPStatistics> requestInstantiable, Instantiable<OFPStatistics> replyInstantiable) {
- this.type = type;
- this.requestClass = requestClass;
- try {
- this.requestConstructor = requestClass.getConstructor(new Class[] {});
- } catch (Exception e) {
- throw new RuntimeException("Failure getting constructor for class: " + requestClass, e);
- }
-
- this.replyClass = replyClass;
- try {
- this.replyConstructor = replyClass.getConstructor(new Class[] {});
- } catch (Exception e) {
- throw new RuntimeException("Failure getting constructor for class: " + replyClass, e);
- }
- this.requestInstantiable = requestInstantiable;
- this.replyInstantiable = replyInstantiable;
- OFPMultipartTypes.addMapping(this.type, OFPType.MULTIPART_REQUEST, this);
- OFPMultipartTypes.addMapping(this.type, OFPType.MULTIPART_REPLY, this);
- }
-
- /**
- * Adds a mapping from type value to OFStatisticsType enum
- *
- * @param i
- * OpenFlow wire protocol type
- * @param t
- * type of containing OFPMessage, only accepts MULTIPART_REQUEST
- * or MULTIPART_REPLY
- * @param st
- * type
- */
- public static void addMapping(int i, OFPType t, OFPMultipartTypes st) {
-
- if (t == OFPType.MULTIPART_REQUEST) {
- if (requestMapping == null)
- requestMapping = new HashMap<Integer, OFPMultipartTypes>();
- OFPMultipartTypes.requestMapping.put(i, st);
- } else if (t == OFPType.MULTIPART_REPLY) {
- if (replyMapping == null)
- replyMapping = new HashMap<Integer, OFPMultipartTypes>();
- OFPMultipartTypes.replyMapping.put(i, st);
- } else {
- throw new RuntimeException(t.toString() + " is an invalid OFPType");
- }
- }
-
- /**
- * Remove a mapping from type value to OFPMultipartType enum
- *
- * @param i
- * OpenFlow wire protocol type
- * @param t
- * type of containing OFPMessage, only accepts MULTIPART_REQUEST
- * or MULTIPART_REPLY
- */
- public static void removeMapping(int i, OFPType t) {
- if (t == OFPType.MULTIPART_REQUEST) {
- requestMapping.remove(i);
- } else if (t == OFPType.MULTIPART_REPLY) {
- replyMapping.remove(i);
- } else {
- throw new RuntimeException(t.toString() + " is an invalid OFPType");
- }
- }
-
- /**
- * Given a wire protocol OpenFlow type number, return the OFPMultipartType
- * associated with it
- *
- * @param i
- * wire protocol number
- * @param t
- * type of containing OFPMessage, only accepts MULTIPART_REQUEST
- * or MULTIPART_REPLY
- * @return OFPMultipartType enum type
- */
- public static OFPMultipartTypes valueOf(short i, OFPType t) {
- if (t == OFPType.MULTIPART_REQUEST) {
- return requestMapping.get(U16.f(i));
- } else if (t == OFPType.MULTIPART_REPLY) {
- return replyMapping.get(U16.f(i));
- } else {
- throw new RuntimeException(t.toString() + " is an invalid OFPType");
- }
- }
-
- /**
- * @return Returns the wire protocol value corresponding to this
- * OFPMultipartType
- */
- public short getTypeValue() {
- return U16.t(this.type);
- }
-
- /**
- * @return Returns the wire protocol unsigned value corresponding to this
- * OFPMultipartType
- */
- public int getTypeValueU() {
- return this.type;
- }
-
- /**
- * @param t
- * type of containing OFPMessage, only accepts MULTIPART_REQUEST
- * or MULTIPART_REPLY
- * @return return the OFPMessage subclass corresponding to this
- * OFPMultipartType
- */
- public Class<? extends OFPStatistics> toClass(OFPType t) {
- if (t == OFPType.MULTIPART_REQUEST) {
- return requestClass;
- } else if (t == OFPType.MULTIPART_REPLY) {
- return replyClass;
- } else {
- throw new RuntimeException(t.toString() + " is an invalid OFPType");
- }
- }
-
- /**
- * Returns the no-argument Constructor of the implementation class for this
- * OFPMultipartType, either request or reply based on the supplied OFPType
- *
- * @param t
- * @return
- */
- public Constructor<? extends OFPStatistics> getConstructor(OFPType t) {
- if (t == OFPType.MULTIPART_REQUEST) {
- return requestConstructor;
- } else if (t == OFPType.MULTIPART_REPLY) {
- return replyConstructor;
- } else {
- throw new RuntimeException(t.toString() + " is an invalid OFPType");
- }
- }
-
- /**
- * @return the requestInstantiable
- */
- public Instantiable<OFPStatistics> getRequestInstantiable() {
- return requestInstantiable;
- }
-
- /**
- * @param requestInstantiable
- * the requestInstantiable to set
- */
- public void setRequestInstantiable(Instantiable<OFPStatistics> requestInstantiable) {
- this.requestInstantiable = requestInstantiable;
- }
-
- /**
- * @return the replyInstantiable
- */
- public Instantiable<OFPStatistics> getReplyInstantiable() {
- return replyInstantiable;
- }
-
- /**
- * @param replyInstantiable
- * the replyInstantiable to set
- */
- public void setReplyInstantiable(Instantiable<OFPStatistics> replyInstantiable) {
- this.replyInstantiable = replyInstantiable;
- }
-
- /**
- * Returns a new instance of the implementation class for this
- * OFPMultipartType, either request or reply based on the supplied OFPType
- *
- * @param t
- * @return
- */
- public OFPStatistics newInstance(OFPType t) {
- if (t == OFPType.MULTIPART_REQUEST) {
- return requestInstantiable.instantiate();
- } else if (t == OFPType.MULTIPART_REPLY) {
- return replyInstantiable.instantiate();
- } else {
- throw new RuntimeException(t.toString() + " is an invalid OFPType");
- }
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import java.io.Serializable;
-
-import org.openflow.codec.protocol.OFPPort;
-
-/**
- * Represents struct ofp_port for OFPMP_PORT_DESCRIPTION
- *
- * @author AnilGujele
- *
- */
-public class OFPPortDescriptionStatistics extends OFPPort implements OFPStatistics, Serializable {
-
- public OFPPortDescriptionStatistics() {
-
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an ofp_port_stats structure
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author AnilGujele
- */
-public class OFPPortStatisticsReply implements OFPStatistics {
- private static final int MINIMUM_LENGTH = 112;
- protected int portNumber;
- protected long receivePackets;
- protected long transmitPackets;
- protected long receiveBytes;
- protected long transmitBytes;
- protected long receiveDropped;
- protected long transmitDropped;
- protected long receiveErrors;
- protected long transmitErrors;
- protected long receiveFrameErrors;
- protected long receiveOverrunErrors;
- protected long receiveCRCErrors;
- protected long collisions;
- protected int durationSec;
- protected int durationNanoSec;
-
- /**
- * @return the portNumber
- */
- public int getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param portNumber
- * the portNumber to set
- */
- public void setPortNumber(int portNumber) {
- this.portNumber = portNumber;
- }
-
- /**
- * @return the receivePackets
- */
- public long getreceivePackets() {
- return receivePackets;
- }
-
- /**
- * @param receivePackets
- * the receivePackets to set
- */
- public void setreceivePackets(long receivePackets) {
- this.receivePackets = receivePackets;
- }
-
- /**
- * @return the transmitPackets
- */
- public long getTransmitPackets() {
- return transmitPackets;
- }
-
- /**
- * @param transmitPackets
- * the transmitPackets to set
- */
- public void setTransmitPackets(long transmitPackets) {
- this.transmitPackets = transmitPackets;
- }
-
- /**
- * @return the receiveBytes
- */
- public long getReceiveBytes() {
- return receiveBytes;
- }
-
- /**
- * @param receiveBytes
- * the receiveBytes to set
- */
- public void setReceiveBytes(long receiveBytes) {
- this.receiveBytes = receiveBytes;
- }
-
- /**
- * @return the transmitBytes
- */
- public long getTransmitBytes() {
- return transmitBytes;
- }
-
- /**
- * @param transmitBytes
- * the transmitBytes to set
- */
- public void setTransmitBytes(long transmitBytes) {
- this.transmitBytes = transmitBytes;
- }
-
- /**
- * @return the receiveDropped
- */
- public long getReceiveDropped() {
- return receiveDropped;
- }
-
- /**
- * @param receiveDropped
- * the receiveDropped to set
- */
- public void setReceiveDropped(long receiveDropped) {
- this.receiveDropped = receiveDropped;
- }
-
- /**
- * @return the transmitDropped
- */
- public long getTransmitDropped() {
- return transmitDropped;
- }
-
- /**
- * @param transmitDropped
- * the transmitDropped to set
- */
- public void setTransmitDropped(long transmitDropped) {
- this.transmitDropped = transmitDropped;
- }
-
- /**
- * @return the receiveErrors
- */
- public long getreceiveErrors() {
- return receiveErrors;
- }
-
- /**
- * @param receiveErrors
- * the receiveErrors to set
- */
- public void setreceiveErrors(long receiveErrors) {
- this.receiveErrors = receiveErrors;
- }
-
- /**
- * @return the transmitErrors
- */
- public long getTransmitErrors() {
- return transmitErrors;
- }
-
- /**
- * @param transmitErrors
- * the transmitErrors to set
- */
- public void setTransmitErrors(long transmitErrors) {
- this.transmitErrors = transmitErrors;
- }
-
- /**
- * @return the receiveFrameErrors
- */
- public long getReceiveFrameErrors() {
- return receiveFrameErrors;
- }
-
- /**
- * @param receiveFrameErrors
- * the receiveFrameErrors to set
- */
- public void setReceiveFrameErrors(long receiveFrameErrors) {
- this.receiveFrameErrors = receiveFrameErrors;
- }
-
- /**
- * @return the receiveOverrunErrors
- */
- public long getReceiveOverrunErrors() {
- return receiveOverrunErrors;
- }
-
- /**
- * @param receiveOverrunErrors
- * the receiveOverrunErrors to set
- */
- public void setReceiveOverrunErrors(long receiveOverrunErrors) {
- this.receiveOverrunErrors = receiveOverrunErrors;
- }
-
- /**
- * @return the receiveCRCErrors
- */
- public long getReceiveCRCErrors() {
- return receiveCRCErrors;
- }
-
- /**
- * @param receiveCRCErrors
- * the receiveCRCErrors to set
- */
- public void setReceiveCRCErrors(long receiveCRCErrors) {
- this.receiveCRCErrors = receiveCRCErrors;
- }
-
- /**
- * @return the collisions
- */
- public long getCollisions() {
- return collisions;
- }
-
- /**
- * @param collisions
- * the collisions to set
- */
- public void setCollisions(long collisions) {
- this.collisions = collisions;
- }
-
- /**
- * get duration time port has been alive in sec
- *
- * @return
- */
- public int getDurationSec() {
- return durationSec;
- }
-
- /**
- * set duration time port has been alive in sec
- *
- * @param durationSec
- */
- public void setDurationSec(int durationSec) {
- this.durationSec = durationSec;
- }
-
- /**
- * get duration time port has been alive in nano sec beyond duration second
- *
- * @return
- */
- public int getDurationNanoSec() {
- return durationNanoSec;
- }
-
- /**
- * set duration time port has been alive in nano sec beyond duration second
- *
- * @param durationNanoSec
- */
- public void setDurationNanoSec(int durationNanoSec) {
- this.durationNanoSec = durationNanoSec;
- }
-
- @Override
- public int getLength() {
- return MINIMUM_LENGTH;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- this.portNumber = data.getInt();
- data.getInt(); // pad
- this.receivePackets = data.getLong();
- this.transmitPackets = data.getLong();
- this.receiveBytes = data.getLong();
- this.transmitBytes = data.getLong();
- this.receiveDropped = data.getLong();
- this.transmitDropped = data.getLong();
- this.receiveErrors = data.getLong();
- this.transmitErrors = data.getLong();
- this.receiveFrameErrors = data.getLong();
- this.receiveOverrunErrors = data.getLong();
- this.receiveCRCErrors = data.getLong();
- this.collisions = data.getLong();
- this.durationSec = data.getInt();
- this.durationNanoSec = data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- data.putInt(this.portNumber);
- data.putInt(0); // pad
- data.putLong(this.receivePackets);
- data.putLong(this.transmitPackets);
- data.putLong(this.receiveBytes);
- data.putLong(this.transmitBytes);
- data.putLong(this.receiveDropped);
- data.putLong(this.transmitDropped);
- data.putLong(this.receiveErrors);
- data.putLong(this.transmitErrors);
- data.putLong(this.receiveFrameErrors);
- data.putLong(this.receiveOverrunErrors);
- data.putLong(this.receiveCRCErrors);
- data.putLong(this.collisions);
- data.putInt(this.durationSec);
- data.putInt(this.durationNanoSec);
- }
-
- @Override
- public int hashCode() {
- final int prime = 431;
- int result = 1;
- result = prime * result + (int) (collisions ^ (collisions >>> 32));
- result = prime * result + portNumber;
- result = prime * result + durationSec;
- result = prime * result + durationNanoSec;
- result = prime * result + (int) (receivePackets ^ (receivePackets >>> 32));
- result = prime * result + (int) (receiveBytes ^ (receiveBytes >>> 32));
- result = prime * result + (int) (receiveCRCErrors ^ (receiveCRCErrors >>> 32));
- result = prime * result + (int) (receiveDropped ^ (receiveDropped >>> 32));
- result = prime * result + (int) (receiveFrameErrors ^ (receiveFrameErrors >>> 32));
- result = prime * result + (int) (receiveOverrunErrors ^ (receiveOverrunErrors >>> 32));
- result = prime * result + (int) (receiveErrors ^ (receiveErrors >>> 32));
- result = prime * result + (int) (transmitBytes ^ (transmitBytes >>> 32));
- result = prime * result + (int) (transmitDropped ^ (transmitDropped >>> 32));
- result = prime * result + (int) (transmitErrors ^ (transmitErrors >>> 32));
- result = prime * result + (int) (transmitPackets ^ (transmitPackets >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPPortStatisticsReply)) {
- return false;
- }
- OFPPortStatisticsReply other = (OFPPortStatisticsReply) obj;
- if (collisions != other.collisions) {
- return false;
- }
- if (portNumber != other.portNumber) {
- return false;
- }
- if (durationSec != other.durationSec) {
- return false;
- }
- if (durationNanoSec != other.durationNanoSec) {
- return false;
- }
- if (receivePackets != other.receivePackets) {
- return false;
- }
- if (receiveBytes != other.receiveBytes) {
- return false;
- }
- if (receiveCRCErrors != other.receiveCRCErrors) {
- return false;
- }
- if (receiveDropped != other.receiveDropped) {
- return false;
- }
- if (receiveFrameErrors != other.receiveFrameErrors) {
- return false;
- }
- if (receiveOverrunErrors != other.receiveOverrunErrors) {
- return false;
- }
- if (receiveErrors != other.receiveErrors) {
- return false;
- }
- if (transmitBytes != other.transmitBytes) {
- return false;
- }
- if (transmitDropped != other.transmitDropped) {
- return false;
- }
- if (transmitErrors != other.transmitErrors) {
- return false;
- }
- if (transmitPackets != other.transmitPackets) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an ofp_port_stats_request structure
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author AnilGujele
- */
-public class OFPPortStatisticsRequest implements OFPStatistics {
- private final static int MINIMUM_LENGTH = 8;
- protected int portNumber;
-
- /**
- * @return the portNumber
- */
- public int getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param portNumber
- * the portNumber to set
- */
- public void setPortNumber(int portNumber) {
- this.portNumber = portNumber;
- }
-
- @Override
- public int getLength() {
- return MINIMUM_LENGTH;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- this.portNumber = data.getInt();
- data.getInt(); // pad
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- data.putInt(this.portNumber);
- data.putInt(0); // pad
- }
-
- @Override
- public int hashCode() {
- final int prime = 433;
- int result = 1;
- result = prime * result + portNumber;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPPortStatisticsRequest)) {
- return false;
- }
- OFPPortStatisticsRequest other = (OFPPortStatisticsRequest) obj;
- if (portNumber != other.portNumber) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an ofp_queue_stats structure
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author AnilGujele
- */
-public class OFPQueueStatisticsReply implements OFPStatistics {
- private final static int MINIMUM_LENGTH = 40;
- protected int portNumber;
- protected int queueId;
- protected long transmitBytes;
- protected long transmitPackets;
- protected long transmitErrors;
- protected int durationSec;
- protected int durationNanoSec;
-
- /**
- * @return the portNumber
- */
- public int getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param portNumber
- * the portNumber to set
- */
- public void setPortNumber(int portNumber) {
- this.portNumber = portNumber;
- }
-
- /**
- * @return the queueId
- */
- public int getQueueId() {
- return queueId;
- }
-
- /**
- * @param queueId
- * the queueId to set
- */
- public void setQueueId(int queueId) {
- this.queueId = queueId;
- }
-
- /**
- * @return the transmitBytes
- */
- public long getTransmitBytes() {
- return transmitBytes;
- }
-
- /**
- * @param transmitBytes
- * the transmitBytes to set
- */
- public void setTransmitBytes(long transmitBytes) {
- this.transmitBytes = transmitBytes;
- }
-
- /**
- * @return the transmitPackets
- */
- public long getTransmitPackets() {
- return transmitPackets;
- }
-
- /**
- * @param transmitPackets
- * the transmitPackets to set
- */
- public void setTransmitPackets(long transmitPackets) {
- this.transmitPackets = transmitPackets;
- }
-
- /**
- * @return the transmitErrors
- */
- public long getTransmitErrors() {
- return transmitErrors;
- }
-
- /**
- * @param transmitErrors
- * the transmitErrors to set
- */
- public void setTransmitErrors(long transmitErrors) {
- this.transmitErrors = transmitErrors;
- }
-
- /**
- * get duration queue has been alive in seconds.
- *
- * @return
- */
- public int getDurationSec() {
- return durationSec;
- }
-
- /**
- * set duration queue has been alive in seconds.
- *
- * @param durationSec
- */
- public void setDurationSec(int durationSec) {
- this.durationSec = durationSec;
- }
-
- /**
- * get duration queue has been alive in nanoseconds beyond duration_sec.
- *
- * @return
- */
- public int getDurationNanoSec() {
- return durationNanoSec;
- }
-
- /**
- * set duration queue has been alive in nanoseconds beyond duration_sec.
- *
- * @param durationNanoSec
- */
- public void setDurationNanoSec(int durationNanoSec) {
- this.durationNanoSec = durationNanoSec;
- }
-
- @Override
- public int getLength() {
- return MINIMUM_LENGTH;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- this.portNumber = data.getInt();
- this.queueId = data.getInt();
- this.transmitBytes = data.getLong();
- this.transmitPackets = data.getLong();
- this.transmitErrors = data.getLong();
- this.durationSec = data.getInt();
- this.durationNanoSec = data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- data.putInt(this.portNumber);
- data.putInt(this.queueId);
- data.putLong(this.transmitBytes);
- data.putLong(this.transmitPackets);
- data.putLong(this.transmitErrors);
- data.putInt(this.durationSec);
- data.putInt(this.durationNanoSec);
- }
-
- @Override
- public int hashCode() {
- final int prime = 439;
- int result = 1;
- result = prime * result + portNumber;
- result = prime * result + queueId;
- result = prime * result + (int) (transmitBytes ^ (transmitBytes >>> 32));
- result = prime * result + (int) (transmitErrors ^ (transmitErrors >>> 32));
- result = prime * result + (int) (transmitPackets ^ (transmitPackets >>> 32));
- result = prime * result + durationSec;
- result = prime * result + durationNanoSec;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPQueueStatisticsReply)) {
- return false;
- }
- OFPQueueStatisticsReply other = (OFPQueueStatisticsReply) obj;
- if (portNumber != other.portNumber) {
- return false;
- }
- if (queueId != other.queueId) {
- return false;
- }
- if (transmitBytes != other.transmitBytes) {
- return false;
- }
- if (transmitErrors != other.transmitErrors) {
- return false;
- }
- if (transmitPackets != other.transmitPackets) {
- return false;
- }
- if (durationSec != other.durationSec) {
- return false;
- }
- if (durationNanoSec != other.durationNanoSec) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an ofp_queue_stats_request structure
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author AnilGujele
- */
-public class OFPQueueStatisticsRequest implements OFPStatistics {
- private static final int MINIMUM_LENGTH = 8;
- protected int portNumber;
- protected int queueId;
-
- /**
- * @return the portNumber
- */
- public int getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param portNumber
- * the portNumber to set
- */
- public void setPortNumber(int portNumber) {
- this.portNumber = portNumber;
- }
-
- /**
- * @return the queueId
- */
- public int getQueueId() {
- return queueId;
- }
-
- /**
- * @param queueId
- * the queueId to set
- */
- public void setQueueId(int queueId) {
- this.queueId = queueId;
- }
-
- @Override
- public int getLength() {
- return MINIMUM_LENGTH;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- this.portNumber = data.getInt();
- this.queueId = data.getInt();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- data.putInt(this.portNumber);
- data.putInt(this.queueId);
- }
-
- @Override
- public int hashCode() {
- final int prime = 443;
- int result = 1;
- result = prime * result + portNumber;
- result = prime * result + queueId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPQueueStatisticsRequest)) {
- return false;
- }
- OFPQueueStatisticsRequest other = (OFPQueueStatisticsRequest) obj;
- if (portNumber != other.portNumber) {
- return false;
- }
- if (queueId != other.queueId) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * The base class for all OpenFlow statistics.
- *
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-public interface OFPStatistics {
- /**
- * Returns the wire length of this message in bytes
- *
- * @return the length
- */
- public int getLength();
-
- /**
- * Read this message off the wire from the specified DataBuffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data);
-
- /**
- * Write this message's binary format to the specified DataBuffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data);
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.factory.OFPActionFactory;
-import org.openflow.codec.protocol.factory.OFPActionFactoryAware;
-import org.openflow.codec.protocol.factory.OFPInstructionFactory;
-import org.openflow.codec.protocol.factory.OFPInstructionFactoryAware;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropHeader;
-import org.openflow.codec.util.StringByteSerializer;
-
-/**
- * Represents an ofp_table_features structure
- *
- * @author AnilGujele
- */
-public class OFPTableFeatures implements OFPStatistics, OFPInstructionFactoryAware, OFPActionFactoryAware, Serializable {
- private static final int MINIMUM_LENGTH = 64;
- private static final int MAX_TABLE_NAME_LEN = 32;
-
- private short length = MINIMUM_LENGTH;
- private byte tableId;
- private String name;
- private long metadataMatch;
- private long metadataWrite;
- private int config;
- private int maxEntries;
- private List<OFPTableFeaturePropHeader> properties;
- private OFPInstructionFactory instructionFactory;
- private OFPActionFactory actionFactory;
-
- /**
- * @return the tableId
- */
- public byte getTableId() {
- return tableId;
- }
-
- /**
- * @param tableId
- * the tableId to set
- */
- public void setTableId(byte tableId) {
- this.tableId = tableId;
- }
-
- /**
- *
- * @return
- */
- public String getName() {
- return name;
- }
-
- /**
- *
- * @param name
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- *
- * @return
- */
- public long getMetadataMatch() {
- return metadataMatch;
- }
-
- /**
- *
- * @param metadataMatch
- */
- public void setMetadataMatch(long metadataMatch) {
- this.metadataMatch = metadataMatch;
- }
-
- /**
- *
- * @return
- */
- public long getMetadataWrite() {
- return metadataWrite;
- }
-
- /**
- *
- * @param metadataWrite
- */
- public void setMetadataWrite(long metadataWrite) {
- this.metadataWrite = metadataWrite;
- }
-
- /**
- *
- * @return
- */
- public int getConfig() {
- return config;
- }
-
- /**
- *
- * @param config
- */
- public void setConfig(int config) {
- this.config = config;
- }
-
- /**
- *
- * @return
- */
- public int getMaxEntries() {
- return maxEntries;
- }
-
- /**
- *
- * @param maxEntries
- */
- public void setMaxEntries(int maxEntries) {
- this.maxEntries = maxEntries;
- }
-
- /**
- *
- * @return
- */
- public List<OFPTableFeaturePropHeader> getProperties() {
- return properties;
- }
-
- /**
- *
- * @param properties
- */
- public void setProperties(List<OFPTableFeaturePropHeader> properties) {
- this.properties = properties;
- updateLength();
- }
-
- /**
- * update length TODO: All the associated properties are 8 byte (64 bits)
- * aligned. Length of each property excludes the padding, if we sum up each
- * associated property length it will give us length excluding the total
- * bytes of padding added to make it align. We assume that table feature
- * response message switch will send in response to OFPMP_TABLE_FEATURES
- * request, will also consider padding in the message lengh. Something to
- * cross check with switch implementation.
- */
- private void updateLength() {
- length = MINIMUM_LENGTH;
- for (OFPTableFeaturePropHeader prop : properties) {
- int len = prop.getLengthU();
- /* Add the aligned length, including padding */
- length += len + (8 - (len % 8));
-
- }
- }
-
- @Override
- public int getLength() {
- return length;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
-
- this.length = data.getShort();
- this.tableId = data.get();
- data.get(); // pad
- data.getInt(); // pad
- this.name = StringByteSerializer.readFrom(data, MAX_TABLE_NAME_LEN);
- this.metadataMatch = data.getLong();
- this.metadataWrite = data.getLong();
- this.config = data.getInt();
- this.maxEntries = data.getInt();
- int propLength = this.length - OFPTableFeatures.MINIMUM_LENGTH;
- this.properties = readTableFeatureProp(data, propLength);
-
- }
-
- /**
- * read table feature property type
- *
- * @param data
- * @param length
- * @return
- */
- private List<OFPTableFeaturePropHeader> readTableFeatureProp(IDataBuffer data, int length) {
- List<OFPTableFeaturePropHeader> results = null;
- OFPTableFeaturePropHeader tempProp = new OFPTableFeaturePropHeader();
- OFPTableFeaturePropHeader ofTFProp;
- int end = data.position() + length;
-
- while (data.position() <= end) {
- if (data.remaining() < OFPTableFeaturePropHeader.MINIMUM_LENGTH
- || (data.position() + OFPTableFeaturePropHeader.MINIMUM_LENGTH) > end)
- return results;
-
- // to read property type
- data.mark();
- tempProp.readFrom(data);
- data.reset();
-
- if (tempProp.getLengthU() > data.remaining() || (data.position() + tempProp.getLengthU()) > end)
- return results;
- // create instance of porperty type
- ofTFProp = tempProp.getOFTableFeaturePropType().newInstance();
- if (ofTFProp instanceof OFPInstructionFactoryAware) {
- ((OFPInstructionFactoryAware) ofTFProp).setInstructionFactory(this.instructionFactory);
- }
- if (ofTFProp instanceof OFPActionFactoryAware) {
- ((OFPActionFactoryAware) ofTFProp).setActionFactory(this.actionFactory);
- }
- ofTFProp.readFrom(data);
- if (null == results) {
- results = new ArrayList<OFPTableFeaturePropHeader>();
- }
- results.add(ofTFProp);
- }
-
- return results;
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
-
- data.putShort(length);
- data.put(this.tableId);
- data.put((byte) 0); // pad
- data.putInt(0); // pad
- StringByteSerializer.writeTo(data, MAX_TABLE_NAME_LEN, this.name);
- data.putLong(this.metadataMatch);
- data.putLong(this.metadataWrite);
- data.putInt(this.config);
- data.putInt(this.maxEntries);
- if (null != properties) {
- for (OFPTableFeaturePropHeader prop : properties) {
- prop.writeTo(data);
- }
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 4491;
- int result = 1;
- result = prime * result + maxEntries;
- result = prime * result + config;
- result = prime * result + (int) (metadataMatch ^ (metadataMatch >>> 32));
- result = prime * result + (int) (metadataWrite ^ (metadataWrite >>> 32));
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + tableId;
- result = prime * result + length;
- result = prime * result + ((properties == null) ? 0 : properties.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPTableFeatures)) {
- return false;
- }
- OFPTableFeatures other = (OFPTableFeatures) obj;
- if (maxEntries != other.maxEntries) {
- return false;
- }
- if (config != other.config) {
- return false;
- }
- if (metadataMatch != other.metadataMatch) {
- return false;
- }
- if (metadataWrite != other.metadataWrite) {
- return false;
- }
- if (length != other.length) {
- return false;
- }
- if (tableId != other.tableId) {
- return false;
- }
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (properties == null) {
- if (other.properties != null) {
- return false;
- }
- } else if (!properties.equals(other.properties)) {
- return false;
- }
- return true;
- }
-
- @Override
- public void setActionFactory(OFPActionFactory actionFactory) {
- this.actionFactory = actionFactory;
-
- }
-
- @Override
- public void setInstructionFactory(OFPInstructionFactory instructionFactory) {
- this.instructionFactory = instructionFactory;
-
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics;
-
-import java.io.Serializable;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents an ofp_table_stats structure
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author AnilGujele
- */
-public class OFPTableStatistics implements OFPStatistics, Serializable {
- private static final int MINIMUM_LENGTH = 24;
-
- protected byte tableId;
- protected int activeCount;
- protected long lookupCount;
- protected long matchedCount;
-
- /**
- * @return the tableId
- */
- public byte getTableId() {
- return tableId;
- }
-
- /**
- * @param tableId
- * the tableId to set
- */
- public void setTableId(byte tableId) {
- this.tableId = tableId;
- }
-
- /**
- * @return the activeCount
- */
- public int getActiveCount() {
- return activeCount;
- }
-
- /**
- * @param activeCount
- * the activeCount to set
- */
- public void setActiveCount(int activeCount) {
- this.activeCount = activeCount;
- }
-
- /**
- * @return the lookupCount
- */
- public long getLookupCount() {
- return lookupCount;
- }
-
- /**
- * @param lookupCount
- * the lookupCount to set
- */
- public void setLookupCount(long lookupCount) {
- this.lookupCount = lookupCount;
- }
-
- /**
- * @return the matchedCount
- */
- public long getMatchedCount() {
- return matchedCount;
- }
-
- /**
- * @param matchedCount
- * the matchedCount to set
- */
- public void setMatchedCount(long matchedCount) {
- this.matchedCount = matchedCount;
- }
-
- @Override
- public int getLength() {
- return MINIMUM_LENGTH;
- }
-
- @Override
- public void readFrom(IDataBuffer data) {
- this.tableId = data.get();
- data.get(); // pad
- data.get(); // pad
- data.get(); // pad
- this.activeCount = data.getInt();
- this.lookupCount = data.getLong();
- this.matchedCount = data.getLong();
- }
-
- @Override
- public void writeTo(IDataBuffer data) {
- data.put(this.tableId);
- data.put((byte) 0); // pad
- data.put((byte) 0); // pad
- data.put((byte) 0); // pad
- data.putInt(this.activeCount);
- data.putLong(this.lookupCount);
- data.putLong(this.matchedCount);
- }
-
- @Override
- public int hashCode() {
- final int prime = 449;
- int result = 1;
- result = prime * result + activeCount;
- result = prime * result + (int) (lookupCount ^ (lookupCount >>> 32));
- result = prime * result + (int) (matchedCount ^ (matchedCount >>> 32));
- result = prime * result + tableId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPTableStatistics)) {
- return false;
- }
- OFPTableStatistics other = (OFPTableStatistics) obj;
- if (activeCount != other.activeCount) {
- return false;
- }
- if (lookupCount != other.lookupCount) {
- return false;
- }
- if (matchedCount != other.matchedCount) {
- return false;
- }
- if (tableId != other.tableId) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.action.OFPAction;
-import org.openflow.codec.protocol.factory.OFPActionFactory;
-import org.openflow.codec.protocol.factory.OFPActionFactoryAware;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents struct ofp_table_feature_prop_actions
- *
- * @author AnilGujele
- *
- */
-public abstract class OFPTableFeaturePropActions extends OFPTableFeaturePropHeader implements OFPActionFactoryAware {
- private List<OFPAction> actionIds;
- private OFPActionFactory actionFactory;
-
- /**
- * constructor
- */
- public OFPTableFeaturePropActions() {
- super.setLength(MINIMUM_LENGTH);
- actionIds = new ArrayList<OFPAction>();
- }
-
- /**
- * get list of action id
- *
- * @return
- */
- public List<OFPAction> getActionIds() {
- return actionIds;
- }
-
- /**
- * set list of action id
- *
- * @param actionIds
- */
- public void setActionIds(List<OFPAction> actionIds) {
- this.actionIds = actionIds;
- updateLength();
- }
-
- /**
- * update the length
- *
- * @return
- */
- private void updateLength() {
- int length = this.getLength();
- for (OFPAction OFAction : actionIds) {
- length += OFAction.getLengthU();
- }
- this.setLength((short) length);
-
- }
-
- /**
- * read OFPTableFeaturePropActions from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- int actionIdsLength = U16.f(this.getLength()) - MINIMUM_LENGTH;
- // TODO : experimenter part where size can differ
- // It will be dependent on type of experimenter
- if (null == actionFactory) {
- throw new RuntimeException("OFPInstructionFactory is not set.");
- }
- actionIds = actionFactory.parseActions(data, actionIdsLength);
- /* Read the padding, if any */
- int paddingLength = ((this.getLength() % MULTIPLE_OF_EIGHT) == 0) ? 0
- : (MULTIPLE_OF_EIGHT - (this.getLength() % MULTIPLE_OF_EIGHT));
- data.position(data.position() + paddingLength);
- }
-
- /**
- * write OFPTableFeaturePropActions to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- // write action ids
- for (OFPAction ofAction : actionIds) {
- ofAction.writeTo(data);
- }
- /* Add padding if structure is not 8 byte aligned */
- int paddingLength = ((this.getLength() % MULTIPLE_OF_EIGHT) == 0) ? 0
- : (MULTIPLE_OF_EIGHT - (this.getLength() % MULTIPLE_OF_EIGHT));
- byte[] padding = new byte[paddingLength];
- data.put(padding);
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 744;
- int result = super.hashCode();
- result = prime * result + actionIds.hashCode();
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPTableFeaturePropActions)) {
- return false;
- }
- OFPTableFeaturePropActions other = (OFPTableFeaturePropActions) obj;
- if (!this.actionIds.equals(other.actionIds)) {
- return false;
- }
- return true;
- }
-
- @Override
- public void setActionFactory(OFPActionFactory actionFactory) {
- this.actionFactory = actionFactory;
-
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-/**
- * Class defines OFPTFPT_APPLY_ACTIONS type
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropApplyActions extends OFPTableFeaturePropActions {
-
- /**
- * constructor
- */
- public OFPTableFeaturePropApplyActions() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.APPLY_ACTIONS);
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-/**
- * Class defines OFPTFPT_APPLY_ACTIONS_MISS type
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropApplyActionsMiss extends OFPTableFeaturePropActions {
-
- /**
- * constructor
- */
- public OFPTableFeaturePropApplyActionsMiss() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.APPLY_ACTIONS_MISS);
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-/**
- * Class defines OFPTFPT_APPLY_SETFIELD type
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropApplySetField extends OFPTableFeaturePropOXM {
-
- /**
- * constructor
- */
- public OFPTableFeaturePropApplySetField() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.APPLY_SETFIELD);
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-/**
- * Class defines OFPTFPT_APPLY_SETFIELD_MISS type
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropApplySetFieldMiss extends OFPTableFeaturePropOXM {
-
- /**
- * constructor
- */
- public OFPTableFeaturePropApplySetFieldMiss() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.APPLY_SETFIELD_MISS);
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-import java.util.Arrays;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * Represents struct ofp_table_feature_prop_experimenter
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropExperimenter extends OFPTableFeaturePropHeader {
- private static final short MINIMUM_LENGTH = 12;
- private int expId;
- private int expType;
- private int[] expData = new int[0];
-
- /**
- * constructor
- */
- public OFPTableFeaturePropExperimenter() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.EXPERIMENTER);
- super.setLength(OFPTableFeaturePropExperimenter.MINIMUM_LENGTH);
- }
-
- public int getExpId() {
- return expId;
- }
-
- public void setExpId(int expId) {
- this.expId = expId;
- }
-
- public int getExpType() {
- return expType;
- }
-
- public void setExpType(int expType) {
- this.expType = expType;
- }
-
- public int[] getExpData() {
- return expData;
- }
-
- public void setExpData(int[] expData) {
- this.expData = expData;
- updateLength();
- }
-
- /**
- * update the length
- *
- */
- private void updateLength() {
- int length = this.getLength() + (expData.length * 4);
- this.setLength((short) length);
-
- }
-
- /**
- * read OFPTableFeaturePropExperimenter from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- this.expId = data.getInt();
- this.expType = data.getInt();
- int dataLength = this.getLengthU() - OFPTableFeaturePropExperimenter.MINIMUM_LENGTH;
- int intDataLength = dataLength / 4;
- expData = new int[intDataLength];
- for (int i = 0; i < intDataLength; i++) {
- expData[i] = data.getInt();
- }
-
- /* Read the padding, if any */
- int paddingLength = ((this.getLengthU() % MULTIPLE_OF_EIGHT) == 0) ? 0 : (MULTIPLE_OF_EIGHT - (this
- .getLengthU() % MULTIPLE_OF_EIGHT));
- data.position(data.position() + paddingLength);
-
- }
-
- /**
- * write OFPTableFeaturePropExperimenter to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.putInt(this.expId);
- data.putInt(this.expType);
- for (int value : expData) {
- data.putInt(value);
- }
-
- /* Add padding if structure is not 8 byte aligned */
- int paddingLength = ((this.getLengthU() % MULTIPLE_OF_EIGHT) == 0) ? 0 : (MULTIPLE_OF_EIGHT - (this
- .getLengthU() % MULTIPLE_OF_EIGHT));
- byte[] padding = new byte[paddingLength];
- data.put(padding);
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 746;
- int result = super.hashCode();
- result = prime * result + expId;
- result = prime * result + expType;
- result = prime * result + Arrays.hashCode(expData);
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPTableFeaturePropExperimenter)) {
- return false;
- }
- OFPTableFeaturePropExperimenter other = (OFPTableFeaturePropExperimenter) obj;
- if (this.expId != other.expId) {
- return false;
- }
- if (this.expType != other.expType) {
- return false;
- }
- if (!Arrays.equals(expData, other.expData)) {
- return false;
- }
- return true;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-/**
- * Class defines OFPTFPT_EXPERIMENTER_MISS.
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropExperimenterMiss extends OFPTableFeaturePropExperimenter {
-
- /**
- * constructor
- */
- public OFPTableFeaturePropExperimenterMiss() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.EXPERIMENTER_MISS);
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents struct ofp_table_feature_prop_header that is common to all table
- * feature properties.
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropHeader {
- public static final short MINIMUM_LENGTH = 4;
-
- private OFPTableFeaturePropType type;
- private short length;
-
- /**
- * Match size should be multiple of eight, so padding will be done based on
- * length of match.
- */
- protected static final int MULTIPLE_OF_EIGHT = 8;
-
- /**
- * get the length of TableFeatureProp structure
- *
- * @return
- */
- public short getLength() {
- return length;
- }
-
- /**
- * set the length of TableFeatureProp structure
- *
- * @param length
- */
- public void setLength(short length) {
- this.length = length;
- }
-
- /**
- * get the unsigned length of TableFeatureProp structure
- *
- * @return
- */
- public int getLengthU() {
- return U16.f(length);
- }
-
- /**
- * get the OFPTableFeaturePropType
- *
- * @return
- */
- public OFPTableFeaturePropType getOFTableFeaturePropType() {
- return type;
- }
-
- /**
- * set the OFPTableFeaturePropType
- *
- * @param type
- */
- public void setOFTableFeaturePropType(OFPTableFeaturePropType type) {
- this.type = type;
- }
-
- /**
- * read OFPTableFeaturePropHeader object state from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- this.type = OFPTableFeaturePropType.valueOf(data.getShort());
- this.length = data.getShort();
- }
-
- /**
- * write OFPTableFeaturePropHeader object state to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- data.putShort(type.getTypeValue());
- data.putShort(this.length);
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 751;
- int result = 1;
- result = prime * result + length;
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPTableFeaturePropHeader)) {
- return false;
- }
- OFPTableFeaturePropHeader other = (OFPTableFeaturePropHeader) obj;
- if (length != other.length) {
- return false;
- }
- if (type == null) {
- if (other.type != null) {
- return false;
- }
- } else if (!type.equals(other.type)) {
- return false;
- }
- return true;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.factory.OFPInstructionFactory;
-import org.openflow.codec.protocol.factory.OFPInstructionFactoryAware;
-import org.openflow.codec.protocol.instruction.OFPInstruction;
-import org.openflow.codec.util.U16;
-
-/**
- * Represents struct ofp_table_feature_prop_instructions
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropInstructions extends OFPTableFeaturePropHeader implements OFPInstructionFactoryAware {
- private List<OFPInstruction> instructionIds;
- private OFPInstructionFactory instructionFactory;
-
- /**
- * constructor
- */
- public OFPTableFeaturePropInstructions() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.INSTRUCTIONS);
- super.setLength(MINIMUM_LENGTH);
- setInstructionIds(new ArrayList<OFPInstruction>());
- }
-
- /**
- * get list of instruction id
- *
- * @return
- */
- public List<OFPInstruction> getInstructionIds() {
- return instructionIds;
- }
-
- /**
- * set list of instruction id
- *
- * @param instructionIds
- */
- public void setInstructionIds(List<OFPInstruction> instructionIds) {
- this.instructionIds = instructionIds;
- updateLength();
- }
-
- /**
- * update the length
- *
- * @return
- */
- private void updateLength() {
- int length = this.getLength();
- for (OFPInstruction ofInstruction : instructionIds) {
- length += ofInstruction.getLengthU();
- }
- this.setLength((short) length);
-
- }
-
- /**
- * read OFPTableFeaturePropInstructions from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- int instructionIdsLength = U16.f(this.getLength()) - MINIMUM_LENGTH;
- if (null == instructionFactory) {
- throw new RuntimeException("OFPInstructionFactory is not set.");
- }
- instructionIds = instructionFactory.parseInstructions(data, instructionIdsLength);
- /* Read the padding, if any */
- int paddingLength = ((this.getLength() % MULTIPLE_OF_EIGHT) == 0) ? 0
- : (MULTIPLE_OF_EIGHT - (this.getLength() % MULTIPLE_OF_EIGHT));
- data.position(data.position() + paddingLength);
-
- }
-
- /**
- * write OFPTableFeaturePropInstructions to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- // write instruction ids
- for (OFPInstruction ofInstruction : instructionIds) {
- ofInstruction.writeTo(data);
- }
-
- /* Add padding if structure is not 8 byte aligned */
- int paddingLength = ((this.getLength() % MULTIPLE_OF_EIGHT) == 0) ? 0
- : (MULTIPLE_OF_EIGHT - (this.getLength() % MULTIPLE_OF_EIGHT));
- byte[] padding = new byte[paddingLength];
- data.put(padding);
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 742;
- int result = super.hashCode();
- result = prime * result + instructionIds.hashCode();
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPTableFeaturePropInstructions)) {
- return false;
- }
- OFPTableFeaturePropInstructions other = (OFPTableFeaturePropInstructions) obj;
- if (!this.instructionIds.equals(other.instructionIds)) {
- return false;
- }
- return true;
- }
-
- @Override
- public void setInstructionFactory(OFPInstructionFactory instructionFactory) {
- this.instructionFactory = instructionFactory;
-
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-/**
- * Class defines OFPTFPT_INSTRUCTIONS_MISS type
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropInstructionsMiss extends OFPTableFeaturePropInstructions {
-
- /**
- * constructor
- */
- public OFPTableFeaturePropInstructionsMiss() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.INSTRUCTIONS_MISS);
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-/**
- * Class defines OFPTFPT_MATCH type
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropMatch extends OFPTableFeaturePropOXM {
-
- /**
- * constructor
- */
- public OFPTableFeaturePropMatch() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.MATCH);
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-import java.util.Arrays;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/**
- * correspond to struct ofp_table_feature_prop_next_tables
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropNextTables extends OFPTableFeaturePropHeader {
- private byte[] nextTableIds = new byte[0];
-
- /**
- * constructor
- */
- public OFPTableFeaturePropNextTables() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.NEXT_TABLES);
- super.setLength(MINIMUM_LENGTH);
- }
-
- /**
- *
- * @return
- */
- public byte[] getNextTableIds() {
- return nextTableIds;
- }
-
- /**
- *
- * @param nextTableIds
- */
- public void setNextTableIds(byte[] nextTableIds) {
- this.nextTableIds = nextTableIds;
- updateLength();
- }
-
- /**
- * update the length
- *
- */
- private void updateLength() {
- int length = this.getLength() + nextTableIds.length;
- this.setLength((short) length);
-
- }
-
- /**
- * read OFPTableFeaturePropNextTables from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- int idDataLength = this.getLengthU() - OFPTableFeaturePropHeader.MINIMUM_LENGTH;
- nextTableIds = new byte[idDataLength];
- data.get(nextTableIds);
-
- /*
- * Read the padding, if any and move the data pointer position to next
- * element
- */
- int paddingLength = ((this.getLengthU() % MULTIPLE_OF_EIGHT) == 0) ? 0 : (MULTIPLE_OF_EIGHT - (this
- .getLengthU() % MULTIPLE_OF_EIGHT));
- data.position(data.position() + paddingLength);
-
- }
-
- /**
- * write OFPTableFeaturePropNextTables to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- data.put(nextTableIds);
-
- /* Add padding if structure is not 8 byte aligned */
- int paddingLength = ((this.getLengthU() % MULTIPLE_OF_EIGHT) == 0) ? 0 : (MULTIPLE_OF_EIGHT - (this
- .getLengthU() % MULTIPLE_OF_EIGHT));
- byte[] padding = new byte[paddingLength];
- data.put(padding);
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 743;
- int result = super.hashCode();
- result = prime * result + Arrays.hashCode(nextTableIds);
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPTableFeaturePropNextTables)) {
- return false;
- }
- OFPTableFeaturePropNextTables other = (OFPTableFeaturePropNextTables) obj;
- if (!Arrays.equals(nextTableIds, other.nextTableIds)) {
- return false;
- }
- return true;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-/**
- * class to define OFPTFPT_NEXT_TABLES_MISS
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropNextTablesMiss extends OFPTableFeaturePropNextTables {
-
- /**
- * constructor
- */
- public OFPTableFeaturePropNextTablesMiss() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.NEXT_TABLES_MISS);
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OXMField;
-
-/**
- * Represents struct ofp_table_feature_prop_oxm
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropOXM extends OFPTableFeaturePropHeader {
- private List<OXMField> oxmIds = new ArrayList<OXMField>();
-
- /**
- * constructor
- */
- public OFPTableFeaturePropOXM() {
- super.setLength(MINIMUM_LENGTH);
- }
-
- /**
- *
- * @return
- */
- public List<OXMField> getOXMIds() {
- return oxmIds;
- }
-
- /**
- *
- * @param oxmIds
- */
- public void setOXMIds(List<OXMField> oxmIds) {
- this.oxmIds = oxmIds;
- updateLength();
- }
-
- /**
- * update the length
- *
- */
- private void updateLength() {
- int length = this.getLength() + OXMField.getTotalLength(oxmIds);
- this.setLength((short) length);
-
- }
-
- /**
- * read OFPTableFeaturePropOXM from buffer
- *
- * @param data
- */
- public void readFrom(IDataBuffer data) {
- super.readFrom(data);
- int idDataLength = this.getLengthU() - OFPTableFeaturePropHeader.MINIMUM_LENGTH;
- oxmIds = OXMField.readOXMFieldHeader(data, idDataLength);
- /* Read the padding, if any */
- int paddingLength = ((this.getLengthU() % MULTIPLE_OF_EIGHT) == 0) ? 0 : (MULTIPLE_OF_EIGHT - (this
- .getLengthU() % MULTIPLE_OF_EIGHT));
- data.position(data.position() + paddingLength);
-
- }
-
- /**
- * write OFPTableFeaturePropOXM to buffer
- *
- * @param data
- */
- public void writeTo(IDataBuffer data) {
- super.writeTo(data);
- OXMField.writeOXMFieldHeader(data, oxmIds);
-
- /* Add padding if structure is not 8 byte aligned */
- int paddingLength = ((this.getLengthU() % MULTIPLE_OF_EIGHT) == 0) ? 0 : (MULTIPLE_OF_EIGHT - (this
- .getLengthU() % MULTIPLE_OF_EIGHT));
- byte[] padding = new byte[paddingLength];
- data.put(padding);
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 745;
- int result = super.hashCode();
- result = prime * result + oxmIds.hashCode();
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPTableFeaturePropOXM)) {
- return false;
- }
- OFPTableFeaturePropOXM other = (OFPTableFeaturePropOXM) obj;
- if (!oxmIds.equals(other.oxmIds)) {
- return false;
- }
- return true;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.openflow.codec.protocol.Instantiable;
-import org.openflow.codec.util.U16;
-
-public enum OFPTableFeaturePropType {
-
- INSTRUCTIONS(0, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropInstructions();
- }
- }), INSTRUCTIONS_MISS(1, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropInstructionsMiss();
- }
- }), NEXT_TABLES(2, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropNextTables();
- }
- }), NEXT_TABLES_MISS(3, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropNextTablesMiss();
- }
- }), WRITE_ACTIONS(4, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropWriteActions();
- }
- }), WRITE_ACTIONS_MISS(5, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropWriteActionsMiss();
- }
- }), APPLY_ACTIONS(6, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropApplyActions();
- }
- }), APPLY_ACTIONS_MISS(7, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropApplyActionsMiss();
- }
- }), MATCH(8, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropMatch();
- }
- }), WILDCARDS(10, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropWildcards();
- }
- }), WRITE_SETFIELD(12, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropWriteSetField();
- }
- }), WRITE_SETFIELD_MISS(13, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropWriteSetFieldMiss();
- }
- }), APPLY_SETFIELD(14, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropApplySetField();
- }
- }), APPLY_SETFIELD_MISS(15, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropApplySetFieldMiss();
- }
- }),
-
- EXPERIMENTER(0xFFFE, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropExperimenter();
- }
- }),
-
- EXPERIMENTER_MISS(0xFFFF, new Instantiable<OFPTableFeaturePropHeader>() {
- @Override
- public OFPTableFeaturePropHeader instantiate() {
- return new OFPTableFeaturePropExperimenterMiss();
- }
- });
-
- private static Map<Integer, OFPTableFeaturePropType> mapping;
-
- private short type;
-
- private Instantiable<OFPTableFeaturePropHeader> instantiable;
-
- /**
- *
- * @param type
- */
- OFPTableFeaturePropType(int type, Instantiable<OFPTableFeaturePropHeader> instantiable) {
- this.setTypeValue((short) type);
- OFPTableFeaturePropType.addMapping(type, this);
- this.instantiable = instantiable;
- }
-
- /**
- * add mapping to store
- *
- * @param type
- * @param TableFeatureType
- */
- private static void addMapping(int type, OFPTableFeaturePropType TableFeatureType) {
- if (null == mapping) {
- mapping = new HashMap<Integer, OFPTableFeaturePropType>();
- }
- mapping.put(type, TableFeatureType);
- }
-
- /**
- * get OFTableFeatureType correspond to value type
- *
- * @param type
- * @return OFTableFeatureType
- */
- public static OFPTableFeaturePropType valueOf(short type) {
- return mapping.get(U16.f(type));
- }
-
- /**
- * get TableFeatureProp type value
- *
- * @return
- */
- public short getTypeValue() {
- return type;
- }
-
- /**
- * set TableFeatureProp type value
- *
- * @param type
- */
- public void setTypeValue(short type) {
- this.type = type;
- }
-
- /**
- * Returns a new instance of the OFPTableFeaturePropHeader represented by
- * this OFPTableFeaturePropType
- *
- * @return the new object
- */
- public OFPTableFeaturePropHeader newInstance() {
- return instantiable.instantiate();
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-/**
- * Class defines OFPTFPT_WILDCARDS type
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropWildcards extends OFPTableFeaturePropOXM {
-
- /**
- * constructor
- */
- public OFPTableFeaturePropWildcards() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.WILDCARDS);
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-/**
- * Class defines OFPTFPT_WRITE_ACTIONS type
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropWriteActions extends OFPTableFeaturePropActions {
-
- /**
- * constructor
- */
- public OFPTableFeaturePropWriteActions() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.WRITE_ACTIONS);
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-/**
- * Class defines OFPTFPT_WRITE_ACTIONS_MISS type
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropWriteActionsMiss extends OFPTableFeaturePropActions {
-
- /**
- * constructor
- */
- public OFPTableFeaturePropWriteActionsMiss() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.WRITE_ACTIONS_MISS);
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-/**
- * Class defines OFPTFPT_WRITE_SETFIELD type
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropWriteSetField extends OFPTableFeaturePropOXM {
-
- /**
- * constructor
- */
- public OFPTableFeaturePropWriteSetField() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.WRITE_SETFIELD);
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.statistics.table;
-
-/**
- * Class defines OFPTFPT_WRITE_SETFIELD_MISS type
- *
- * @author AnilGujele
- *
- */
-public class OFPTableFeaturePropWriteSetFieldMiss extends OFPTableFeaturePropOXM {
-
- /**
- * constructor
- */
- public OFPTableFeaturePropWriteSetFieldMiss() {
- super.setOFTableFeaturePropType(OFPTableFeaturePropType.WRITE_SETFIELD_MISS);
- }
-
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-import java.math.BigInteger;
-
-public class HexString {
- /**
- * Convert a string of bytes to a ':' separated hex string
- *
- * @param bytes
- * @return "0f:ca:fe:de:ad:be:ef"
- */
- public static String toHexString(byte[] bytes) {
- int i;
- String ret = "";
- String tmp;
- for (i = 0; i < bytes.length; i++) {
- if (i > 0)
- ret += ":";
- tmp = Integer.toHexString(U8.f(bytes[i]));
- if (tmp.length() == 1)
- ret += "0";
- ret += tmp;
- }
- return ret;
- }
-
- public static String toHexString(long val) {
- char arr[] = Long.toHexString(val).toCharArray();
- String ret = "";
- // prepend the right number of leading zeros
- int i = 0;
- for (; i < (16 - arr.length); i++) {
- ret += "0";
- if ((i % 2) == 1)
- ret += ":";
- }
- for (int j = 0; j < arr.length; j++) {
- ret += arr[j];
- if ((((i + j) % 2) == 1) && (j < (arr.length - 1)))
- ret += ":";
- }
- return ret;
- }
-
- /**
- * Convert a string of hex values into a string of bytes
- *
- * @param values
- * "0f:ca:fe:de:ad:be:ef"
- * @return [15, 5 ,2, 5, 17]
- */
-
- public static byte[] fromHexString(String values) {
- String[] octets = values.split(":");
- byte[] ret = new byte[octets.length];
- int i;
-
- for (i = 0; i < octets.length; i++)
- ret[i] = Integer.valueOf(octets[i], 16).byteValue();
- return ret;
- }
-
- public static long toLong(String values) {
- long value = new BigInteger(values.replaceAll(":", ""), 16).longValue();
- return value;
- }
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-import java.util.LinkedHashMap;
-
-public class LRULinkedHashMap<K, V> extends LinkedHashMap<K, V> {
- private static final long serialVersionUID = -2964986094089626647L;
- protected int maximumCapacity;
-
- public LRULinkedHashMap(int initialCapacity, int maximumCapacity) {
- super(initialCapacity, 0.75f, true);
- this.maximumCapacity = maximumCapacity;
- }
-
- public LRULinkedHashMap(int maximumCapacity) {
- super(16, 0.75f, true);
- this.maximumCapacity = maximumCapacity;
- }
-
- @Override
- protected boolean removeEldestEntry(java.util.Map.Entry<K, V> eldest) {
- if (this.size() > maximumCapacity)
- return true;
- return false;
- }
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-import java.util.Map;
-
-import org.openflow.codec.protocol.OFBMatchFields;
-import org.openflow.codec.protocol.OFPMatch;
-import org.openflow.codec.protocol.OXMField;
-
-/**
- * utility class for match field
- *
- * @author AnilGujele
- *
- */
-
-public class MatchUtil {
-
- // ofp_vlan_id constant
- private static int OFPVID_NONE = 0x0000; /* No VLAN id was set. */
- private static int OFPVID_PRESENT = 0x1000; /*
- * Bit that indicate that a VLAN
- * id is set
- */
-
- // Ethernet type constant
- private static final int ETH_TYPE_IPV4 = 0x0800;
- private static final int ETH_TYPE_IPV6 = 0x86dd;
- private static final int ETH_TYPE_MPLS_UNICAST = 0x8847;
- private static final int ETH_TYPE_MPLS_MULITCAST = 0x8848;
- private static final int ETH_TYPE_ISID = 0x88E7;
- private static final int ETH_TYPE_ARP = 0x0806;
- // protocol type constant
- private static final short IP_PROTO_TCP = 6;
- private static final short IP_PROTO_UDP = 17;
- private static final short IP_PROTO_SCTP = 132;
- private static final short IP_PROTO_ICMP = 1;
- private static final short IP_PROTO_ICMPV6 = 58;
- // ICMPV6 type constant
- private static final short ICMPV6_TYPE_NDP_NS = 135;
- private static final short ICMPV6_TYPE_NDP_NA = 136;
-
- /**
- * to check if prerequisite is matching for all the field
- *
- * @param field
- * @param map
- * @return
- */
- public static boolean hasPrerequisite(OFPMatch match) {
- Map<String, OXMField> map = match.getMatchFieldMap();
- boolean result = true;
- for (Map.Entry<String, OXMField> entry : map.entrySet()) {
- OFBMatchFields field = entry.getValue().getMatchField();
- OXMField value;
- switch (field.getValue()) {
- case 1: // OXM_OF_IN_PHY_PORT
- result = (null != map.get(OFBMatchFields.IN_PORT.name()));
- break;
- case 7: // OXM_OF_VLAN_PCP
- value = map.get(OFBMatchFields.VLAN_VID.name());
- result = (null != value) && (U16.f(getShort(value.getData())) != MatchUtil.OFPVID_NONE);
-
- case 8: // OXM_OF_IP_DSCP
- case 9: // OXM_OF_IP_ECN
- case 10: // OXM_OF_IP_PROTO
- value = map.get(OFBMatchFields.ETH_TYPE.name());
- boolean isMatched = (null != value) && (U16.f(getShort(value.getData())) == MatchUtil.ETH_TYPE_IPV4);
- result = isMatched
- || ((null != value) && (U16.f(getShort(value.getData())) == MatchUtil.ETH_TYPE_IPV6));
- break;
- case 11: // OXM_OF_IPV4_SRC
- case 12: // OXM_OF_IPV4_DST
- value = map.get(OFBMatchFields.ETH_TYPE.name());
- result = (null != value) && (U16.f(getShort(value.getData())) == MatchUtil.ETH_TYPE_IPV4);
- break;
- case 13: // OXM_OF_TCP_SRC
- case 14: // OXM_OF_TCP_DST
- value = map.get(OFBMatchFields.IP_PROTO.name());
- result = (null != value) && (U8.f(value.getData()[0]) == MatchUtil.IP_PROTO_TCP);
- break;
- case 15: // OXM_OF_UDP_SRC
- case 16: // OXM_OF_UDP_DST
- value = map.get(OFBMatchFields.IP_PROTO.name());
- result = (null != value) && (U8.f(value.getData()[0]) == MatchUtil.IP_PROTO_UDP);
- break;
- case 17: // OXM_OF_SCTP_SRC
- case 18: // OXM_OF_SCTP_DST
- value = map.get(OFBMatchFields.IP_PROTO.name());
- result = (null != value) && (U8.f(value.getData()[0]) == MatchUtil.IP_PROTO_SCTP);
- break;
- case 19: // OXM_OF_ICMPV4_TYPE
- case 20: // OXM_OF_ICMPV4_CODE
- value = map.get(OFBMatchFields.IP_PROTO.name());
- result = (null != value) && (U8.f(value.getData()[0]) == MatchUtil.IP_PROTO_ICMP);
- break;
- case 21: // OXM_OF_ARP_OP
- case 22: // OXM_OF_ARP_SPA
- case 23: // OXM_OF_ARP_TPA
- case 24: // OXM_OF_ARP_SHA
- case 25: // OXM_OF_ARP_THA
- value = map.get(OFBMatchFields.ETH_TYPE.name());
- result = (null != value) && (U16.f(getShort(value.getData())) == MatchUtil.ETH_TYPE_ARP);
- break;
-
- case 26: // OXM_OF_IPV6_SRC
- case 27: // OXM_OF_IPV6_DST
- case 28: // OXM_OF_IPV6_FLABEL
- case 39: // OXM_OF_IPV6_EXTHDR
- value = map.get(OFBMatchFields.ETH_TYPE.name());
- result = (null != value) && (U16.f(getShort(value.getData())) == MatchUtil.ETH_TYPE_IPV6);
- break;
- case 29: // OXM_OF_ICMPV6_TYPE
- case 30: // OXM_OF_ICMPV6_CODE
- value = map.get(OFBMatchFields.IP_PROTO.name());
- result = (null != value) && (U8.f(value.getData()[0]) == MatchUtil.IP_PROTO_ICMPV6);
- break;
- case 31: // OXM_OF_IPV6_ND_TARGET
- value = map.get(OFBMatchFields.ICMPV6_TYPE.name());
- boolean success = (null != value) && (U8.f(value.getData()[0]) == MatchUtil.ICMPV6_TYPE_NDP_NS);
- result = success || ((null != value) && (U8.f(value.getData()[0]) == MatchUtil.ICMPV6_TYPE_NDP_NA));
- break;
- case 32: // OXM_OF_IPV6_ND_SLL
- value = map.get(OFBMatchFields.ICMPV6_TYPE.name());
- result = (null != value) && (U8.f(value.getData()[0]) == MatchUtil.ICMPV6_TYPE_NDP_NS);
- break;
- case 33: // OXM_OF_IPV6_ND_TLL
- value = map.get(OFBMatchFields.ICMPV6_TYPE.name());
- result = (null != value) && (U8.f(value.getData()[0]) == MatchUtil.ICMPV6_TYPE_NDP_NA);
- break;
- case 34: // OXM_OF_MPLS_LABEL
- case 35: // OXM_OF_MPLS_TC
- case 36: // OXM_OF_MPLS_BOS
- value = map.get(OFBMatchFields.ETH_TYPE.name());
- boolean isSuccess = (null != value)
- && (U16.f(getShort(value.getData())) == MatchUtil.ETH_TYPE_MPLS_UNICAST);
- result = isSuccess
- || ((null != value) && (U16.f(getShort(value.getData())) == MatchUtil.ETH_TYPE_MPLS_MULITCAST));
- break;
- case 37: // OXM_OF_PBB_ISID
- value = map.get(OFBMatchFields.ETH_TYPE.name());
- result = (null != value) && (U16.f(getShort(value.getData())) == MatchUtil.ETH_TYPE_ISID);
- break;
- default:
- result = true;
- break;
-
- }
- if (!result) {
- break; // break for loop
- }
- }
- return result;
- }
-
- /**
- * get short value from byte array
- *
- * @param byteArray
- * @return
- */
- public static short getShort(byte[] byteArray) {
- return (short) ((byteArray[1] << 8) | (byteArray[0] & 0xff));
- }
-
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-import java.util.Arrays;
-
-import org.openflow.codec.io.IDataBuffer;
-
-public class StringByteSerializer {
- public static String readFrom(IDataBuffer data, int length) {
- byte[] stringBytes = new byte[length];
- data.get(stringBytes);
- // find the first index of 0
- int index = 0;
- for (byte b : stringBytes) {
- if (0 == b)
- break;
- ++index;
- }
- return new String(Arrays.copyOf(stringBytes, index), Charset.forName("ascii"));
- }
-
- public static void writeTo(IDataBuffer data, int length, String value) {
- try {
- byte[] name = value.getBytes("ASCII");
- if (name.length < length) {
- data.put(name);
- for (int i = name.length; i < length; ++i) {
- data.put((byte) 0);
- }
- } else {
- int end = length - 1;
- for (int i = 0; i < end; i++)
- data.put(name[i]);
- data.put((byte) 0);
- }
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
-
- }
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-public class U16 {
- public static int f(short i) {
- return (int) i & 0xffff;
- }
-
- public static short t(int l) {
- return (short) l;
- }
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-public class U32 {
- public static long f(int i) {
- return (long) i & 0xffffffffL;
- }
-
- public static int t(long l) {
- return (int) l;
- }
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-import java.math.BigInteger;
-
-public class U64 {
- public static BigInteger f(long i) {
- return new BigInteger(Long.toBinaryString(i), 2);
- }
-
- public static long t(BigInteger l) {
- return l.longValue();
- }
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-public class U8 {
- public static short f(byte i) {
- return (short) ((short) i & 0xff);
- }
-
- public static byte t(short l) {
- return (byte) l;
- }
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-import java.math.BigInteger;
-
-import org.openflow.codec.io.IDataBuffer;
-
-/*****
- * A util library class for dealing with the lack of unsigned datatypes in Java
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-
-public class Unsigned {
- /**
- * Get an unsigned byte from the current position of the IDataBuffer
- *
- * @param bb
- * IDataBuffer to get the byte from
- * @return an unsigned byte contained in a short
- */
- public static short getUnsignedByte(IDataBuffer bb) {
- return ((short) (bb.get() & (short) 0xff));
- }
-
- /**
- * Get an unsigned byte from the specified offset in the IDataBuffer
- *
- * @param bb
- * IDataBuffer to get the byte from
- * @param offset
- * the offset to get the byte from
- * @return an unsigned byte contained in a short
- */
- public static short getUnsignedByte(IDataBuffer bb, int offset) {
- return ((short) (bb.get(offset) & (short) 0xff));
- }
-
- /**
- * Put an unsigned byte into the specified IDataBuffer at the current
- * position
- *
- * @param bb
- * IDataBuffer to put the byte into
- * @param v
- * the short containing the unsigned byte
- */
- public static void putUnsignedByte(IDataBuffer bb, short v) {
- bb.put((byte) (v & 0xff));
- }
-
- /**
- * Put an unsigned byte into the specified IDataBuffer at the specified
- * offset
- *
- * @param bb
- * IDataBuffer to put the byte into
- * @param v
- * the short containing the unsigned byte
- * @param offset
- * the offset to insert the unsigned byte at
- */
- public static void putUnsignedByte(IDataBuffer bb, short v, int offset) {
- bb.put(offset, (byte) (v & 0xff));
- }
-
- /**
- * Get an unsigned short from the current position of the IDataBuffer
- *
- * @param bb
- * IDataBuffer to get the byte from
- * @return an unsigned short contained in a int
- */
- public static int getUnsignedShort(IDataBuffer bb) {
- return (bb.getShort() & 0xffff);
- }
-
- /**
- * Get an unsigned short from the specified offset in the IDataBuffer
- *
- * @param bb
- * IDataBuffer to get the short from
- * @param offset
- * the offset to get the short from
- * @return an unsigned short contained in a int
- */
- public static int getUnsignedShort(IDataBuffer bb, int offset) {
- return (bb.getShort(offset) & 0xffff);
- }
-
- /**
- * Put an unsigned short into the specified IDataBuffer at the current
- * position
- *
- * @param bb
- * IDataBuffer to put the short into
- * @param v
- * the int containing the unsigned short
- */
- public static void putUnsignedShort(IDataBuffer bb, int v) {
- bb.putShort((short) (v & 0xffff));
- }
-
- /**
- * Put an unsigned short into the specified IDataBuffer at the specified
- * offset
- *
- * @param bb
- * IDataBuffer to put the short into
- * @param v
- * the int containing the unsigned short
- * @param offset
- * the offset to insert the unsigned short at
- */
- public static void putUnsignedShort(IDataBuffer bb, int v, int offset) {
- bb.putShort(offset, (short) (v & 0xffff));
- }
-
- /**
- * Get an unsigned int from the current position of the IDataBuffer
- *
- * @param bb
- * IDataBuffer to get the int from
- * @return an unsigned int contained in a long
- */
- public static long getUnsignedInt(IDataBuffer bb) {
- return ((long) bb.getInt() & 0xffffffffL);
- }
-
- /**
- * Get an unsigned int from the specified offset in the IDataBuffer
- *
- * @param bb
- * IDataBuffer to get the int from
- * @param offset
- * the offset to get the int from
- * @return an unsigned int contained in a long
- */
- public static long getUnsignedInt(IDataBuffer bb, int offset) {
- return ((long) bb.getInt(offset) & 0xffffffffL);
- }
-
- /**
- * Put an unsigned int into the specified IDataBuffer at the current
- * position
- *
- * @param bb
- * IDataBuffer to put the int into
- * @param v
- * the long containing the unsigned int
- */
- public static void putUnsignedInt(IDataBuffer bb, long v) {
- bb.putInt((int) (v & 0xffffffffL));
- }
-
- /**
- * Put an unsigned int into the specified IDataBuffer at the specified
- * offset
- *
- * @param bb
- * IDataBuffer to put the int into
- * @param v
- * the long containing the unsigned int
- * @param offset
- * the offset to insert the unsigned int at
- */
- public static void putUnsignedInt(IDataBuffer bb, long v, int offset) {
- bb.putInt(offset, (int) (v & 0xffffffffL));
- }
-
- /**
- * Get an unsigned long from the current position of the IDataBuffer
- *
- * @param bb
- * IDataBuffer to get the long from
- * @return an unsigned long contained in a BigInteger
- */
- public static BigInteger getUnsignedLong(IDataBuffer bb) {
- byte[] v = new byte[8];
- for (int i = 0; i < 8; ++i) {
- v[i] = bb.get(i);
- }
- return new BigInteger(1, v);
- }
-
- /**
- * Get an unsigned long from the specified offset in the IDataBuffer
- *
- * @param bb
- * IDataBuffer to get the long from
- * @param offset
- * the offset to get the long from
- * @return an unsigned long contained in a BigInteger
- */
- public static BigInteger getUnsignedLong(IDataBuffer bb, int offset) {
- byte[] v = new byte[8];
- for (int i = 0; i < 8; ++i) {
- v[i] = bb.get(offset + i);
- }
- return new BigInteger(1, v);
- }
-
- /**
- * Put an unsigned long into the specified IDataBuffer at the current
- * position
- *
- * @param bb
- * IDataBuffer to put the long into
- * @param v
- * the BigInteger containing the unsigned long
- */
- public static void putUnsignedLong(IDataBuffer bb, BigInteger v) {
- bb.putLong(v.longValue());
- }
-
- /**
- * Put an unsigned long into the specified IDataBuffer at the specified
- * offset
- *
- * @param bb
- * IDataBuffer to put the long into
- * @param v
- * the BigInteger containing the unsigned long
- * @param offset
- * the offset to insert the unsigned long at
- */
- public static void putUnsignedLong(IDataBuffer bb, BigInteger v, int offset) {
- bb.putLong(offset, v.longValue());
- }
-}
+++ /dev/null
-package org.openflow.codec.io;
-
-import org.openflow.codec.io.OFMessageAsyncStream;
-import org.openflow.codec.protocol.*;
-import org.openflow.codec.protocol.factory.OFPBasicFactoryImpl;
-
-import java.util.*;
-import java.nio.channels.*;
-import java.net.InetSocketAddress;
-
-import org.junit.Assert;
-
-import org.junit.Test;
-
-/**
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- *
- */
-public class OFMessageAsyncStreamTest {
- @Test
- public void testMarshalling() throws Exception {
- OFPMessage h = new OFPHello();
-
- ServerSocketChannel serverSC = ServerSocketChannel.open();
- serverSC.socket().bind(new java.net.InetSocketAddress(0));
- serverSC.configureBlocking(false);
-
- SocketChannel client = SocketChannel.open(new InetSocketAddress("localhost", serverSC.socket().getLocalPort()));
- SocketChannel server = serverSC.accept();
- OFMessageAsyncStream clientStream = new OFMessageAsyncStream(client, new OFPBasicFactoryImpl());
- OFMessageAsyncStream serverStream = new OFMessageAsyncStream(server, new OFPBasicFactoryImpl());
-
- clientStream.write(h);
- while (clientStream.needsFlush()) {
- clientStream.flush();
- }
- List<OFPMessage> l = serverStream.read();
- Assert.assertEquals(l.size(), 1);
- OFPMessage m = l.get(0);
- Assert.assertEquals(m.getLength(), h.getLength());
- Assert.assertEquals(m.getVersion(), h.getVersion());
- Assert.assertEquals(m.getType(), h.getType());
- Assert.assertEquals(m.getType(), h.getType());
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPBarrierReply;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.util.OFTestCase;
-
-public class OFPBarrierReplyTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFPBarrierReply msg = (OFPBarrierReply) messageFactory.getMessage(OFPType.BARRIER_REPLY);
- IDataBuffer bb = DataBuffers.allocate(1024);
- bb.clear();
- msg.writeTo(bb);
- bb.flip();
- msg.readFrom(bb);
- TestCase.assertEquals(OFPType.BARRIER_REPLY, msg.getType());
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPBarrierRequest;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.util.OFTestCase;
-
-public class OFPBarrierRequestTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFPBarrierRequest msg = (OFPBarrierRequest) messageFactory.getMessage(OFPType.BARRIER_REQUEST);
- IDataBuffer bb = DataBuffers.allocate(1024);
- bb.clear();
- msg.writeTo(bb);
- bb.flip();
- msg.readFrom(bb);
- TestCase.assertEquals(OFPType.BARRIER_REQUEST, msg.getType());
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPMessage;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.protocol.factory.OFPBasicFactoryImpl;
-import org.openflow.codec.util.U16;
-
-public class OFPBasicFactoryImplTest extends TestCase {
- public void testCreateAndParse() {
- OFPBasicFactoryImpl factory = new OFPBasicFactoryImpl();
- OFPMessage m = factory.getMessage(OFPType.HELLO);
- m.setVersion((byte) 1);
- m.setType(OFPType.ECHO_REQUEST);
- m.setLength(U16.t(8));
- m.setXid(0xdeadbeef);
- IDataBuffer bb = DataBuffers.allocate(1024);
- m.writeTo(bb);
- bb.flip();
- bb.limit(bb.limit() - 1);
- TestCase.assertEquals(0, factory.parseMessages(bb).size());
- bb.limit(bb.limit() + 1);
- List<OFPMessage> messages = factory.parseMessages(bb);
- TestCase.assertEquals(1, messages.size());
- TestCase.assertTrue(messages.get(0).getType() == OFPType.ECHO_REQUEST);
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPErrorMsg;
-import org.openflow.codec.protocol.OFPHello;
-import org.openflow.codec.protocol.OFPMessage;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.protocol.OFPErrorMsg.OFErrorType;
-import org.openflow.codec.protocol.OFPErrorMsg.OFHelloFailedCode;
-import org.openflow.codec.protocol.factory.OFPBasicFactoryImpl;
-import org.openflow.codec.protocol.factory.OFPMessageFactory;
-import org.openflow.codec.util.OFTestCase;
-
-public class OFPErrorMsgTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFPErrorMsg msg = (OFPErrorMsg) messageFactory.getMessage(OFPType.ERROR);
- msg.setMessageFactory(messageFactory);
- msg.setErrorType((short) OFErrorType.OFPET_HELLO_FAILED.ordinal());
- msg.setErrorCode((short) OFHelloFailedCode.OFPHFC_INCOMPATIBLE.ordinal());
- IDataBuffer bb = DataBuffers.allocate(1024);
- bb.clear();
- msg.writeTo(bb);
- bb.flip();
- msg.readFrom(bb);
- TestCase.assertEquals((short) OFErrorType.OFPET_HELLO_FAILED.ordinal(), msg.getErrorType());
- TestCase.assertEquals((short) OFHelloFailedCode.OFPHFC_INCOMPATIBLE.ordinal(), msg.getErrorType());
- TestCase.assertNull(msg.getOffendingMsg(bb));
-
- msg.setOffendingMsg(new OFPHello(), bb);
- bb.clear();
- msg.writeTo(bb);
- bb.flip();
- msg.readFrom(bb);
- TestCase.assertEquals((short) OFErrorType.OFPET_HELLO_FAILED.ordinal(), msg.getErrorType());
- TestCase.assertEquals((short) OFHelloFailedCode.OFPHFC_INCOMPATIBLE.ordinal(), msg.getErrorType());
- TestCase.assertNotNull(msg.getOffendingMsg(bb));
- TestCase.assertEquals(OFPHello.MINIMUM_LENGTH, msg.getOffendingMsg(bb).length);
- }
-
- public void testGarbageAtEnd() {
- // This is a OFPErrorMsg msg (12 bytes), that encaps a OFVendor msg (24
- // bytes)
- // AND some zeros at the end (40 bytes) for a total of 76 bytes
- // THIS is what an NEC sends in reply to Nox's VENDOR request
- byte[] oferrorRaw = { 0x01, 0x01, 0x00, 0x4c, 0x00, 0x00, 0x10, (byte) 0xcc, 0x00, 0x01, 0x00, 0x01, 0x01,
- 0x04, 0x00, 0x18, 0x00, 0x00, 0x10, (byte) 0xcc, 0x00, 0x00, 0x23, 0x20, 0x00, 0x00, 0x00, 0x08, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- OFPMessageFactory factory = new OFPBasicFactoryImpl();
- IDataBuffer buffer = DataBuffers.allocate(1024).wrap(oferrorRaw);
-
- List<OFPMessage> msgs = factory.parseMessages(buffer, oferrorRaw.length);
- TestCase.assertEquals(1, msgs.size());
- OFPMessage msg = msgs.get(0);
- TestCase.assertEquals(76, msg.getLengthU());
- IDataBuffer buffer1 = DataBuffers.allocate(1024);
- msg.writeTo(buffer1);
- TestCase.assertEquals(76, buffer1.position());
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPExperimenterHeader;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.util.OFTestCase;
-
-public class OFPExperimenterHeaderTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFPExperimenterHeader msg = (OFPExperimenterHeader) messageFactory.getMessage(OFPType.EXPERIMENTER);
- msg.setExperimenter(1);
- msg.setExpType(2);
- IDataBuffer bb = DataBuffers.allocate(1024);
- bb.clear();
- msg.writeTo(bb);
- bb.flip();
- msg.readFrom(bb);
- TestCase.assertEquals(1, msg.getExperimenter());
- TestCase.assertEquals(2, msg.getExpType());
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFBMatchFields;
-import org.openflow.codec.protocol.OFPFlowMod;
-import org.openflow.codec.protocol.OFPFlowModCommand;
-import org.openflow.codec.protocol.OFPMatch;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.protocol.OXMClass;
-import org.openflow.codec.protocol.OXMField;
-import org.openflow.codec.protocol.action.OFPAction;
-import org.openflow.codec.protocol.action.OFPActionOutput;
-import org.openflow.codec.protocol.factory.OFPBasicFactoryImpl;
-import org.openflow.codec.protocol.factory.OFPInstructionFactory;
-import org.openflow.codec.protocol.instruction.OFPInstruction;
-import org.openflow.codec.protocol.instruction.OFPInstructionApplyActions;
-import org.openflow.codec.protocol.instruction.OFPInstructionGoToTable;
-
-/**
- * test class to verify OFPFlowMod message
- *
- * @author AnilGujele
- *
- */
-public class OFPFlowModTest extends TestCase {
-
- private OFPInstructionFactory instrFactory = new OFPBasicFactoryImpl();
-
- private IDataBuffer buffer = DataBuffers.allocate(1024);
-
- protected void tearDown() throws Exception {
- buffer.clear();
- }
-
- public void testFlowModCreation() {
- OFPFlowMod flowMod = this.getDefaultFlowMod();
- assertTrue(flowMod.type.equals(OFPType.FLOW_MOD));
-
- }
-
- private OFPFlowMod getDefaultFlowMod() {
- OFPFlowMod flowMod = new OFPFlowMod();
- flowMod.setCookie(25L);
- flowMod.setCookieMask(25L);
- flowMod.setTableId((byte) 0);
- flowMod.setBufferId(1);
- flowMod.setIdleTimeout((short) 2000);
- flowMod.setHardTimeout((short) 25000);
- flowMod.setPriority((short) 1);
- flowMod.setCommand(OFPFlowModCommand.OFPFC_ADD);
- flowMod.setOutPort(1000);
- flowMod.setOutGroup(1);
- flowMod.setFlags((short) 1);
- OFPMatch match = new OFPMatch();
- flowMod.setMatch(match);
- OFPInstruction instr = new OFPInstructionGoToTable();
- List<OFPInstruction> instrList = new ArrayList<OFPInstruction>();
- instrList.add(instr);
- flowMod.setInstructions(instrList);
- flowMod.setInstructionFactory(instrFactory);
- return flowMod;
- }
-
- public void testClone() {
- OFPFlowMod flowMod = this.getDefaultFlowMod();
- OFPFlowMod flowModCloned = flowMod.clone();
- TestCase.assertEquals(flowMod, flowModCloned);
-
- OXMField matchField = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_SRC, false, new byte[] { 1, 2,
- 3, 4 });
- flowMod.getMatch().addMatchField(matchField);
- TestCase.assertNotSame(flowMod, flowModCloned);
-
- flowMod = flowModCloned.clone();
- TestCase.assertEquals(flowMod, flowModCloned);
- }
-
- public void testReadWriteSuccess() {
- OFPFlowMod flowModWriter = this.getDefaultFlowMod();
- OFPFlowMod flowModReader = new OFPFlowMod();
- OXMField matchField = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_SRC, false, new byte[] { 1, 2,
- 3, 4 });
- flowModWriter.getMatch().addMatchField(matchField);
- flowModWriter.writeTo(buffer);
- buffer.flip();
- flowModReader.setInstructionFactory(instrFactory);
- flowModReader.readFrom(buffer);
- TestCase.assertEquals(flowModWriter, flowModReader);
-
- }
-
- public void testReadWriteFailed() {
- OFPFlowMod flowModWriter = this.getDefaultFlowMod();
- OFPFlowMod flowModReader = new OFPFlowMod();
- OXMField matchField = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_SRC, false, new byte[] { 1, 2,
- 3, 4 });
- flowModWriter.getMatch().addMatchField(matchField);
- flowModWriter.writeTo(buffer);
- buffer.flip();
- boolean result = false;
- try {
- flowModReader.readFrom(buffer);
- } catch (RuntimeException ex) {
- result = true;
- }
- TestCase.assertTrue(result);
- }
-
- public void testLength() {
- OFPFlowMod flowModWriter = this.getDefaultFlowMod();
- OFPFlowMod flowModReader = new OFPFlowMod();
- OXMField matchField = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_SRC, false, new byte[] { 1, 2,
- 3, 4 });
- flowModWriter.getMatch().addMatchField(matchField);
- flowModWriter.writeTo(buffer);
- buffer.flip();
- flowModReader.setInstructionFactory(instrFactory);
- flowModReader.readFrom(buffer);
- TestCase.assertEquals(flowModWriter.getLength(), flowModReader.getLength());
-
- }
-
- public void testToString() {
- OFPFlowMod flowModWriter = this.getDefaultFlowMod();
- OFPFlowMod flowModReader = new OFPFlowMod();
- OXMField matchField = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_SRC, false, new byte[] { 1, 2,
- 3, 4 });
- flowModWriter.getMatch().addMatchField(matchField);
- flowModWriter.writeTo(buffer);
- buffer.flip();
- flowModReader.setInstructionFactory(instrFactory);
- flowModReader.readFrom(buffer);
- TestCase.assertEquals(flowModWriter.toString(), flowModReader.toString());
- }
-
- public void testEqualHashcode() {
-
- OFPFlowMod flowModWriter = this.getDefaultFlowMod();
- OFPFlowMod flowModReader = new OFPFlowMod();
- OXMField matchField = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_SRC, false, new byte[] { 1, 2,
- 3, 4 });
- flowModWriter.getMatch().addMatchField(matchField);
- OXMField matchField1 = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_DST, false, new byte[] { 1, 2,
- 3, 4 });
- flowModWriter.getMatch().addMatchField(matchField1);
- flowModWriter.writeTo(buffer);
- buffer.flip();
- flowModReader.setInstructionFactory(instrFactory);
- flowModReader.readFrom(buffer);
- TestCase.assertTrue(flowModWriter.equals(flowModReader));
- TestCase.assertEquals(flowModWriter.hashCode(), flowModReader.hashCode());
- }
-
- public void testFlowModInstrActions() {
- OFPFlowMod flowModWriter = this.getDefaultFlowMod();
- OFPInstructionApplyActions instr = new OFPInstructionApplyActions();
- List<OFPInstruction> instrList = new ArrayList<OFPInstruction>();
- instrList.add(instr);
- OFPAction action = new OFPActionOutput();
- List<OFPAction> actionList = new ArrayList<OFPAction>();
- actionList.add(action);
- instr.setActions(actionList);
- instr.setActionFactory(new OFPBasicFactoryImpl());
- flowModWriter.setInstructions(instrList);
- flowModWriter.writeTo(buffer);
- buffer.flip();
- OFPFlowMod flowModReader = new OFPFlowMod();
- flowModReader.setInstructionFactory(instrFactory);
- flowModReader.readFrom(buffer);
- assertEquals(flowModWriter, flowModReader);
-
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFBMatchFields;
-import org.openflow.codec.protocol.OFPFlowRemoved;
-import org.openflow.codec.protocol.OFPMatch;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.protocol.OXMClass;
-import org.openflow.codec.protocol.OXMField;
-import org.openflow.codec.protocol.OFPFlowRemoved.OFFlowRemovedReason;
-import org.openflow.codec.util.OFTestCase;
-
-public class OFPFlowRemovedTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFPFlowRemoved msg = (OFPFlowRemoved) messageFactory.getMessage(OFPType.FLOW_REMOVED);
- msg.setMatch(new OFPMatch());
- byte[] hwAddr = new byte[6];
- OXMField ethSrc = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.ETH_SRC, false, hwAddr);
- OXMField ethDst = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.ETH_DST, false, hwAddr);
- msg.getMatch().addMatchField(ethSrc);
- msg.getMatch().addMatchField(ethDst);
- msg.setReason(OFFlowRemovedReason.OFPRR_DELETE);
- IDataBuffer bb = DataBuffers.allocate(1024);
- bb.clear();
- msg.writeTo(bb);
- bb.flip();
- msg.readFrom(bb);
- TestCase.assertEquals(OFPType.FLOW_REMOVED, msg.getType());
- TestCase.assertEquals(OFFlowRemovedReason.OFPRR_DELETE, msg.getReason());
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPSetConfig;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.util.OFTestCase;
-
-public class OFPGetConfigReplyTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFPSetConfig msg = (OFPSetConfig) messageFactory.getMessage(OFPType.SET_CONFIG);
- msg.setFlags((short) 1);
- IDataBuffer bb = DataBuffers.allocate(1024);
- bb.clear();
- msg.writeTo(bb);
- bb.flip();
- msg.readFrom(bb);
- TestCase.assertEquals(OFPType.SET_CONFIG, msg.getType());
- TestCase.assertEquals((short) 1, msg.getFlags());
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPGetConfigRequest;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.util.OFTestCase;
-
-public class OFPGetConfigRequestTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFPGetConfigRequest msg = (OFPGetConfigRequest) messageFactory.getMessage(OFPType.GET_CONFIG_REQUEST);
- IDataBuffer bb = DataBuffers.allocate(1024);
- bb.clear();
- msg.writeTo(bb);
- bb.flip();
- msg.readFrom(bb);
- TestCase.assertEquals(OFPType.GET_CONFIG_REQUEST, msg.getType());
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPHello;
-import org.openflow.codec.protocol.OFPHelloElemHeader;
-import org.openflow.codec.protocol.OFPHelloElemType;
-import org.openflow.codec.protocol.OFPHelloElemVersionBitmap;
-
-public class OFPHelloTest extends TestCase {
-
- private IDataBuffer buffer = DataBuffers.allocate(1024);
-
- protected void tearDown() throws Exception {
- super.tearDown();
- buffer.clear();
- }
-
- public void testHelloElemTypeMapping() throws Exception {
- TestCase.assertEquals(OFPHelloElemType.VERSIONBITMAP, OFPHelloElemType.valueOf((short) 1));
- }
-
- public void testReadWrite() {
- OFPHello helloWriter = new OFPHello();
- List<OFPHelloElemHeader> elements = new ArrayList<OFPHelloElemHeader>();
- elements.add(OFPHelloElemType.VERSIONBITMAP.newInstance());
- helloWriter.setHelloElements(elements);
- helloWriter.writeTo(buffer);
- buffer.flip();
- OFPHello helloReader = new OFPHello();
- helloReader.readFrom(buffer);
- TestCase.assertEquals(helloWriter, helloReader);
- }
-
- public void testReadWriteWithBitmap() {
- OFPHello helloWriter = new OFPHello();
- List<OFPHelloElemHeader> elements = new ArrayList<OFPHelloElemHeader>();
- OFPHelloElemVersionBitmap bitmap = (OFPHelloElemVersionBitmap) OFPHelloElemType.VERSIONBITMAP.newInstance();
- bitmap.setBitmaps(new int[] { 3, 1 });
- elements.add(bitmap);
- helloWriter.setHelloElements(elements);
- helloWriter.writeTo(buffer);
- buffer.flip();
- OFPHello helloReader = new OFPHello();
- helloReader.readFrom(buffer);
- TestCase.assertEquals(helloWriter, helloReader);
- }
-
- public void testEqualHashcode() {
- OFPHello helloWriter = new OFPHello();
- List<OFPHelloElemHeader> elements = new ArrayList<OFPHelloElemHeader>();
- elements.add(OFPHelloElemType.VERSIONBITMAP.newInstance());
- helloWriter.setHelloElements(elements);
- helloWriter.writeTo(buffer);
- buffer.flip();
- OFPHello helloReader = new OFPHello();
- helloReader.readFrom(buffer);
- TestCase.assertEquals(helloWriter, helloReader);
- TestCase.assertEquals(helloWriter.hashCode(), helloReader.hashCode());
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFBMatchFields;
-import org.openflow.codec.protocol.OFPMatch;
-import org.openflow.codec.protocol.OXMClass;
-import org.openflow.codec.protocol.OXMField;
-
-public class OFPMatchTest extends TestCase {
-
- private IDataBuffer buffer = DataBuffers.allocate(1024);
-
- protected void tearDown() throws Exception {
- buffer.clear();
- }
-
- public void testClone() {
- OFPMatch match1 = new OFPMatch();
- OFPMatch match2 = match1.clone();
- TestCase.assertEquals(match1, match2);
- OXMField matchField = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_SRC, false, new byte[] { 1, 2,
- 3, 4 });
- match2.addMatchField(matchField);
- TestCase.assertNotSame(match1, match2);
- match1 = match2.clone();
- TestCase.assertEquals(match1, match2);
- }
-
- public void testReadWrite() {
- OFPMatch match1 = new OFPMatch();
- OFPMatch match2 = new OFPMatch();
- OXMField matchField = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_SRC, false, new byte[] { 1, 2,
- 3, 4 });
- match1.addMatchField(matchField);
- match1.writeTo(buffer);
- buffer.flip();
- match2.readFrom(buffer);
- TestCase.assertEquals(match1, match2);
- }
-
- public void testToString() {
- OFPMatch match1 = new OFPMatch();
- OFPMatch match2 = new OFPMatch();
- OXMField matchField = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_SRC, false, new byte[] { 1, 2,
- 3, 4 });
- match1.addMatchField(matchField);
- match1.writeTo(buffer);
- buffer.flip();
- match2.readFrom(buffer);
- TestCase.assertEquals(match1.toString(), match2.toString());
- }
-
- public void testEqualHashcode() {
- OFPMatch match1 = new OFPMatch();
- OFPMatch match2 = new OFPMatch();
- OXMField matchField = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_SRC, false, new byte[] { 1, 2,
- 3, 4 });
- match1.addMatchField(matchField);
- OXMField matchField1 = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_DST, false, new byte[] { 1, 2,
- 3, 4 });
- match1.addMatchField(matchField1);
- match1.writeTo(buffer);
- buffer.flip();
- match2.readFrom(buffer);
- TestCase.assertTrue(match1.equals(match2));
- TestCase.assertEquals(match1.hashCode(), match2.hashCode());
- }
-
- public void testPrerequisite() {
- OFPMatch match1 = new OFPMatch();
- OFPMatch match2 = new OFPMatch();
- OXMField matchField = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_SRC, false, new byte[] { 1, 2,
- 3, 4 });
- match1.addMatchField(matchField);
- OXMField matchField1 = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_DST, false, new byte[] { 1, 2,
- 3, 4 });
- match1.addMatchField(matchField1);
- match1.writeTo(buffer);
- buffer.flip();
- boolean result = match2.readFrom(buffer);
- TestCase.assertTrue(result);
- }
-
- public void testFromString() {
- // OFPMatch correct = new OFPMatch();
- // OFPMatch tester = new OFPMatch();
- //
- // // Various combinations of "all"/"any"
- // tester.fromString("OFPMatch[]");
- // // correct is already wildcarded
- // TestCase.assertEquals(correct, tester);
- // tester.fromString("all");
- // TestCase.assertEquals(correct, tester);
- // tester.fromString("ANY");
- // TestCase.assertEquals(correct, tester);
- // tester.fromString("");
- // TestCase.assertEquals(correct, tester);
- // tester.fromString("[]");
- // TestCase.assertEquals(correct, tester);
- //
- // // ip_src
- // correct.setWildcards(~OFPMatch.OFPFW_NW_SRC_MASK);
- // correct.setNetworkSource(0x01010203);
- // tester.fromString("nw_src=1.1.2.3");
- // TestCase.assertEquals(correct.getNetworkSourceMaskLen(), tester
- // .getNetworkSourceMaskLen());
- // TestCase.assertEquals(correct, tester);
- // tester.fromString("IP_sRc=1.1.2.3");
- // TestCase.assertEquals(correct.getNetworkSourceMaskLen(), tester
- // .getNetworkSourceMaskLen());
- // TestCase.assertEquals(correct, tester);
- }
-
- public void testIpToString() {
- // String test = OFPMatch.ipToString(-1);
- // TestCase.assertEquals("255.255.255.255", test);
- }
-
- public void testReverse() {
- // OFPMatch match1 = new OFPMatch();
- // OFPMatch match2 = match1.reverse((short)0, true);
- // TestCase.assertEquals(match1, match2);
- //
- // match1.fromString("dl_dst=00:11:22:33:44:55");
- // match2 = match1.reverse((short)0, true);
- // OFPMatch match3 = new OFPMatch();
- // match3.fromString("dl_src=00:11:22:33:44:55");
- // TestCase.assertEquals(match2, match3);
- //
- // match1.fromString("nw_dst=192.168.0.0/24");
- // match2 = match1.reverse((short)0, true);
- // match3.fromString("nw_src=192.168.0.0/24");
- // TestCase.assertEquals(match2, match3);
- //
- // match1.fromString("in_port=1");
- // match2 = match1.reverse((short)2, false);
- // match3.fromString("in_port=2");
- // TestCase.assertEquals(match2, match3);
- }
-
- public void testSubsumes() {
- // OFPMatch match1 = new OFPMatch();
- // OFPMatch match2 = new OFPMatch();
- // match2.fromString("dl_dst=00:11:22:33:44:55");
- // TestCase.assertTrue(match1.subsumes(match2));
- // TestCase.assertFalse(match2.subsumes(match1));
- //
- // match1.fromString("nw_dst=192.168.0.0/16");
- // match2.fromString("nw_dst=192.168.0.0/24");
- // TestCase.assertTrue(match1.subsumes(match2));
- // TestCase.assertFalse(match2.subsumes(match1));
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.factory.OFPBasicFactoryImpl;
-import org.openflow.codec.protocol.factory.OFPMessageFactory;
-import org.openflow.codec.util.OFTestCase;
-
-public class OFPMultipartReplyTest extends OFTestCase {
- public void testOFFlowStatisticsReply() throws Exception {
- byte[] packet = new byte[] { 0x01, 0x11, 0x01, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
- 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x02, (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0a,
- 0x00, 0x00, 0x03, 0x0a, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a,
- (byte) 0xa6, (byte) 0xa6, 0x00, (byte) 0xff, (byte) 0xff, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0xc4, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x08, 0x06, 0x00, 0x02,
- 0x00, 0x00, 0x0a, 0x00, 0x00, 0x03, 0x0a, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x3b, 0x2f, (byte) 0xfa, 0x40, (byte) 0xff, (byte) 0xff, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, (byte) 0xff, (byte) 0xff, 0x00, 0x62, 0x08, 0x00, 0x00, 0x01,
- 0x62, 0x37, 0x0a, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x3a, (byte) 0xc5, 0x2a, (byte) 0x80, (byte) 0xff, (byte) 0xff, 0x00, 0x05, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0xc4, 0x00, 0x00, 0x00, 0x08,
- 0x00, 0x02, 0x00, 0x00 };
-
- OFPMessageFactory factory = new OFPBasicFactoryImpl();
- IDataBuffer bb = DataBuffers.allocate(8);
- IDataBuffer packetBuf = bb.wrap(packet);
- /*
- * List<OFPMessage> msgs = factory.parseMessages(packetBuf,
- * packet.length); TestCase.assertEquals(1, msgs.size());
- * TestCase.assertTrue(msgs.get(0) instanceof OFStatisticsReply);
- * OFStatisticsReply sr = (OFStatisticsReply) msgs.get(0);
- * TestCase.assertEquals(OFStatisticsType.FLOW, sr.getStatisticType());
- * TestCase.assertEquals(3, sr.getStatistics().size());
- */
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFBMatchFields;
-import org.openflow.codec.protocol.OFPMatch;
-import org.openflow.codec.protocol.OXMClass;
-import org.openflow.codec.protocol.OXMField;
-import org.openflow.codec.protocol.OFPPort.OFPortConfig;
-import org.openflow.codec.protocol.OFPPort.OFPortFeatures;
-import org.openflow.codec.protocol.OFPPort.OFPortState;
-import org.openflow.codec.protocol.action.OFPAction;
-import org.openflow.codec.protocol.action.OFPActionType;
-import org.openflow.codec.protocol.factory.OFPBasicFactoryImpl;
-import org.openflow.codec.protocol.factory.OFPActionFactory;
-import org.openflow.codec.protocol.factory.OFPInstructionFactory;
-import org.openflow.codec.protocol.instruction.OFPInstruction;
-import org.openflow.codec.protocol.instruction.OFPInstructionType;
-import org.openflow.codec.protocol.statistics.OFPAggregateStatisticsRequest;
-import org.openflow.codec.protocol.statistics.OFPDescriptionStatistics;
-import org.openflow.codec.protocol.statistics.OFPExperimenterMultipartHeader;
-import org.openflow.codec.protocol.statistics.OFPFlowStatisticsRequest;
-import org.openflow.codec.protocol.statistics.OFPPortDescriptionStatistics;
-import org.openflow.codec.protocol.statistics.OFPPortStatisticsRequest;
-import org.openflow.codec.protocol.statistics.OFPQueueStatisticsRequest;
-import org.openflow.codec.protocol.statistics.OFPTableFeatures;
-import org.openflow.codec.protocol.statistics.OFPTableStatistics;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropHeader;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropApplyActions;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropApplyActionsMiss;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropApplySetField;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropApplySetFieldMiss;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropExperimenter;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropExperimenterMiss;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropInstructions;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropInstructionsMiss;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropMatch;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropNextTables;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropNextTablesMiss;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropType;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropWildcards;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropWriteActions;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropWriteActionsMiss;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropWriteSetField;
-import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropWriteSetFieldMiss;
-import org.openflow.codec.util.OFTestCase;
-
-public class OFPMultipartRequestTest extends OFTestCase {
-
- private IDataBuffer buffer = DataBuffers.allocate(2 * 1024);
-
- public void tearDown() throws Exception {
- super.tearDown();
- buffer.clear();
- }
-
- public void testOFFlowStatisticsRequest() throws Exception {
- OFPFlowStatisticsRequest request = new OFPFlowStatisticsRequest();
- request.setCookie(2L);
- request.setCookieMask(2L);
- request.setMatch(new OFPMatch());
- request.setOutGroup(3);
- request.setOutPort(400);
- request.setTableId((byte) 2);
-
- request.writeTo(buffer);
- buffer.flip();
- OFPFlowStatisticsRequest tempReq = new OFPFlowStatisticsRequest();
- tempReq.readFrom(buffer);
-
- TestCase.assertEquals(request, tempReq);
- TestCase.assertEquals(request.hashCode(), tempReq.hashCode());
- TestCase.assertEquals(request.getLength(), tempReq.getLength());
- }
-
- public void testOFAggregateStatisticsRequest() throws Exception {
- OFPAggregateStatisticsRequest request = new OFPAggregateStatisticsRequest();
- request.setCookie(2L);
- request.setCookieMask(2L);
- request.setMatch(new OFPMatch());
- request.setOutGroup(3);
- request.setOutPort(400);
- request.setTableId((byte) 2);
-
- request.writeTo(buffer);
- buffer.flip();
- OFPAggregateStatisticsRequest tempReq = new OFPAggregateStatisticsRequest();
- tempReq.readFrom(buffer);
-
- TestCase.assertEquals(request, tempReq);
- TestCase.assertEquals(request.hashCode(), tempReq.hashCode());
- TestCase.assertEquals(request.getLength(), tempReq.getLength());
- }
-
- public void testOFDescriptionStatistics() throws Exception {
- OFPDescriptionStatistics request = new OFPDescriptionStatistics();
- request.setDatapathDescription("dataPathDescription");
- request.setHardwareDescription("hardwareDescription");
- request.setManufacturerDescription("manufacturerDescription");
- request.setSerialNumber("serialNumber");
- request.setSoftwareDescription("softwareDescription");
- buffer.clear();
- request.writeTo(buffer);
- buffer.flip();
- OFPDescriptionStatistics tempReq = new OFPDescriptionStatistics();
- tempReq.readFrom(buffer);
-
- TestCase.assertEquals(request, tempReq);
- TestCase.assertEquals(request.hashCode(), tempReq.hashCode());
- TestCase.assertEquals(request.getLength(), tempReq.getLength());
- }
-
- public void testOFPortDescriptionStatistics() throws Exception {
- OFPPortDescriptionStatistics request = new OFPPortDescriptionStatistics();
- request.setAdvertisedFeatures(OFPortFeatures.OFPPF_1GB_FD.getValue());
- request.setConfig(OFPortConfig.OFPPC_NO_PACKET_IN.getValue());
- request.setCurrentFeatures(OFPortFeatures.OFPPF_1GB_HD.getValue());
- request.setCurrentSpeed(100000);
- request.setHardwareAddress(new byte[] { 1, 2, 3, 4, 5, 6 });
- request.setMaxSpeed(1000000);
- request.setName("open flow port");
- request.setPeerFeatures(OFPortFeatures.OFPPF_10GB_FD.getValue());
- request.setPortNumber((short) 200);
- request.setState(OFPortState.OFPPS_LIVE.getValue());
- request.setSupportedFeatures(OFPortFeatures.OFPPF_FIBER.getValue());
-
- request.writeTo(buffer);
- buffer.flip();
- OFPPortDescriptionStatistics tempReq = new OFPPortDescriptionStatistics();
- tempReq.readFrom(buffer);
-
- TestCase.assertEquals(request, tempReq);
- TestCase.assertEquals(request.hashCode(), tempReq.hashCode());
- TestCase.assertEquals(request.getLength(), tempReq.getLength());
- }
-
- public void testOFPortStatisticsRequest() throws Exception {
- OFPPortStatisticsRequest request = new OFPPortStatisticsRequest();
- request.setPortNumber(5342);
- request.writeTo(buffer);
- buffer.flip();
- OFPPortStatisticsRequest tempReq = new OFPPortStatisticsRequest();
- tempReq.readFrom(buffer);
-
- TestCase.assertEquals(request, tempReq);
- TestCase.assertEquals(request.hashCode(), tempReq.hashCode());
- TestCase.assertEquals(request.getLength(), tempReq.getLength());
- }
-
- public void testOFQueueStatisticsRequest() throws Exception {
- OFPQueueStatisticsRequest request = new OFPQueueStatisticsRequest();
- request.setPortNumber(5342);
- request.setQueueId(2);
- request.writeTo(buffer);
- buffer.flip();
- OFPQueueStatisticsRequest tempReq = new OFPQueueStatisticsRequest();
- tempReq.readFrom(buffer);
-
- TestCase.assertEquals(request, tempReq);
- TestCase.assertEquals(request.hashCode(), tempReq.hashCode());
- TestCase.assertEquals(request.getLength(), tempReq.getLength());
- }
-
- public void testOFTableStatistics() throws Exception {
- OFPTableStatistics request = new OFPTableStatistics();
- request.setActiveCount(10);
- request.setLookupCount(10);
- request.setMatchedCount(2);
- request.setTableId((byte) 1);
- request.writeTo(buffer);
- buffer.flip();
- OFPTableStatistics tempReq = new OFPTableStatistics();
- tempReq.readFrom(buffer);
-
- TestCase.assertEquals(request, tempReq);
- TestCase.assertEquals(request.hashCode(), tempReq.hashCode());
- TestCase.assertEquals(request.getLength(), tempReq.getLength());
- }
-
- public void testOFTableFeaturesNoProp() throws Exception {
- OFPTableFeatures request = getOFTableFeatures();
-
- executeTest(request);
- }
-
- private OFPTableFeatures getOFTableFeatures() {
- OFPTableFeatures request = new OFPTableFeatures();
- request.setConfig(1);
- request.setMaxEntries(100);
- request.setMetadataMatch(10L);
- request.setMetadataWrite(5L);
- request.setName("table1");
- request.setTableId((byte) 1);
- return request;
- }
-
- public void testOFTableFeaturesNextTables() throws Exception {
- OFPTableFeatures request = getOFTableFeatures();
- OFPTableFeaturePropNextTables prop = (OFPTableFeaturePropNextTables) OFPTableFeaturePropType.NEXT_TABLES
- .newInstance();
- prop.setNextTableIds(new byte[] { 4, 6, 9 });
- List<OFPTableFeaturePropHeader> list = new ArrayList<OFPTableFeaturePropHeader>();
- list.add(prop);
- request.setProperties(list);
-
- executeTest(request);
- }
-
- private void executeTest(OFPTableFeatures request) {
- request.writeTo(buffer);
- buffer.flip();
- OFPTableFeatures tempReq = new OFPTableFeatures();
- tempReq.readFrom(buffer);
-
- TestCase.assertEquals(request, tempReq);
- TestCase.assertEquals(request.hashCode(), tempReq.hashCode());
- TestCase.assertEquals(request.getLength(), tempReq.getLength());
- }
-
- public void testOFTableFeaturesNextTablesMiss() throws Exception {
- OFPTableFeatures request = getOFTableFeatures();
- OFPTableFeaturePropNextTablesMiss prop = (OFPTableFeaturePropNextTablesMiss) OFPTableFeaturePropType.NEXT_TABLES_MISS
- .newInstance();
- prop.setNextTableIds(new byte[] { 4, 6, 9 });
- List<OFPTableFeaturePropHeader> list = new ArrayList<OFPTableFeaturePropHeader>();
- list.add(prop);
- request.setProperties(list);
-
- executeTest(request);
- }
-
- public void testOFTableFeaturesInstructionsSuccess() throws Exception {
- OFPTableFeatures request = getOFTableFeatures();
- OFPInstructionFactory instructionFactory = new OFPBasicFactoryImpl();
- request.setInstructionFactory(instructionFactory);
-
- // Instructions property
- OFPTableFeaturePropInstructions prop = (OFPTableFeaturePropInstructions) OFPTableFeaturePropType.INSTRUCTIONS
- .newInstance();
- OFPInstruction instrId = OFPInstructionType.GOTO_TABLE.newInstance();
- List<OFPInstruction> list = new ArrayList<OFPInstruction>();
- list.add(instrId);
- prop.setInstructionIds(list);
-
- // Instruction miss property
- OFPTableFeaturePropInstructionsMiss propMiss = (OFPTableFeaturePropInstructionsMiss) OFPTableFeaturePropType.INSTRUCTIONS_MISS
- .newInstance();
- propMiss.setInstructionIds(list);
-
- List<OFPTableFeaturePropHeader> listProp = new ArrayList<OFPTableFeaturePropHeader>();
- listProp.add(prop);
- listProp.add(propMiss);
- request.setProperties(listProp);
-
- request.writeTo(buffer);
- buffer.flip();
- OFPTableFeatures tempReq = new OFPTableFeatures();
- tempReq.setInstructionFactory(instructionFactory);
- tempReq.readFrom(buffer);
-
- TestCase.assertEquals(request, tempReq);
- TestCase.assertEquals(request.hashCode(), tempReq.hashCode());
- TestCase.assertEquals(request.getLength(), tempReq.getLength());
- }
-
- public void testOFTableFeaturesInstructionsFailed() throws Exception {
- OFPTableFeatures request = getOFTableFeatures();
-
- // Instructions property
- OFPTableFeaturePropInstructions prop = (OFPTableFeaturePropInstructions) OFPTableFeaturePropType.INSTRUCTIONS
- .newInstance();
- OFPInstruction instrId = OFPInstructionType.GOTO_TABLE.newInstance();
- List<OFPInstruction> list = new ArrayList<OFPInstruction>();
- list.add(instrId);
- prop.setInstructionIds(list);
-
- List<OFPTableFeaturePropHeader> listProp = new ArrayList<OFPTableFeaturePropHeader>();
- listProp.add(prop);
- request.setProperties(listProp);
-
- request.writeTo(buffer);
- buffer.flip();
- OFPTableFeatures tempReq = new OFPTableFeatures();
- boolean result = false;
- try {
- tempReq.readFrom(buffer);
- } catch (RuntimeException ex) {
- result = true;
- }
- TestCase.assertTrue(result);
- }
-
- public void testOFTableFeaturesActions() throws Exception {
- OFPTableFeatures request = getOFTableFeatures();
- OFPActionFactory actionFactory = new OFPBasicFactoryImpl();
- request.setActionFactory(actionFactory);
- // Apply action property
- OFPTableFeaturePropApplyActions prop = (OFPTableFeaturePropApplyActions) OFPTableFeaturePropType.APPLY_ACTIONS
- .newInstance();
- OFPAction action = OFPActionType.OUTPUT.newInstance();
- List<OFPAction> list = new ArrayList<OFPAction>();
- list.add(action);
- prop.setActionIds(list);
-
- OFPTableFeaturePropApplyActionsMiss propMiss = (OFPTableFeaturePropApplyActionsMiss) OFPTableFeaturePropType.APPLY_ACTIONS_MISS
- .newInstance();
- propMiss.setActionIds(list);
-
- OFPTableFeaturePropWriteActions prop1 = (OFPTableFeaturePropWriteActions) OFPTableFeaturePropType.WRITE_ACTIONS
- .newInstance();
- prop1.setActionIds(list);
-
- OFPTableFeaturePropWriteActionsMiss propMiss1 = (OFPTableFeaturePropWriteActionsMiss) OFPTableFeaturePropType.WRITE_ACTIONS_MISS
- .newInstance();
- propMiss1.setActionIds(list);
-
- List<OFPTableFeaturePropHeader> listProp = new ArrayList<OFPTableFeaturePropHeader>();
- listProp.add(prop);
- listProp.add(propMiss);
- listProp.add(prop1);
- listProp.add(propMiss1);
-
- request.setProperties(listProp);
-
- request.writeTo(buffer);
- buffer.flip();
- OFPTableFeatures tempReq = new OFPTableFeatures();
- tempReq.setActionFactory(actionFactory);
- tempReq.readFrom(buffer);
-
- TestCase.assertEquals(request, tempReq);
- TestCase.assertEquals(request.hashCode(), tempReq.hashCode());
- TestCase.assertEquals(request.getLength(), tempReq.getLength());
- }
-
- public void testOFTableFeaturesMatch() throws Exception {
- OFPTableFeatures request = getOFTableFeatures();
-
- OFPTableFeaturePropMatch prop = (OFPTableFeaturePropMatch) OFPTableFeaturePropType.MATCH.newInstance();
- OXMField field = new OXMField(OXMClass.OPENFLOW_BASIC, OFBMatchFields.IPV4_SRC, false, null);
- List<OXMField> list = new ArrayList<OXMField>();
- list.add(field);
- prop.setOXMIds(list);
-
- OFPTableFeaturePropWildcards wildcard = (OFPTableFeaturePropWildcards) OFPTableFeaturePropType.WILDCARDS
- .newInstance();
- wildcard.setOXMIds(list);
-
- OFPTableFeaturePropWriteSetField write = (OFPTableFeaturePropWriteSetField) OFPTableFeaturePropType.WRITE_SETFIELD
- .newInstance();
- write.setOXMIds(list);
-
- OFPTableFeaturePropWriteSetFieldMiss writeMiss = (OFPTableFeaturePropWriteSetFieldMiss) OFPTableFeaturePropType.WRITE_SETFIELD_MISS
- .newInstance();
- writeMiss.setOXMIds(list);
-
- OFPTableFeaturePropApplySetField apply = (OFPTableFeaturePropApplySetField) OFPTableFeaturePropType.APPLY_SETFIELD
- .newInstance();
- apply.setOXMIds(list);
-
- OFPTableFeaturePropApplySetFieldMiss applyMiss = (OFPTableFeaturePropApplySetFieldMiss) OFPTableFeaturePropType.APPLY_SETFIELD_MISS
- .newInstance();
- applyMiss.setOXMIds(list);
-
- List<OFPTableFeaturePropHeader> listProp = new ArrayList<OFPTableFeaturePropHeader>();
- listProp.add(prop);
- listProp.add(wildcard);
- listProp.add(write);
- listProp.add(writeMiss);
- listProp.add(apply);
- listProp.add(applyMiss);
-
- request.setProperties(listProp);
-
- executeTest(request);
- }
-
- public void testOFTableFeaturesExperimenter() throws Exception {
- OFPTableFeatures request = getOFTableFeatures();
-
- OFPTableFeaturePropExperimenter prop = (OFPTableFeaturePropExperimenter) OFPTableFeaturePropType.EXPERIMENTER
- .newInstance();
- prop.setExpId(2);
- prop.setExpType(1);
- prop.setExpData(new int[] { 1, 2, 3 });
-
- OFPTableFeaturePropExperimenterMiss propMiss = (OFPTableFeaturePropExperimenterMiss) OFPTableFeaturePropType.EXPERIMENTER_MISS
- .newInstance();
- propMiss.setExpId(22);
- propMiss.setExpType(12);
- propMiss.setExpData(new int[] { 12, 22, 32 });
-
- List<OFPTableFeaturePropHeader> listProp = new ArrayList<OFPTableFeaturePropHeader>();
- listProp.add(prop);
- listProp.add(propMiss);
-
- request.setProperties(listProp);
-
- executeTest(request);
- }
-
- public void testOFPExperimenterMultipartHeaderReadWrite() throws Exception {
- OFPExperimenterMultipartHeader request = new OFPExperimenterMultipartHeader();
- request.setExperimenter(1);
- request.setExpType(2);
- request.setData(new byte[] { 1, 2, 3, 4 });
-
- request.writeTo(buffer);
- buffer.flip();
- OFPExperimenterMultipartHeader tempReq = new OFPExperimenterMultipartHeader();
- tempReq.setLength(12);
- tempReq.readFrom(buffer);
-
- TestCase.assertEquals(request, tempReq);
- TestCase.assertEquals(request.hashCode(), tempReq.hashCode());
- }
-
- public void testOFPExperimenterMultipartHeaderGetters() throws Exception {
- OFPExperimenterMultipartHeader request = new OFPExperimenterMultipartHeader();
- request.setExperimenter(1);
- request.setExpType(2);
- request.setData(new byte[] { 1, 2, 3, 4 });
-
- request.writeTo(buffer);
- buffer.flip();
- OFPExperimenterMultipartHeader tempReq = new OFPExperimenterMultipartHeader();
- tempReq.setLength(12);
- tempReq.readFrom(buffer);
-
- TestCase.assertEquals(1, tempReq.getExperimenter());
- TestCase.assertEquals(2, tempReq.getExpType());
- TestCase.assertEquals(request.getLength(), tempReq.getLength());
- }
-
- public void testOFPExperimenterMultipartHeaderNoData() throws Exception {
- OFPExperimenterMultipartHeader request = new OFPExperimenterMultipartHeader();
- request.setExperimenter(1);
- request.setExpType(2);
-
- request.writeTo(buffer);
- buffer.flip();
- OFPExperimenterMultipartHeader tempReq = new OFPExperimenterMultipartHeader();
- tempReq.readFrom(buffer);
-
- TestCase.assertEquals(1, tempReq.getExperimenter());
- TestCase.assertEquals(2, tempReq.getExpType());
- TestCase.assertEquals(request.getLength(), tempReq.getLength());
- }
-
- // public void testOFFlowStatisticsRequest() throws Exception {
- // byte[] packet = new byte[] { 0x04, 0x10, 0x00, 0x38, 0x00, 0x00, 0x00,
- // 0x16, 0x00, 0x01, 0x00, 0x00, (byte) 0xff, (byte) 0xff,
- // (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- // (byte) 0xff, 0x00, (byte) 0xff, (byte) 0xff };
- //
- // OFPMessageFactory factory = new OFPBasicFactoryImpl();
- // IDataBuffer packetBuf = DataBuffers.createBuffer(8).wrap(packet);
- // List<OFPMessage> msgs = factory.parseMessages(packetBuf, packet.length);
- // TestCase.assertEquals(1, msgs.size());
- // TestCase.assertTrue(msgs.get(0) instanceof OFPMultipartRequest);
- // OFPMultipartRequest sr = (OFPMultipartRequest) msgs.get(0);
- // TestCase.assertEquals(OFPMultipartTypes.FLOW, sr.getMultipartType());
- // TestCase.assertEquals(1, sr.getStatistics().size());
- // TestCase.assertTrue(sr.getStatistics().get(0) instanceof
- // OFPFlowStatisticsRequest);
- // }
- //
- // public void testOFStatisticsRequestVendor() throws Exception {
- // byte[] packet = new byte[] { 0x01, 0x10, 0x00, 0x50, 0x00, 0x00, 0x00,
- // 0x63, (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
- // 0x4c, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- // 0x01, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x20,
- // (byte) 0xe0, 0x00, 0x11, 0x00, 0x0c, 0x29, (byte) 0xc5,
- // (byte) 0x95, 0x57, 0x02, 0x25, 0x5c, (byte) 0xca, 0x00, 0x02,
- // (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
- // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x50, 0x04,
- // 0x00, 0x00, 0x00, 0x00, (byte) 0xff, 0x00, 0x00, 0x00,
- // (byte) 0xff, (byte) 0xff, 0x4e, 0x20 };
- //
- // OFPMessageFactory factory = new OFPBasicFactoryImpl();
- // IDataBuffer packetBuf = DataBuffers.createBuffer(8).wrap(packet);
- // List<OFPMessage> msgs = factory.parseMessages(packetBuf, packet.length);
- // TestCase.assertEquals(1, msgs.size());
- // TestCase.assertTrue(msgs.get(0) instanceof OFPMultipartRequest);
- // OFPMultipartRequest sr = (OFPMultipartRequest) msgs.get(0);
- // TestCase.assertEquals(OFPMultipartTypes.VENDOR, sr.getMultipartType());
- // TestCase.assertEquals(1, sr.getStatistics().size());
- // TestCase.assertTrue(sr.getStatistics().get(0) instanceof
- // OFPVendorStatistics);
- // TestCase.assertEquals(68,
- // ((OFPVendorStatistics)sr.getStatistics().get(0)).getLength());
- // }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import junit.framework.TestCase;
-
-import org.junit.Test;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.protocol.statistics.OFPMultipartTypes;
-
-public class OFPMultipartTypeTest extends TestCase {
- @Test
- public void testMapping() throws Exception {
- TestCase.assertEquals(OFPMultipartTypes.DESC, OFPMultipartTypes.valueOf((short) 0, OFPType.MULTIPART_REQUEST));
- TestCase.assertEquals(OFPMultipartTypes.QUEUE, OFPMultipartTypes.valueOf((short) 5, OFPType.MULTIPART_REQUEST));
- TestCase.assertEquals(OFPMultipartTypes.EXPERIMENTER,
- OFPMultipartTypes.valueOf((short) 0xffff, OFPType.MULTIPART_REQUEST));
- TestCase.assertEquals(OFPMultipartTypes.EXPERIMENTER,
- OFPMultipartTypes.valueOf((short) 0xffff, OFPType.MULTIPART_REPLY));
- TestCase.assertEquals(OFPMultipartTypes.PORT_STATS,
- OFPMultipartTypes.valueOf((short) 4, OFPType.MULTIPART_REQUEST));
- TestCase.assertEquals(OFPMultipartTypes.PORT_DESC,
- OFPMultipartTypes.valueOf((short) 13, OFPType.MULTIPART_REQUEST));
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.junit.Test;
-import org.openflow.codec.protocol.action.OFPActionType;
-
-import junit.framework.TestCase;
-
-public class OFPPActionTypeTest extends TestCase {
- @Test
- public void testMapping() throws Exception {
- TestCase.assertEquals(OFPActionType.OUTPUT, OFPActionType.valueOf((short) 0));
- TestCase.assertEquals(OFPActionType.COPY_TTL_OUT, OFPActionType.valueOf((short) 11));
- TestCase.assertEquals(OFPActionType.EXPERIMENTER, OFPActionType.valueOf((short) 0xffff));
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPPortMod;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.util.OFTestCase;
-
-public class OFPPortConfigTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFPPortMod msg = (OFPPortMod) messageFactory.getMessage(OFPType.PORT_MOD);
- msg.setHardwareAddress(new byte[6]);
- msg.portNumber = 1;
- IDataBuffer bb = DataBuffers.allocate(1024);
- bb.clear();
- msg.writeTo(bb);
- bb.flip();
- msg.readFrom(bb);
- TestCase.assertEquals(OFPType.PORT_MOD, msg.getType());
- TestCase.assertEquals(1, msg.getPortNumber());
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPPort;
-import org.openflow.codec.protocol.OFPPortStatus;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.protocol.OFPPortStatus.OFPortReason;
-import org.openflow.codec.util.OFTestCase;
-
-public class OFPPortStatusTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFPPortStatus msg = (OFPPortStatus) messageFactory.getMessage(OFPType.PORT_STATUS);
- msg.setDesc(new OFPPort());
- msg.getDesc().setHardwareAddress(new byte[6]);
- msg.getDesc().setName("eth0");
- msg.setReason((byte) OFPortReason.OFPPR_ADD.ordinal());
- IDataBuffer bb = DataBuffers.allocate(1024);
- bb.clear();
- msg.writeTo(bb);
- bb.flip();
- msg.readFrom(bb);
- TestCase.assertEquals(OFPType.PORT_STATUS, msg.getType());
- TestCase.assertEquals((byte) OFPortReason.OFPPR_ADD.ordinal(), msg.getReason());
- TestCase.assertNotNull(msg.getDesc());
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPQueueConfigReply;
-import org.openflow.codec.protocol.OFPQueueConfigRequest;
-import org.openflow.codec.protocol.factory.OFPBasicFactoryImpl;
-import org.openflow.codec.protocol.queue.OFPPacketQueue;
-import org.openflow.codec.protocol.queue.OFPQueueProperty;
-import org.openflow.codec.protocol.queue.OFPQueuePropertyMinRate;
-import org.openflow.codec.protocol.queue.OFPQueuePropertyType;
-import org.openflow.codec.util.OFTestCase;
-
-public class OFPQueueConfigTest extends OFTestCase {
- public void testRequest() throws Exception {
- OFPQueueConfigRequest req = new OFPQueueConfigRequest();
- req.setPort((short) 5);
- IDataBuffer bb = DataBuffers.allocate(1024);
- bb.clear();
- req.writeTo(bb);
- bb.flip();
-
- OFPQueueConfigRequest req2 = new OFPQueueConfigRequest();
- req2.readFrom(bb);
- TestCase.assertEquals(req, req2);
- }
-
- public void testReply() throws Exception {
- OFPQueueConfigReply reply = new OFPQueueConfigReply();
- reply.setPort((short) 5);
-
- OFPPacketQueue queue = new OFPPacketQueue();
- queue.setQueueId(1);
- List<OFPQueueProperty> properties = new ArrayList<OFPQueueProperty>();
- properties.add(new OFPQueuePropertyMinRate().setRate((short) 1));
- queue.setProperties(properties);
- queue.setLength((short) (OFPPacketQueue.MINIMUM_LENGTH + OFPQueuePropertyMinRate.MINIMUM_LENGTH));
-
- List<OFPPacketQueue> queues = new ArrayList<OFPPacketQueue>();
- queues.add(queue);
- reply.setQueues(queues);
- reply.setLengthU(OFPQueueConfigReply.MINIMUM_LENGTH + queue.getLength());
-
- IDataBuffer bb = DataBuffers.allocate(1024);
- bb.clear();
- reply.writeTo(bb);
- bb.flip();
-
- OFPQueueConfigReply reply2 = new OFPQueueConfigReply();
- reply2.setQueuePropertyFactory(new OFPBasicFactoryImpl());
- reply2.readFrom(bb);
- TestCase.assertEquals(reply, reply2);
- TestCase.assertEquals(1, reply2.getQueues().size());
- TestCase.assertEquals(1, reply2.getQueues().get(0).getProperties().size());
- TestCase.assertTrue(reply2.getQueues().get(0).getProperties().get(0) instanceof OFPQueuePropertyMinRate);
- TestCase.assertEquals(OFPQueuePropertyType.MIN_RATE, reply2.getQueues().get(0).getProperties().get(0).getType());
-
- reply.getQueues().add(queue.clone());
- reply.setLengthU(reply.getLengthU() + queue.getLength());
- bb.clear();
- reply.writeTo(bb);
- bb.flip();
- reply2 = new OFPQueueConfigReply();
- reply2.setQueuePropertyFactory(new OFPBasicFactoryImpl());
- reply2.readFrom(bb);
- TestCase.assertEquals(reply, reply2);
- TestCase.assertEquals(2, reply2.getQueues().size());
-
- queue.getProperties().add(new OFPQueuePropertyMinRate().setRate((short) 2));
- queue.setLength((short) (queue.getLength() + OFPQueuePropertyMinRate.MINIMUM_LENGTH));
- reply.setLengthU(reply.getLengthU() + OFPQueuePropertyMinRate.MINIMUM_LENGTH);
- bb.clear();
- reply.writeTo(bb);
- bb.flip();
- reply2 = new OFPQueueConfigReply();
- reply2.setQueuePropertyFactory(new OFPBasicFactoryImpl());
- reply2.readFrom(bb);
- TestCase.assertEquals(reply, reply2);
- TestCase.assertEquals(2, reply2.getQueues().size());
- TestCase.assertEquals(2, reply2.getQueues().get(0).getProperties().size());
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.OFPGetConfigReply;
-import org.openflow.codec.protocol.OFPType;
-import org.openflow.codec.util.OFTestCase;
-
-public class OFPSetConfigTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFPGetConfigReply msg = (OFPGetConfigReply) messageFactory.getMessage(OFPType.GET_CONFIG_REPLY);
- msg.setFlags((short) 1);
- IDataBuffer bb = DataBuffers.allocate(1024);
- bb.clear();
- msg.writeTo(bb);
- bb.flip();
- msg.readFrom(bb);
- TestCase.assertEquals(OFPType.GET_CONFIG_REPLY, msg.getType());
- TestCase.assertEquals((short) 1, msg.getFlags());
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import org.openflow.codec.util.OFTestCase;
-
-public class OFPSwitchFeaturesReplyTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- // OFPSwitchFeaturesReply ofr = (OFPSwitchFeaturesReply) messageFactory
- // .getMessage(OFPType.FEATURES_REPLY);
- // List<OFPPort> ports = new ArrayList<OFPPort>();
- // OFPPort port = new OFPPort();
- // port.setHardwareAddress(new byte[6]);
- // port.setName("eth0");
- // ports.add(port);
- // ofr.setPorts(ports);
- // IDataBuffer bb = DataBuffers.createBuffer(1024);
- // bb.clear();
- // ofr.writeTo(bb);
- // bb.flip();
- // ofr.readFrom(bb);
- // TestCase.assertEquals(1, ofr.getPorts().size());
- // TestCase.assertEquals("eth0", ofr.getPorts().get(0).getName());
- //
- // // test a 15 character name
- // ofr.getPorts().get(0).setName("012345678901234");
- // bb.clear();
- // ofr.writeTo(bb);
- // bb.flip();
- // ofr.readFrom(bb);
- // TestCase.assertEquals("012345678901234",
- // ofr.getPorts().get(0).getName());
- //
- // // test a 16 character name getting truncated
- // ofr.getPorts().get(0).setName("0123456789012345");
- // bb.clear();
- // ofr.writeTo(bb);
- // bb.flip();
- // ofr.readFrom(bb);
- // TestCase.assertEquals("012345678901234",
- // ofr.getPorts().get(0).getName());
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol;
-
-import junit.framework.TestCase;
-
-import org.junit.Test;
-import org.openflow.codec.protocol.OFPHello;
-import org.openflow.codec.protocol.OFPMessage;
-import org.openflow.codec.protocol.OFPType;
-
-public class OFPTypeTest extends TestCase {
-
- public void testOFTypeCreate() throws Exception {
- OFPType foo = OFPType.HELLO;
- Class<? extends OFPMessage> c = foo.toClass();
- TestCase.assertEquals(c, OFPHello.class);
- }
-
- @Test
- public void testMapping() throws Exception {
- TestCase.assertEquals(OFPType.HELLO, OFPType.valueOf((byte) 0));
- TestCase.assertEquals(OFPType.BARRIER_REPLY, OFPType.valueOf((byte) 21));
- }
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.action.OFPAction;
-import org.openflow.codec.protocol.action.OFPActionCopyTimeToLiveIn;
-import org.openflow.codec.protocol.action.OFPActionOutput;
-import org.openflow.codec.protocol.factory.OFPBasicFactoryImpl;
-import org.openflow.codec.protocol.factory.OFPActionFactory;
-import org.openflow.codec.protocol.instruction.OFPInstructionApplyActions;
-import org.openflow.codec.protocol.instruction.OFPInstructionClearActions;
-import org.openflow.codec.protocol.instruction.OFPInstructionType;
-import org.openflow.codec.protocol.instruction.OFPInstructionWriteActions;
-
-/**
- * test class to verify instruction structure
- *
- * @author AnilGujele
- *
- */
-public class OFPInstructionActionsTest extends TestCase {
-
- private OFPActionFactory factory = new OFPBasicFactoryImpl();
-
- private IDataBuffer buffer = DataBuffers.allocate(1024);
-
- protected void tearDown() throws Exception {
- buffer.clear();
- }
-
- public void testOFInstructionApplyActions() {
- OFPInstructionApplyActions instruction = new OFPInstructionApplyActions();
- assertTrue(instruction.type.equals(OFPInstructionType.APPLY_ACTIONS));
-
- }
-
- public void testOFInstructionWriteActions() {
- OFPInstructionWriteActions instruction = new OFPInstructionWriteActions();
- assertTrue(instruction.type.equals(OFPInstructionType.WRITE_ACTIONS));
-
- }
-
- public void testOFInstructionClearActions() {
- OFPInstructionClearActions instruction = new OFPInstructionClearActions();
- assertTrue(instruction.type.equals(OFPInstructionType.CLEAR_ACTIONS));
-
- }
-
- public void testClone() throws CloneNotSupportedException {
- OFPInstructionApplyActions instruction = getOFInstructionApplyActions();
- OFPInstructionApplyActions instructionCloned = (OFPInstructionApplyActions) instruction.clone();
- TestCase.assertEquals(instruction, instructionCloned);
-
- OFPAction action = new OFPActionCopyTimeToLiveIn();
- List<OFPAction> actionList = new ArrayList<OFPAction>();
- actionList.add(action);
- instructionCloned.setActions(actionList);
- instructionCloned.setActionFactory(factory);
- TestCase.assertNotSame(instruction, instructionCloned);
-
- instruction = (OFPInstructionApplyActions) instructionCloned.clone();
- TestCase.assertEquals(instruction, instructionCloned);
- }
-
- public void testReadWriteSuccess() {
- OFPInstructionApplyActions instruction = getOFInstructionApplyActions();
-
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionApplyActions instructionTemp = new OFPInstructionApplyActions();
- instructionTemp.setActionFactory(factory);
- instructionTemp.readFrom(buffer);
- TestCase.assertEquals(instruction, instructionTemp);
-
- }
-
- public void testReadWriteFailed() {
- OFPInstructionApplyActions instruction = getOFInstructionApplyActions();
-
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionApplyActions instructionTemp = new OFPInstructionApplyActions();
- boolean result = false;
- try {
- instructionTemp.readFrom(buffer);
- } catch (RuntimeException ex) {
- result = true;
- }
- TestCase.assertTrue(result);
-
- }
-
- public void testToString() {
- OFPInstructionApplyActions instruction = getOFInstructionApplyActions();
-
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionApplyActions instructionTemp = new OFPInstructionApplyActions();
- instructionTemp.setActionFactory(factory);
- instructionTemp.readFrom(buffer);
- TestCase.assertEquals(instruction.toString(), instructionTemp.toString());
- }
-
- public void testEqualHashcode() {
-
- OFPInstructionApplyActions instruction = getOFInstructionApplyActions();
-
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionApplyActions instructionTemp = new OFPInstructionApplyActions();
- instructionTemp.setActionFactory(factory);
- instructionTemp.readFrom(buffer);
-
- TestCase.assertTrue(instruction.equals(instructionTemp));
- TestCase.assertEquals(instruction.hashCode(), instructionTemp.hashCode());
- }
-
- private OFPInstructionApplyActions getOFInstructionApplyActions() {
- OFPInstructionApplyActions instruction = new OFPInstructionApplyActions();
- OFPAction action = new OFPActionOutput();
- List<OFPAction> actionList = new ArrayList<OFPAction>();
- actionList.add(action);
- instruction.setActions(actionList);
- instruction.setActionFactory(factory);
- return instruction;
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.instruction.OFPInstructionExperimenter;
-import org.openflow.codec.protocol.instruction.OFPInstructionType;
-
-/**
- * test class to verify instruction structure
- *
- * @author AnilGujele
- *
- */
-public class OFPInstructionExperimenterTest extends TestCase {
-
- private IDataBuffer buffer = DataBuffers.allocate(1024);
-
- protected void tearDown() throws Exception {
- buffer.clear();
- }
-
- public void testOFInstructionExperimenterCreation() {
- OFPInstructionExperimenter instruction = new OFPInstructionExperimenter();
- assertTrue(instruction.type.equals(OFPInstructionType.EXPERIMENTER));
-
- }
-
- public void testClone() throws CloneNotSupportedException {
- OFPInstructionExperimenter instruction = new OFPInstructionExperimenter();
- instruction.setExperimenterId((byte) 2);
- OFPInstructionExperimenter instructionCloned = (OFPInstructionExperimenter) instruction.clone();
- TestCase.assertEquals(instruction, instructionCloned);
-
- instruction.setExperimenterId((byte) 1);
- TestCase.assertNotSame(instruction, instructionCloned);
-
- instruction = (OFPInstructionExperimenter) instructionCloned.clone();
- TestCase.assertEquals(instruction, instructionCloned);
- }
-
- public void testReadWriteSuccess() {
- OFPInstructionExperimenter instruction = new OFPInstructionExperimenter();
- instruction.setExperimenterId((byte) 2);
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionExperimenter instructionTemp = new OFPInstructionExperimenter();
- instructionTemp.readFrom(buffer);
- TestCase.assertEquals(instruction, instructionTemp);
-
- }
-
- public void testToString() {
- OFPInstructionExperimenter instruction = new OFPInstructionExperimenter();
- instruction.setExperimenterId((byte) 2);
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionExperimenter instructionTemp = new OFPInstructionExperimenter();
- instructionTemp.readFrom(buffer);
- TestCase.assertEquals(instruction.toString(), instructionTemp.toString());
- }
-
- public void testEqualHashcode() {
-
- OFPInstructionExperimenter instruction = new OFPInstructionExperimenter();
- instruction.setExperimenterId((byte) 2);
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionExperimenter instructionTemp = new OFPInstructionExperimenter();
- instructionTemp.readFrom(buffer);
-
- TestCase.assertTrue(instruction.equals(instructionTemp));
- TestCase.assertEquals(instruction.hashCode(), instructionTemp.hashCode());
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.instruction.OFPInstructionGoToTable;
-import org.openflow.codec.protocol.instruction.OFPInstructionType;
-
-/**
- * test class to verify instruction structure
- *
- * @author AnilGujele
- *
- */
-public class OFPInstructionGoToTableTest extends TestCase {
-
- private IDataBuffer buffer = DataBuffers.allocate(1024);
-
- protected void tearDown() throws Exception {
- buffer.clear();
- }
-
- public void testOFInstructionGoToTableCreation() {
- OFPInstructionGoToTable instruction = new OFPInstructionGoToTable();
- assertTrue(instruction.type.equals(OFPInstructionType.GOTO_TABLE));
-
- }
-
- public void testClone() throws CloneNotSupportedException {
- OFPInstructionGoToTable instruction = new OFPInstructionGoToTable();
- instruction.setTableId((byte) 2);
- OFPInstructionGoToTable instructionCloned = (OFPInstructionGoToTable) instruction.clone();
- TestCase.assertEquals(instruction, instructionCloned);
-
- instruction.setTableId((byte) 1);
- TestCase.assertNotSame(instruction, instructionCloned);
-
- instruction = (OFPInstructionGoToTable) instructionCloned.clone();
- TestCase.assertEquals(instruction, instructionCloned);
- }
-
- public void testReadWriteSuccess() {
- OFPInstructionGoToTable instruction = new OFPInstructionGoToTable();
- instruction.setTableId((byte) 2);
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionGoToTable instructionTemp = new OFPInstructionGoToTable();
- instructionTemp.readFrom(buffer);
- TestCase.assertEquals(instruction, instructionTemp);
-
- }
-
- public void testToString() {
- OFPInstructionGoToTable instruction = new OFPInstructionGoToTable();
- instruction.setTableId((byte) 2);
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionGoToTable instructionTemp = new OFPInstructionGoToTable();
- instructionTemp.readFrom(buffer);
- TestCase.assertEquals(instruction.toString(), instructionTemp.toString());
- }
-
- public void testEqualHashcode() {
-
- OFPInstructionGoToTable instruction = new OFPInstructionGoToTable();
- instruction.setTableId((byte) 2);
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionGoToTable instructionTemp = new OFPInstructionGoToTable();
- instructionTemp.readFrom(buffer);
-
- TestCase.assertTrue(instruction.equals(instructionTemp));
- TestCase.assertEquals(instruction.hashCode(), instructionTemp.hashCode());
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.instruction.OFPInstructionMeter;
-import org.openflow.codec.protocol.instruction.OFPInstructionType;
-
-/**
- * test class to verify instruction structure
- *
- * @author AnilGujele
- *
- */
-public class OFPInstructionMeterTest extends TestCase {
-
- private IDataBuffer buffer = DataBuffers.allocate(1024);
-
- protected void tearDown() throws Exception {
- buffer.clear();
- }
-
- public void testOFInstructionMeterCreation() {
- OFPInstructionMeter instruction = new OFPInstructionMeter();
- assertTrue(instruction.type.equals(OFPInstructionType.METER));
-
- }
-
- public void testClone() throws CloneNotSupportedException {
- OFPInstructionMeter instruction = new OFPInstructionMeter();
- instruction.setMeterId((byte) 2);
- OFPInstructionMeter instructionCloned = (OFPInstructionMeter) instruction.clone();
- TestCase.assertEquals(instruction, instructionCloned);
-
- instruction.setMeterId((byte) 1);
- TestCase.assertNotSame(instruction, instructionCloned);
-
- instruction = (OFPInstructionMeter) instructionCloned.clone();
- TestCase.assertEquals(instruction, instructionCloned);
- }
-
- public void testReadWriteSuccess() {
- OFPInstructionMeter instruction = new OFPInstructionMeter();
- instruction.setMeterId((byte) 2);
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionMeter instructionTemp = new OFPInstructionMeter();
- instructionTemp.readFrom(buffer);
- TestCase.assertEquals(instruction, instructionTemp);
-
- }
-
- public void testToString() {
- OFPInstructionMeter instruction = new OFPInstructionMeter();
- instruction.setMeterId((byte) 2);
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionMeter instructionTemp = new OFPInstructionMeter();
- instructionTemp.readFrom(buffer);
- TestCase.assertEquals(instruction.toString(), instructionTemp.toString());
- }
-
- public void testEqualHashcode() {
-
- OFPInstructionMeter instruction = new OFPInstructionMeter();
- instruction.setMeterId((byte) 2);
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionMeter instructionTemp = new OFPInstructionMeter();
- instructionTemp.readFrom(buffer);
-
- TestCase.assertTrue(instruction.equals(instructionTemp));
- TestCase.assertEquals(instruction.hashCode(), instructionTemp.hashCode());
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.instruction;
-
-import junit.framework.TestCase;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.protocol.instruction.OFPInstructionType;
-import org.openflow.codec.protocol.instruction.OFPInstructionWriteMetaData;
-
-/**
- * test class to verify instruction structure
- *
- * @author AnilGujele
- *
- */
-public class OFPInstructionWriteMetaDataTest extends TestCase {
-
- private IDataBuffer buffer = DataBuffers.allocate(1024);
-
- protected void tearDown() throws Exception {
- buffer.clear();
- }
-
- public void testOFInstructionWriteMetaDataCreation() {
- OFPInstructionWriteMetaData instruction = new OFPInstructionWriteMetaData();
- assertTrue(instruction.type.equals(OFPInstructionType.WRITE_METADATA));
-
- }
-
- public void testClone() throws CloneNotSupportedException {
- OFPInstructionWriteMetaData instruction = new OFPInstructionWriteMetaData();
- instruction.setMetadata(2);
- instruction.setMetadataMask(2);
- OFPInstructionWriteMetaData instructionCloned = (OFPInstructionWriteMetaData) instruction.clone();
- TestCase.assertEquals(instruction, instructionCloned);
-
- instruction.setMetadata(1);
- instruction.setMetadataMask(1);
- TestCase.assertNotSame(instruction, instructionCloned);
-
- instruction = (OFPInstructionWriteMetaData) instructionCloned.clone();
- TestCase.assertEquals(instruction, instructionCloned);
- }
-
- public void testReadWriteSuccess() {
- OFPInstructionWriteMetaData instruction = new OFPInstructionWriteMetaData();
- instruction.setMetadata(2);
- instruction.setMetadataMask(2);
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionWriteMetaData instructionTemp = new OFPInstructionWriteMetaData();
- instructionTemp.readFrom(buffer);
- TestCase.assertEquals(instruction, instructionTemp);
-
- }
-
- public void testToString() {
- OFPInstructionWriteMetaData instruction = new OFPInstructionWriteMetaData();
- instruction.setMetadata(2);
- instruction.setMetadataMask(2);
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionWriteMetaData instructionTemp = new OFPInstructionWriteMetaData();
- instructionTemp.readFrom(buffer);
- TestCase.assertEquals(instruction.toString(), instructionTemp.toString());
- }
-
- public void testEqualHashcode() {
-
- OFPInstructionWriteMetaData instruction = new OFPInstructionWriteMetaData();
- instruction.setMetadata(2);
- instruction.setMetadataMask(2);
- instruction.writeTo(buffer);
- buffer.flip();
-
- OFPInstructionWriteMetaData instructionTemp = new OFPInstructionWriteMetaData();
- instructionTemp.readFrom(buffer);
-
- TestCase.assertTrue(instruction.equals(instructionTemp));
- TestCase.assertEquals(instruction.hashCode(), instructionTemp.hashCode());
- }
-
-}
+++ /dev/null
-package org.openflow.codec.protocol.queue;
-
-import junit.framework.TestCase;
-
-import org.junit.Test;
-import org.openflow.codec.protocol.queue.OFPQueuePropertyType;
-
-public class OFPQueuePropertyTypeTest extends TestCase {
- @Test
- public void testMapping() throws Exception {
- TestCase.assertEquals(OFPQueuePropertyType.MIN_RATE, OFPQueuePropertyType.valueOf((short) 1));
- TestCase.assertEquals(OFPQueuePropertyType.MAX_RATE, OFPQueuePropertyType.valueOf((short) 2));
- TestCase.assertEquals(OFPQueuePropertyType.EXPERIMENTER, OFPQueuePropertyType.valueOf((short) 0xffff));
-
- }
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-import org.openflow.codec.util.HexString;
-
-import junit.framework.TestCase;
-
-/**
- * Does hexstring conversion work?
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- *
- */
-
-public class HexStringTest extends TestCase {
-
- public void testMarshalling() throws Exception {
- String dpidStr = "00:00:00:23:20:2d:16:71";
- long dpid = HexString.toLong(dpidStr);
- String testStr = HexString.toHexString(dpid);
- TestCase.assertEquals(dpidStr, testStr);
- }
-
- public void testToStringBytes() {
- byte[] dpid = { 0, 0, 0, 0, 0, 0, 0, -1 };
- String valid = "00:00:00:00:00:00:00:ff";
- String testString = HexString.toHexString(dpid);
- TestCase.assertEquals(valid, testString);
- }
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-import org.openflow.codec.protocol.factory.OFPBasicFactoryImpl;
-import org.openflow.codec.protocol.factory.OFPMessageFactory;
-
-import junit.framework.TestCase;
-
-public class OFTestCase extends TestCase {
- public OFPMessageFactory messageFactory;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- messageFactory = new OFPBasicFactoryImpl();
- }
-
- public void test() throws Exception {
- }
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-import org.openflow.codec.util.U16;
-
-import junit.framework.TestCase;
-
-public class U16Test extends TestCase {
- /**
- * Tests that we correctly translate unsigned values in and out of a short
- *
- * @throws Exception
- */
- public void test() throws Exception {
- int val = 0xffff;
- TestCase.assertEquals((short) -1, U16.t(val));
- TestCase.assertEquals((short) 32767, U16.t(0x7fff));
- TestCase.assertEquals(val, U16.f((short) -1));
- }
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-import org.openflow.codec.util.U32;
-
-import junit.framework.TestCase;
-
-public class U32Test extends TestCase {
- /**
- * Tests that we correctly translate unsigned values in and out of an int
- *
- * @throws Exception
- */
- public void test() throws Exception {
- long val = 0xffffffffL;
- TestCase.assertEquals(-1, U32.t(val));
- TestCase.assertEquals(val, U32.f(-1));
- }
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-import java.math.BigInteger;
-
-import org.openflow.codec.util.U64;
-
-import junit.framework.TestCase;
-
-public class U64Test extends TestCase {
- /**
- * Tests that we correctly translate unsigned values in and out of a long
- *
- * @throws Exception
- */
- public void test() throws Exception {
- BigInteger val = new BigInteger("ffffffffffffffff", 16);
- TestCase.assertEquals(-1, U64.t(val));
- TestCase.assertEquals(val, U64.f(-1));
- }
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-import org.openflow.codec.util.U8;
-
-import junit.framework.TestCase;
-
-public class U8Test extends TestCase {
- /**
- * Tests that we correctly translate unsigned values in and out of a byte
- *
- * @throws Exception
- */
- public void test() throws Exception {
- short val = 0xff;
- TestCase.assertEquals(-1, U8.t(val));
- TestCase.assertEquals(val, U8.f((byte) -1));
- }
-}
+++ /dev/null
-package org.openflow.codec.util;
-
-import java.math.BigInteger;
-
-import org.openflow.codec.io.DataBuffers;
-import org.openflow.codec.io.IDataBuffer;
-import org.openflow.codec.util.Unsigned;
-
-import junit.framework.TestCase;
-
-public class UnsignedTest extends TestCase {
- public static String ULONG_MAX = "18446744073709551615";
-
- /**
- * Tests that we correctly extract an unsigned long into a BigInteger
- *
- * @throws Exception
- */
- public void testGetUnsignedLong() throws Exception {
- IDataBuffer bb = DataBuffers.allocate(8);
- bb.put((byte) 0xff).put((byte) 0xff).put((byte) 0xff).put((byte) 0xff);
- bb.put((byte) 0xff).put((byte) 0xff).put((byte) 0xff).put((byte) 0xff);
- bb.position(0);
- bb.limit(8);
- BigInteger bi = Unsigned.getUnsignedLong(bb);
- BigInteger uLongMax = new BigInteger(ULONG_MAX);
- for (int i = 0; i < uLongMax.bitCount(); ++i) {
- TestCase.assertTrue("Bit: " + i + " should be: " + uLongMax.testBit(i),
- uLongMax.testBit(i) == bi.testBit(i));
- }
- TestCase.assertEquals(ULONG_MAX, bi.toString());
-
- bb = DataBuffers.allocate(10);
- bb.put((byte) 0x00);
- bb.put((byte) 0xff).put((byte) 0xff).put((byte) 0xff).put((byte) 0xff);
- bb.put((byte) 0xff).put((byte) 0xff).put((byte) 0xff).put((byte) 0xff);
- bb.put((byte) 0x00);
- bb.position(0);
- bb.limit(10);
- bi = Unsigned.getUnsignedLong(bb, 1);
- uLongMax = new BigInteger(ULONG_MAX);
- for (int i = 0; i < uLongMax.bitCount(); ++i) {
- TestCase.assertTrue("Bit: " + i + " should be: " + uLongMax.testBit(i),
- uLongMax.testBit(i) == bi.testBit(i));
- }
- TestCase.assertEquals(ULONG_MAX, bi.toString());
- }
-
- /**
- * Tests that we correctly put an unsigned long into a DataBuffer
- *
- * @throws Exception
- */
- public void testPutUnsignedLong() throws Exception {
- IDataBuffer bb = DataBuffers.allocate(8);
- BigInteger uLongMax = new BigInteger(ULONG_MAX);
- Unsigned.putUnsignedLong(bb, uLongMax);
- for (int i = 0; i < 8; ++i) {
- TestCase.assertTrue("Byte: " + i + " should be 0xff, was: " + bb.get(i), (bb.get(i) & (short) 0xff) == 0xff);
- }
-
- bb = DataBuffers.allocate(10);
- Unsigned.putUnsignedLong(bb, uLongMax, 1);
- int offset = 1;
- for (int i = 0; i < 8; ++i) {
- TestCase.assertTrue("Byte: " + i + " should be 0xff, was: " + bb.get(offset + i),
- (bb.get(offset + i) & (short) 0xff) == 0xff);
- }
- }
-}
want to make sure that the openflowJ embedded is picking the
netty one over the non-netty enabled-->
<dependency>
- <groupId>org.opendaylight.controller.thirdparty</groupId>
+ <groupId>org.opendaylight.openflowjava.thirdparty</groupId>
<artifactId>org.openflow.openflowj_netty</artifactId>
<version>1.0.2-SNAPSHOT</version>
</dependency>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <modelVersion>4.0.0</modelVersion>
- <prerequisites>
- <maven>3.0</maven>
- </prerequisites>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>commons.thirdparty</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- <packaging>pom</packaging>
-
- <properties>
- <sonar.host.url>https://sonar.opendaylight.org/</sonar.host.url>
- <nexusproxy>http://nexus.opendaylight.org/content</nexusproxy>
- <sitedeploy>dav:http://nexus.opendaylight.org/content/sites/site</sitedeploy>
- <siteplugin>3.2</siteplugin>
- <projectinfo>2.6</projectinfo>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <compiler.version>2.3.2</compiler.version>
- <surefire.version>2.13</surefire.version>
- </properties>
-
- <pluginRepositories>
- <pluginRepository>
- <id>central2</id>
- <name>central2</name>
- <url>${nexusproxy}/repositories/central2/</url>
- </pluginRepository>
- </pluginRepositories>
-
- <profiles>
- <profile>
- <id>fastreassembly</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.4</version>
- <executions>
- <execution>
- <id>copyfastreassembly</id>
- <phase>install</phase>
- <goals>
- <goal>copy</goal>
- </goals>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>${project.groupId}</groupId>
- <artifactId>${project.artifactId}</artifactId>
- <version>${project.version}</version>
- <destFileName>${project.groupId}.${project.artifactId}-${project.version}.jar</destFileName>
- </artifactItem>
- </artifactItems>
- <outputDirectory>${fastreassembly.directory}</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
- <build>
- <plugins>
- <plugin>
- <groupId>com.googlecode.maven-java-formatter-plugin</groupId>
- <artifactId>maven-java-formatter-plugin</artifactId>
- <version>0.3.1</version>
- <configuration>
- <excludes>
- <exclude>**/*</exclude>
- </excludes>
- </configuration>
- </plugin>
- </plugins>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-site-plugin</artifactId>
- <version>${siteplugin}</version>
- <configuration>
- <reportPlugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <version>${projectinfo}</version>
- <configuration>
- <dependencyDetailsEnabled>false</dependencyDetailsEnabled>
- <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
- </configuration>
- <reports>
- <report>index</report>
- <report>project-team</report>
- <report>license</report>
- <report>mailing-list</report>
- <report>plugin-management</report>
- <report>cim</report>
- <report>issue-tracking</report>
- <report>scm</report>
- <report>summary</report>
- </reports>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <version>2.10</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>2.8.1</version>
- <configuration>
- <doclet>org.jboss.apiviz.APIviz</doclet>
- <docletArtifact>
- <groupId>org.jboss.apiviz</groupId>
- <artifactId>apiviz</artifactId>
- <version>1.3.2.GA</version>
- </docletArtifact>
- <finalName>${project.artifactId}-${build.suffix}</finalName>
- <useStandardDocletOptions>true</useStandardDocletOptions>
- <charset>UTF-8</charset>
- <encoding>UTF-8</encoding>
- <docencoding>UTF-8</docencoding>
- <breakiterator>true</breakiterator>
- <version>true</version>
- <author>true</author>
- <keywords>true</keywords>
- <excludePackageNames>net.sf.jnetlib.*:cern.*:corejava</excludePackageNames>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jxr-plugin</artifactId>
- <version>2.3</version>
- <configuration>
- <aggregate>true</aggregate>
- <linkJavadoc>true</linkJavadoc>
- </configuration>
- </plugin>
- </reportPlugins>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
-
- <repositories>
- <!-- Maven repo2 mirror -->
- <repository>
- <id>central2</id>
- <name>central2</name>
- <url>${nexusproxy}/repositories/central2/</url>
- </repository>
- <!-- Maven repo1 mirror -->
- <repository>
- <id>central</id>
- <name>central</name>
- <url>${nexusproxy}/repositories/central/</url>
- </repository>
- <!-- Third Packages hosted in local maven because not available in
- other places -->
- <repository>
- <id>thirdparty</id>
- <name>thirdparty</name>
- <url>${nexusproxy}/repositories/thirdparty</url>
- </repository>
- </repositories>
- <distributionManagement>
- <!-- OpenDayLight Released artifact -->
- <repository>
- <id>opendaylight-release</id>
- <url>${nexusproxy}/repositories/opendaylight.release/</url>
- </repository>
- <!-- OpenDayLight Snapshot artifact -->
- <snapshotRepository>
- <id>opendaylight-snapshot</id>
- <url>${nexusproxy}/repositories/opendaylight.snapshot/</url>
- </snapshotRepository>
- <!-- Site deployment -->
- <site>
- <id>website</id>
- <url>${sitedeploy}</url>
- </site>
- </distributionManagement>
-</project>
+++ /dev/null
-Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-University
-
-We are making the OpenFlow specification and associated documentation
-(Software) available for public use and benefit with the expectation that
-others will use, modify and enhance the Software and contribute those
-enhancements back to the community. However, since we would like to make the
-Software available for broadest use, with as few restrictions as possible
-permission is hereby granted, free of charge, to any person obtaining a copy of
-this Software to deal in the Software under the copyrights without restriction,
-including without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to permit
-persons to whom the Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-
-The name and trademarks of copyright holder(s) may NOT be used in advertising
-or publicity pertaining to the Software or any derivatives without specific,
-written prior permission.
+++ /dev/null
-# Because I am old and crotchety and my fingers can't stop from running
-# `make` commands
-all:
- ant
-
-run:
- ant run
-
-doc:
- ant javadoc
-
-tests:
- ant tests
-
-count:
- @find . -name \*.java | xargs wc -l | sort -n
-
-clean:
- ant clean
-OpenFlow Java - v1.0.0
+openflowj_netty has been moved to the openflowjava project as
+of Aug 30, 2013:
-A Java implementation of low-level OpenFlow packet marshalling/unmarshalling
-and IO operations. Implements v1.0 of the OpenFlow specification at
-http://www.openflow.org.
+https://git.opendaylight.org/gerrit/#/c/1047/
- - David Erickson (daviderickson@cs.stanford.edu)
- - Rob Sherwood (rob.sherwood@stanford.edu)
+You can include it in your maven project with:
-Building requires Maven 2.x+ (http://maven.apache.org/).
+<repositories>
+ <!-- OpenDayLight Released artifact -->
+ <repository>
+ <id>opendaylight-release</id>
+ <name>opendaylight-release</name>
+ <url>${nexusproxy}/repositories/opendaylight.release/</url>
+ </repository>
+ <!-- OpenDayLight Snapshot artifact -->
+ <repository>
+ <id>opendaylight-snapshot</id>
+ <name>opendaylight-snapshot</name>
+ <url>${nexusproxy}/repositories/opendaylight.snapshot/</url>
+ </repository>
+</repositories>
-To build:
- mvn package
-
-To build javadocs:
- mvn javadoc:javadoc
+<dependency>
+ <groupId>org.opendaylight.openflowjava.thirdparty</groupId>
+ <artifactId>org.openflow.openflowj_netty</artifactId>
+ <version>1.0.2-SNAPSHOT</version>
+</dependency>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<profiles version="11">
-<profile kind="CodeFormatterProfile" name="OpenFlowJ" version="11">
-<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
-<setting id="org.eclipse.jdt.core.compiler.source" value="1.5"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
-<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="80"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
-<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/>
-<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
-<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
-<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
-<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
-<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.5"/>
-<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
-<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="80"/>
-<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
-<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
-<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.5"/>
-<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
-<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
-<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
-<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
-<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
-</profile>
-</profiles>
+++ /dev/null
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.opendaylight.controller.thirdparty</groupId>
- <artifactId>org.openflow.openflowj_netty</artifactId>
- <version>1.0.2-SNAPSHOT</version>
- <name>OpenFlow Java</name>
- <description>A Java implemention of the OpenFlow v1.0 protocol</description>
-
- <!-- Get some common settings for the project we are using it in -->
- <parent>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>commons.thirdparty</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- <relativePath>../commons/thirdparty</relativePath>
- </parent>
-
- <developers>
- <developer>
- <name>David Erickson</name>
- <email>daviderickson@cs.stanford.edu</email>
- </developer>
- <developer>
- <name>Rob Sherwood</name>
- <email>rob.sherwood@stanford.edu</email>
- </developer>
- </developers>
- <packaging>bundle</packaging>
- <url>http://www.openflow.org</url>
- <licenses>
- <license>
- <name>The OpenFlow License</name>
- <url>http://www.openflowswitch.org/wp/legal/</url>
- <distribution>repo</distribution>
- </license>
- </licenses>
- <scm>
- <connection>scm:git://gitosis.stanford.edu:openflowj.git</connection>
- <url>https://openflow.stanford.edu/fisheye/browse/OpenFlowJ</url>
- </scm>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
- <!-- For GPG release signing, use mvn release:perform -->
- <profiles>
- <profile>
- <id>release-sign-artifacts</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-gpg-plugin</artifactId>
- <version>1.1</version>
- <executions>
- <execution>
- <id>sign-artifacts</id>
- <phase>verify</phase>
- <goals>
- <goal>sign</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <mavenExecutorId>forked-path</mavenExecutorId>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>2.3.6</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Import-Package>
- org.jboss.netty.*
- </Import-Package>
- <Export-Package>
- org.openflow.*
- </Export-Package>
- </instructions>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.8.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.netty</groupId>
- <artifactId>netty</artifactId>
- <version>3.2.6.Final</version>
- </dependency>
- </dependencies>
-</project>
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-/**
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public interface Instantiable<E> {
-
- /**
- * Create a new instance of a given subclass.
- * @return the new instance.
- */
- public E instantiate();
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import org.openflow.util.U16;
-
-/**
- * Represents an OFPT_BARRIER_REPLY message
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFBarrierReply extends OFMessage {
- public OFBarrierReply() {
- super();
- this.type = OFType.BARRIER_REPLY;
- this.length = U16.t(OFMessage.MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import org.openflow.util.U16;
-
-/**
- * Represents an OFPT_BARRIER_REQUEST message
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFBarrierRequest extends OFMessage {
- public OFBarrierRequest() {
- super();
- this.type = OFType.BARRIER_REQUEST;
- this.length = U16.t(OFMessage.MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import org.openflow.util.U16;
-
-/**
- * Represents an ofp_echo_reply message
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- */
-
-public class OFEchoReply extends OFEchoRequest {
- public static int MINIMUM_LENGTH = 8;
-
- public OFEchoReply() {
- super();
- this.type = OFType.ECHO_REPLY;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-
-import java.util.Arrays;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.U16;
-
-/**
- * Represents an ofp_echo_request message
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- */
-
-public class OFEchoRequest extends OFMessage {
- public static int MINIMUM_LENGTH = 8;
- byte[] payload;
-
- public OFEchoRequest() {
- super();
- this.type = OFType.ECHO_REQUEST;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- @Override
- public void readFrom(ChannelBuffer bb) {
- super.readFrom(bb);
- int datalen = this.getLengthU() - MINIMUM_LENGTH;
- if (datalen > 0) {
- this.payload = new byte[datalen];
- bb.readBytes(payload);
- }
- }
-
- /**
- * @return the payload
- */
- public byte[] getPayload() {
- return payload;
- }
-
- /**
- * @param payload
- * the payload to set
- */
- public void setPayload(byte[] payload) {
- this.payload = payload;
- }
-
- @Override
- public void writeTo(ChannelBuffer bb) {
- super.writeTo(bb);
- if (payload != null)
- bb.writeBytes(payload);
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + Arrays.hashCode(payload);
- return result;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (getClass() != obj.getClass())
- return false;
- OFEchoRequest other = (OFEchoRequest) obj;
- if (!Arrays.equals(payload, other.payload))
- return false;
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.protocol.factory.MessageParseException;
-import org.openflow.protocol.factory.OFMessageFactory;
-import org.openflow.protocol.factory.OFMessageFactoryAware;
-import org.openflow.util.U16;
-
-/**
- * Represents an ofp_error_msg
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- */
-public class OFError extends OFMessage implements OFMessageFactoryAware {
- public static int MINIMUM_LENGTH = 12;
-
- public enum OFErrorType {
- // OFPET_VENDOR_ERROR is an extension that was added in Open vSwitch and isn't
- // in the OF 1.0 spec, but it was easier to add it here instead of adding
- // generic support for extensible vendor-defined error messages.
- // It uses the random value 0xb0c2 to avoid conflicts with other possible new
- // error types. Support for vendor-defined extended errors has been standardized
- // in the OF 1.2 spec, so this workaround is only needed for 1.0.
- OFPET_HELLO_FAILED, OFPET_BAD_REQUEST, OFPET_BAD_ACTION, OFPET_FLOW_MOD_FAILED, OFPET_PORT_MOD_FAILED, OFPET_QUEUE_OP_FAILED, OFPET_VENDOR_ERROR((short)0xb0c2);
-
- protected short value;
-
- private OFErrorType() {
- this.value = (short) this.ordinal();
- }
-
- private OFErrorType(short value) {
- this.value = value;
- }
-
- public short getValue() {
- return value;
- }
- }
-
- public enum OFHelloFailedCode {
- OFPHFC_INCOMPATIBLE, OFPHFC_EPERM
- }
-
- public enum OFBadRequestCode {
- OFPBRC_BAD_VERSION, OFPBRC_BAD_TYPE, OFPBRC_BAD_STAT, OFPBRC_BAD_VENDOR, OFPBRC_BAD_SUBTYPE, OFPBRC_EPERM, OFPBRC_BAD_LEN, OFPBRC_BUFFER_EMPTY, OFPBRC_BUFFER_UNKNOWN
- }
-
- public enum OFBadActionCode {
- OFPBAC_BAD_TYPE, OFPBAC_BAD_LEN, OFPBAC_BAD_VENDOR, OFPBAC_BAD_VENDOR_TYPE, OFPBAC_BAD_OUT_PORT, OFPBAC_BAD_ARGUMENT, OFPBAC_EPERM, OFPBAC_TOO_MANY, OFPBAC_BAD_QUEUE
- }
-
- public enum OFFlowModFailedCode {
- OFPFMFC_ALL_TABLES_FULL, OFPFMFC_OVERLAP, OFPFMFC_EPERM, OFPFMFC_BAD_EMERG_TIMEOUT, OFPFMFC_BAD_COMMAND, OFPFMFC_UNSUPPORTED
- }
-
- public enum OFPortModFailedCode {
- OFPPMFC_BAD_PORT, OFPPMFC_BAD_HW_ADDR
- }
-
- public enum OFQueueOpFailedCode {
- OFPQOFC_BAD_PORT, OFPQOFC_BAD_QUEUE, OFPQOFC_EPERM
- }
-
- protected short errorType;
- protected short errorCode;
- protected int vendor;
- protected int vendorErrorType;
- protected short vendorErrorCode;
- protected OFMessageFactory factory;
- protected byte[] error;
- protected boolean errorIsAscii;
-
- public OFError() {
- super();
- this.type = OFType.ERROR;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /** convenience constructor */
- public OFError(OFErrorType errorType) {
- this();
- setErrorType(errorType);
- }
-
- /**
- * @return the errorType
- */
- public short getErrorType() {
- return errorType;
- }
-
- /**
- * @param errorType
- * the errorType to set
- */
- public void setErrorType(short errorType) {
- this.errorType = errorType;
- }
-
- public void setErrorType(OFErrorType type) {
- this.errorType = type.getValue();
- }
-
- /**
- * @return true if the error is an extended vendor error
- */
- public boolean isVendorError() {
- return errorType == OFErrorType.OFPET_VENDOR_ERROR.getValue();
- }
-
- /**
- * @return the errorCode
- */
- public short getErrorCode() {
- return errorCode;
- }
-
- /**
- * @param errorCode
- * the errorCode to set
- */
- public void setErrorCode(OFHelloFailedCode code) {
- this.errorCode = (short) code.ordinal();
- }
-
- public void setErrorCode(short errorCode) {
- this.errorCode = errorCode;
- }
-
- public void setErrorCode(OFBadRequestCode code) {
- this.errorCode = (short) code.ordinal();
- }
-
- public void setErrorCode(OFBadActionCode code) {
- this.errorCode = (short) code.ordinal();
- }
-
- public void setErrorCode(OFFlowModFailedCode code) {
- this.errorCode = (short) code.ordinal();
- }
-
- public void setErrorCode(OFPortModFailedCode code) {
- this.errorCode = (short) code.ordinal();
- }
-
- public void setErrorCode(OFQueueOpFailedCode code) {
- this.errorCode = (short) code.ordinal();
- }
-
- public int getVendorErrorType() {
- return vendorErrorType;
- }
-
- public void setVendorErrorType(int vendorErrorType) {
- this.vendorErrorType = vendorErrorType;
- }
-
- public short getVendorErrorCode() {
- return vendorErrorCode;
- }
-
- public void setVendorErrorCode(short vendorErrorCode) {
- this.vendorErrorCode = vendorErrorCode;
- }
-
- public OFMessage getOffendingMsg() throws MessageParseException {
- // should only have one message embedded; if more than one, just
- // grab first
- if (this.error == null)
- return null;
- ChannelBuffer errorMsg = ChannelBuffers.wrappedBuffer(this.error);
- if (factory == null)
- throw new RuntimeException("MessageFactory not set");
-
- List<OFMessage> msglist = this.factory.parseMessage(errorMsg);
- if (msglist == null)
- return null;
- return msglist.get(0);
- }
-
- /**
- * Write this offending message into the payload of the Error message
- *
- * @param offendingMsg
- */
-
- public void setOffendingMsg(OFMessage offendingMsg) {
- if (offendingMsg == null) {
- super.setLengthU(MINIMUM_LENGTH);
- } else {
- this.error = new byte[offendingMsg.getLengthU()];
- ChannelBuffer data = ChannelBuffers.wrappedBuffer(this.error);
- data.writerIndex(0);
- offendingMsg.writeTo(data);
- super.setLengthU(MINIMUM_LENGTH + offendingMsg.getLengthU());
- }
- }
-
- public OFMessageFactory getFactory() {
- return factory;
- }
-
- @Override
- public void setMessageFactory(OFMessageFactory factory) {
- this.factory = factory;
- }
-
- /**
- * @return the error
- */
- public byte[] getError() {
- return error;
- }
-
- /**
- * @param error
- * the error to set
- */
- public void setError(byte[] error) {
- this.error = error;
- }
-
- /**
- * @return the errorIsAscii
- */
- public boolean isErrorIsAscii() {
- return errorIsAscii;
- }
-
- /**
- * @param errorIsAscii
- * the errorIsAscii to set
- */
- public void setErrorIsAscii(boolean errorIsAscii) {
- this.errorIsAscii = errorIsAscii;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.errorType = data.readShort();
- this.errorCode = data.readShort();
- int dataLength = this.getLengthU() - MINIMUM_LENGTH;
- if (dataLength > 0) {
- this.error = new byte[dataLength];
- data.readBytes(this.error);
- if (this.errorType == OFErrorType.OFPET_HELLO_FAILED.getValue())
- this.errorIsAscii = true;
- }
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeShort(errorType);
- data.writeShort(errorCode);
- if (error != null)
- data.writeBytes(error);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + Arrays.hashCode(error);
- result = prime * result + errorCode;
- result = prime * result + (errorIsAscii ? 1231 : 1237);
- result = prime * result + errorType;
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (getClass() != obj.getClass())
- return false;
- OFError other = (OFError) obj;
- if (!Arrays.equals(error, other.error))
- return false;
- if (errorCode != other.errorCode)
- return false;
- if (errorIsAscii != other.errorIsAscii)
- return false;
- if (errorType != other.errorType)
- return false;
- return true;
- }
-
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.U16;
-
-
-/**
- * Represents a features reply message
- * @author David Erickson (daviderickson@cs.stanford.edu)
- *
- */
-
-public class OFFeaturesReply extends OFMessage {
- public static int MINIMUM_LENGTH = 32;
-
- /**
- * Corresponds to bits on the capabilities field
- */
- public enum OFCapabilities {
- OFPC_FLOW_STATS (1 << 0),
- OFPC_TABLE_STATS (1 << 1),
- OFPC_PORT_STATS (1 << 2),
- OFPC_STP (1 << 3),
- OFPC_RESERVED (1 << 4),
- OFPC_IP_REASM (1 << 5),
- OFPC_QUEUE_STATS (1 << 6),
- OFPC_ARP_MATCH_IP (1 << 7);
-
- protected int value;
-
- private OFCapabilities(int value) {
- this.value = value;
- }
-
- /**
- * @return the value
- */
- public int getValue() {
- return value;
- }
- }
-
- protected long datapathId;
- protected int buffers;
- protected byte tables;
- protected int capabilities;
- protected int actions;
- protected List<OFPhysicalPort> ports;
-
- public OFFeaturesReply() {
- super();
- this.type = OFType.FEATURES_REPLY;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * @return the datapathId
- */
- public long getDatapathId() {
- return datapathId;
- }
-
- /**
- * @param datapathId the datapathId to set
- */
- public void setDatapathId(long datapathId) {
- this.datapathId = datapathId;
- }
-
- /**
- * @return the buffers
- */
- public int getBuffers() {
- return buffers;
- }
-
- /**
- * @param buffers the buffers to set
- */
- public void setBuffers(int buffers) {
- this.buffers = buffers;
- }
-
- /**
- * @return the tables
- */
- public byte getTables() {
- return tables;
- }
-
- /**
- * @param tables the tables to set
- */
- public void setTables(byte tables) {
- this.tables = tables;
- }
-
- /**
- * @return the capabilities
- */
- public int getCapabilities() {
- return capabilities;
- }
-
- /**
- * @param capabilities the capabilities to set
- */
- public void setCapabilities(int capabilities) {
- this.capabilities = capabilities;
- }
-
- /**
- * @return the actions
- */
- public int getActions() {
- return actions;
- }
-
- /**
- * @param actions the actions to set
- */
- public void setActions(int actions) {
- this.actions = actions;
- }
-
- /**
- * @return the ports
- */
- public List<OFPhysicalPort> getPorts() {
- return ports;
- }
-
- /**
- * @param ports the ports to set
- */
- public void setPorts(List<OFPhysicalPort> ports) {
- this.ports = ports;
- if (ports == null) {
- this.setLengthU(MINIMUM_LENGTH);
- } else {
- this.setLengthU(MINIMUM_LENGTH + ports.size()
- * OFPhysicalPort.MINIMUM_LENGTH);
- }
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.datapathId = data.readLong();
- this.buffers = data.readInt();
- this.tables = data.readByte();
- data.readerIndex(data.readerIndex() + 3); // pad
- this.capabilities = data.readInt();
- this.actions = data.readInt();
- if (this.ports == null) {
- this.ports = new ArrayList<OFPhysicalPort>();
- } else {
- this.ports.clear();
- }
- int portCount = (super.getLengthU() - 32)
- / OFPhysicalPort.MINIMUM_LENGTH;
- OFPhysicalPort port;
- for (int i = 0; i < portCount; ++i) {
- port = new OFPhysicalPort();
- port.readFrom(data);
- this.ports.add(port);
- }
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeLong(this.datapathId);
- data.writeInt(this.buffers);
- data.writeByte(this.tables);
- data.writeShort((short) 0); // pad
- data.writeByte((byte) 0); // pad
- data.writeInt(this.capabilities);
- data.writeInt(this.actions);
- if (this.ports != null)
- for (OFPhysicalPort port : this.ports) {
- port.writeTo(data);
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 139;
- int result = super.hashCode();
- result = prime * result + actions;
- result = prime * result + buffers;
- result = prime * result + capabilities;
- result = prime * result + (int) (datapathId ^ (datapathId >>> 32));
- result = prime * result + ((ports == null) ? 0 : ports.hashCode());
- result = prime * result + tables;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFFeaturesReply)) {
- return false;
- }
- OFFeaturesReply other = (OFFeaturesReply) obj;
- if (actions != other.actions) {
- return false;
- }
- if (buffers != other.buffers) {
- return false;
- }
- if (capabilities != other.capabilities) {
- return false;
- }
- if (datapathId != other.datapathId) {
- return false;
- }
- if (ports == null) {
- if (other.ports != null) {
- return false;
- }
- } else if (!ports.equals(other.ports)) {
- return false;
- }
- if (tables != other.tables) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import org.openflow.util.U16;
-
-
-/**
- * Represents a features request message
- * @author David Erickson (daviderickson@cs.stanford.edu)
- *
- */
-public class OFFeaturesRequest extends OFMessage {
- public static int MINIMUM_LENGTH = 8;
-
- public OFFeaturesRequest() {
- super();
- this.type = OFType.FEATURES_REQUEST;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.action.OFAction;
-import org.openflow.protocol.factory.OFActionFactory;
-import org.openflow.protocol.factory.OFActionFactoryAware;
-import org.openflow.util.U16;
-
-/**
- * Represents an ofp_flow_mod message
- * @author David Erickson (daviderickson@cs.stanford.edu)
- *
- */
-public class OFFlowMod extends OFMessage implements OFActionFactoryAware, Cloneable {
- public static int MINIMUM_LENGTH = 72;
-
- public static final short OFPFC_ADD = 0; /* New flow. */
- public static final short OFPFC_MODIFY = 1; /* Modify all matching flows. */
- public static final short OFPFC_MODIFY_STRICT = 2; /* Modify entry strictly matching wildcards */
- public static final short OFPFC_DELETE=3; /* Delete all matching flows. */
- public static final short OFPFC_DELETE_STRICT =4; /* Strictly match wildcards and priority. */
-
- // Open Flow Flow Mod Flags. Use "or" operation to set multiple flags
- public static final short OFPFF_SEND_FLOW_REM = 0x1; // 1 << 0
- public static final short OFPFF_CHECK_OVERLAP = 0x2; // 1 << 1
- public static final short OFPFF_EMERG = 0x4; // 1 << 2
-
- protected OFActionFactory actionFactory;
- protected OFMatch match;
- protected long cookie;
- protected short command;
- protected short idleTimeout;
- protected short hardTimeout;
- protected short priority;
- protected int bufferId;
- protected short outPort;
- protected short flags;
- protected List<OFAction> actions;
-
- public OFFlowMod() {
- super();
- this.outPort = OFPort.OFPP_NONE.getValue();
- this.type = OFType.FLOW_MOD;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * Get buffer_id
- * @return
- */
- public int getBufferId() {
- return this.bufferId;
- }
-
- /**
- * Set buffer_id
- * @param bufferId
- */
- public OFFlowMod setBufferId(int bufferId) {
- this.bufferId = bufferId;
- return this;
- }
-
- /**
- * Get cookie
- * @return
- */
- public long getCookie() {
- return this.cookie;
- }
-
- /**
- * Set cookie
- * @param cookie
- */
- public OFFlowMod setCookie(long cookie) {
- this.cookie = cookie;
- return this;
- }
-
- /**
- * Get command
- * @return
- */
- public short getCommand() {
- return this.command;
- }
-
- /**
- * Set command
- * @param command
- */
- public OFFlowMod setCommand(short command) {
- this.command = command;
- return this;
- }
-
- /**
- * Get flags
- * @return
- */
- public short getFlags() {
- return this.flags;
- }
-
- /**
- * Set flags
- * @param flags
- */
- public OFFlowMod setFlags(short flags) {
- this.flags = flags;
- return this;
- }
-
- /**
- * Get hard_timeout
- * @return
- */
- public short getHardTimeout() {
- return this.hardTimeout;
- }
-
- /**
- * Set hard_timeout
- * @param hardTimeout
- */
- public OFFlowMod setHardTimeout(short hardTimeout) {
- this.hardTimeout = hardTimeout;
- return this;
- }
-
- /**
- * Get idle_timeout
- * @return
- */
- public short getIdleTimeout() {
- return this.idleTimeout;
- }
-
- /**
- * Set idle_timeout
- * @param idleTimeout
- */
- public OFFlowMod setIdleTimeout(short idleTimeout) {
- this.idleTimeout = idleTimeout;
- return this;
- }
-
- /**
- * Gets a copy of the OFMatch object for this FlowMod, changes to this
- * object do not modify the FlowMod
- * @return
- */
- public OFMatch getMatch() {
- return this.match;
- }
-
- /**
- * Set match
- * @param match
- */
- public OFFlowMod setMatch(OFMatch match) {
- this.match = match;
- return this;
- }
-
- /**
- * Get out_port
- * @return
- */
- public short getOutPort() {
- return this.outPort;
- }
-
- /**
- * Set out_port
- * @param outPort
- */
- public OFFlowMod setOutPort(short outPort) {
- this.outPort = outPort;
- return this;
- }
-
- /**
- * Set out_port
- * @param port
- */
- public OFFlowMod setOutPort(OFPort port) {
- this.outPort = port.getValue();
- return this;
- }
-
- /**
- * Get priority
- * @return
- */
- public short getPriority() {
- return this.priority;
- }
-
- /**
- * Set priority
- * @param priority
- */
- public OFFlowMod setPriority(short priority) {
- this.priority = priority;
- return this;
- }
-
- /**
- * Returns read-only copies of the actions contained in this Flow Mod
- * @return a list of ordered OFAction objects
- */
- public List<OFAction> getActions() {
- return this.actions;
- }
-
- /**
- * Sets the list of actions this Flow Mod contains
- * @param actions a list of ordered OFAction objects
- */
- public OFFlowMod setActions(List<OFAction> actions) {
- this.actions = actions;
- return this;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- if (this.match == null)
- this.match = new OFMatch();
- this.match.readFrom(data);
- this.cookie = data.readLong();
- this.command = data.readShort();
- this.idleTimeout = data.readShort();
- this.hardTimeout = data.readShort();
- this.priority = data.readShort();
- this.bufferId = data.readInt();
- this.outPort = data.readShort();
- this.flags = data.readShort();
- if (this.actionFactory == null)
- throw new RuntimeException("OFActionFactory not set");
- this.actions = this.actionFactory.parseActions(data, getLengthU() -
- MINIMUM_LENGTH);
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- this.match.writeTo(data);
- data.writeLong(cookie);
- data.writeShort(command);
- data.writeShort(idleTimeout);
- data.writeShort(hardTimeout);
- data.writeShort(priority);
- data.writeInt(bufferId);
- data.writeShort(outPort);
- data.writeShort(flags);
- if (actions != null) {
- for (OFAction action : actions) {
- action.writeTo(data);
- }
- }
- }
-
- @Override
- public void setActionFactory(OFActionFactory actionFactory) {
- this.actionFactory = actionFactory;
- }
-
- @Override
- public int hashCode() {
- final int prime = 227;
- int result = super.hashCode();
- result = prime * result + ((actions == null) ? 0 : actions.hashCode());
- result = prime * result + bufferId;
- result = prime * result + command;
- result = prime * result + (int) (cookie ^ (cookie >>> 32));
- result = prime * result + flags;
- result = prime * result + hardTimeout;
- result = prime * result + idleTimeout;
- result = prime * result + ((match == null) ? 0 : match.hashCode());
- result = prime * result + outPort;
- result = prime * result + priority;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFFlowMod)) {
- return false;
- }
- OFFlowMod other = (OFFlowMod) obj;
- if (actions == null) {
- if (other.actions != null) {
- return false;
- }
- } else if (!actions.equals(other.actions)) {
- return false;
- }
- if (bufferId != other.bufferId) {
- return false;
- }
- if (command != other.command) {
- return false;
- }
- if (cookie != other.cookie) {
- return false;
- }
- if (flags != other.flags) {
- return false;
- }
- if (hardTimeout != other.hardTimeout) {
- return false;
- }
- if (idleTimeout != other.idleTimeout) {
- return false;
- }
- if (match == null) {
- if (other.match != null) {
- return false;
- }
- } else if (!match.equals(other.match)) {
- return false;
- }
- if (outPort != other.outPort) {
- return false;
- }
- if (priority != other.priority) {
- return false;
- }
- return true;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#clone()
- */
- @Override
- public OFFlowMod clone() throws CloneNotSupportedException {
- OFMatch neoMatch = match.clone();
- OFFlowMod flowMod= (OFFlowMod) super.clone();
- flowMod.setMatch(neoMatch);
- List<OFAction> neoActions = new LinkedList<OFAction>();
- for(OFAction action: this.actions)
- neoActions.add((OFAction) action.clone());
- flowMod.setActions(neoActions);
- return flowMod;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "OFFlowMod [actionFactory=" + actionFactory + ", actions="
- + actions + ", bufferId=" + bufferId + ", command=" + command
- + ", cookie=" + cookie + ", flags=" + flags + ", hardTimeout="
- + hardTimeout + ", idleTimeout=" + idleTimeout + ", match="
- + match + ", outPort=" + outPort + ", priority=" + priority
- + ", length=" + length + ", type=" + type + ", version="
- + version + ", xid=" + xid + "]";
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.U16;
-
-/**
- * Represents an ofp_flow_removed message
- * @author David Erickson (daviderickson@cs.stanford.edu)
- *
- */
-public class OFFlowRemoved extends OFMessage {
- public static int MINIMUM_LENGTH = 88;
-
- public enum OFFlowRemovedReason {
- OFPRR_IDLE_TIMEOUT,
- OFPRR_HARD_TIMEOUT,
- OFPRR_DELETE
- }
-
- protected OFMatch match;
- protected long cookie;
- protected short priority;
- protected OFFlowRemovedReason reason;
- protected int durationSeconds;
- protected int durationNanoseconds;
- protected short idleTimeout;
- protected long packetCount;
- protected long byteCount;
-
- public OFFlowRemoved() {
- super();
- this.type = OFType.FLOW_REMOVED;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * Get cookie
- * @return
- */
- public long getCookie() {
- return this.cookie;
- }
-
- /**
- * Set cookie
- * @param cookie
- */
- public void setCookie(long cookie) {
- this.cookie = cookie;
- }
-
- /**
- * Get idle_timeout
- * @return
- */
- public short getIdleTimeout() {
- return this.idleTimeout;
- }
-
- /**
- * Set idle_timeout
- * @param idleTimeout
- */
- public void setIdleTimeout(short idleTimeout) {
- this.idleTimeout = idleTimeout;
- }
-
- /**
- * Gets a copy of the OFMatch object for this FlowMod, changes to this
- * object do not modify the FlowMod
- * @return
- */
- public OFMatch getMatch() {
- return this.match;
- }
-
- /**
- * Set match
- * @param match
- */
- public void setMatch(OFMatch match) {
- this.match = match;
- }
-
- /**
- * Get priority
- * @return
- */
- public short getPriority() {
- return this.priority;
- }
-
- /**
- * Set priority
- * @param priority
- */
- public void setPriority(short priority) {
- this.priority = priority;
- }
-
- /**
- * @return the reason
- */
- public OFFlowRemovedReason getReason() {
- return reason;
- }
-
- /**
- * @param reason the reason to set
- */
- public void setReason(OFFlowRemovedReason reason) {
- this.reason = reason;
- }
-
- /**
- * @return the durationSeconds
- */
- public int getDurationSeconds() {
- return durationSeconds;
- }
-
- /**
- * @param durationSeconds the durationSeconds to set
- */
- public void setDurationSeconds(int durationSeconds) {
- this.durationSeconds = durationSeconds;
- }
-
- /**
- * @return the durationNanoseconds
- */
- public int getDurationNanoseconds() {
- return durationNanoseconds;
- }
-
- /**
- * @param durationNanoseconds the durationNanoseconds to set
- */
- public void setDurationNanoseconds(int durationNanoseconds) {
- this.durationNanoseconds = durationNanoseconds;
- }
-
- /**
- * @return the packetCount
- */
- public long getPacketCount() {
- return packetCount;
- }
-
- /**
- * @param packetCount the packetCount to set
- */
- public void setPacketCount(long packetCount) {
- this.packetCount = packetCount;
- }
-
- /**
- * @return the byteCount
- */
- public long getByteCount() {
- return byteCount;
- }
-
- /**
- * @param byteCount the byteCount to set
- */
- public void setByteCount(long byteCount) {
- this.byteCount = byteCount;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- if (this.match == null)
- this.match = new OFMatch();
- this.match.readFrom(data);
- this.cookie = data.readLong();
- this.priority = data.readShort();
- int reasonIndex = (int)(0xff & data.readByte());
- if (reasonIndex >= OFFlowRemovedReason.values().length) {
- reasonIndex = OFFlowRemovedReason.values().length - 1;
- }
- this.reason = OFFlowRemovedReason.values()[reasonIndex];
- data.readByte(); // pad
- this.durationSeconds = data.readInt();
- this.durationNanoseconds = data.readInt();
- this.idleTimeout = data.readShort();
- data.readByte(); // pad
- data.readByte(); // pad
- this.packetCount = data.readLong();
- this.byteCount = data.readLong();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- this.match.writeTo(data);
- data.writeLong(cookie);
- data.writeShort(priority);
- data.writeByte((byte) this.reason.ordinal());
- data.writeByte((byte) 0);
- data.writeInt(this.durationSeconds);
- data.writeInt(this.durationNanoseconds);
- data.writeShort(idleTimeout);
- data.writeByte((byte) 0); // pad
- data.writeByte((byte) 0); // pad
- data.writeLong(this.packetCount);
- data.writeLong(this.byteCount);
- }
-
- @Override
- public int hashCode() {
- final int prime = 271;
- int result = super.hashCode();
- result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
- result = prime * result + (int) (cookie ^ (cookie >>> 32));
- result = prime * result + durationNanoseconds;
- result = prime * result + durationSeconds;
- result = prime * result + idleTimeout;
- result = prime * result + ((match == null) ? 0 : match.hashCode());
- result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
- result = prime * result + priority;
- result = prime * result + ((reason == null) ? 0 : reason.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFFlowRemoved)) {
- return false;
- }
- OFFlowRemoved other = (OFFlowRemoved) obj;
- if (byteCount != other.byteCount) {
- return false;
- }
- if (cookie != other.cookie) {
- return false;
- }
- if (durationNanoseconds != other.durationNanoseconds) {
- return false;
- }
- if (durationSeconds != other.durationSeconds) {
- return false;
- }
- if (idleTimeout != other.idleTimeout) {
- return false;
- }
- if (match == null) {
- if (other.match != null) {
- return false;
- }
- } else if (!match.equals(other.match)) {
- return false;
- }
- if (packetCount != other.packetCount) {
- return false;
- }
- if (priority != other.priority) {
- return false;
- }
- if (reason == null) {
- if (other.reason != null) {
- return false;
- }
- } else if (!reason.equals(other.reason)) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-/**
- * Represents an OFPT_GET_CONFIG_REPLY type message
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFGetConfigReply extends OFSwitchConfig {
- public OFGetConfigReply() {
- super();
- this.type = OFType.GET_CONFIG_REPLY;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import org.openflow.util.U16;
-
-/**
- * Represents an OFPT_GET_CONFIG_REQUEST type message
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFGetConfigRequest extends OFMessage {
- public OFGetConfigRequest() {
- super();
- this.type = OFType.GET_CONFIG_REQUEST;
- this.length = U16.t(OFMessage.MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import org.openflow.util.U16;
-
-
-/**
- * Represents an ofp_hello message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu) - Feb 8, 2010
- */
-public class OFHello extends OFMessage {
- public static int MINIMUM_LENGTH = 8;
-
- /**
- * Construct a ofp_hello message
- */
- public OFHello() {
- super();
- this.type = OFType.HELLO;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-/**
- * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
- * University
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License. You may obtain
- * a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- **/
-
-package org.openflow.protocol;
-
-import java.io.Serializable;
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.HexString;
-import org.openflow.util.U16;
-import org.openflow.util.U8;
-
-/**
- * Represents an ofp_match structure
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- */
-public class OFMatch implements Cloneable, Serializable {
-
- /**
- *
- */
-
- public static final short VLAN_UNTAGGED = (short)0xffff;
-
- private static final long serialVersionUID = 1L;
- public static int MINIMUM_LENGTH = 40;
- final public static int OFPFW_ALL = ((1 << 22) - 1);
-
- final public static int OFPFW_IN_PORT = 1 << 0; /* Switch input port. */
- final public static int OFPFW_DL_VLAN = 1 << 1; /* VLAN id. */
- final public static int OFPFW_DL_SRC = 1 << 2; /* Ethernet source address. */
- final public static int OFPFW_DL_DST = 1 << 3; /*
- * Ethernet destination
- * address.
- */
- final public static int OFPFW_DL_TYPE = 1 << 4; /* Ethernet frame type. */
- final public static int OFPFW_NW_PROTO = 1 << 5; /* IP protocol. */
- final public static int OFPFW_TP_SRC = 1 << 6; /* TCP/UDP source port. */
- final public static int OFPFW_TP_DST = 1 << 7; /* TCP/UDP destination port. */
-
- /*
- * IP source address wildcard bit count. 0 is exact match, 1 ignores the
- * LSB, 2 ignores the 2 least-significant bits, ..., 32 and higher wildcard
- * the entire field. This is the *opposite* of the usual convention where
- * e.g. /24 indicates that 8 bits (not 24 bits) are wildcarded.
- */
- final public static int OFPFW_NW_SRC_SHIFT = 8;
- final public static int OFPFW_NW_SRC_BITS = 6;
- final public static int OFPFW_NW_SRC_MASK = ((1 << OFPFW_NW_SRC_BITS) - 1) << OFPFW_NW_SRC_SHIFT;
- final public static int OFPFW_NW_SRC_ALL = 32 << OFPFW_NW_SRC_SHIFT;
-
- /* IP destination address wildcard bit count. Same format as source. */
- final public static int OFPFW_NW_DST_SHIFT = 14;
- final public static int OFPFW_NW_DST_BITS = 6;
- final public static int OFPFW_NW_DST_MASK = ((1 << OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT;
- final public static int OFPFW_NW_DST_ALL = 32 << OFPFW_NW_DST_SHIFT;
-
- final public static int OFPFW_DL_VLAN_PCP = 1 << 20; /* VLAN priority. */
- final public static int OFPFW_NW_TOS = 1 << 21; /*
- * IP ToS (DSCP field, 6
- * bits).
- */
-
- final public static int OFPFW_ALL_SANITIZED = (((1 << 22) - 1)
- & ~OFPFW_NW_SRC_MASK & ~OFPFW_NW_DST_MASK)
- | OFPFW_NW_SRC_ALL
- | OFPFW_NW_DST_ALL;
-
- /* List of Strings for marshalling and unmarshalling to human readable forms */
- final public static String STR_IN_PORT = "in_port";
- final public static String STR_DL_DST = "dl_dst";
- final public static String STR_DL_SRC = "dl_src";
- final public static String STR_DL_TYPE = "dl_type";
- final public static String STR_DL_VLAN = "dl_vlan";
- final public static String STR_DL_VLAN_PCP = "dl_vlan_pcp";
- final public static String STR_NW_DST = "nw_dst";
- final public static String STR_NW_SRC = "nw_src";
- final public static String STR_NW_PROTO = "nw_proto";
- final public static String STR_NW_TOS = "nw_tos";
- final public static String STR_TP_DST = "tp_dst";
- final public static String STR_TP_SRC = "tp_src";
-
- protected int wildcards;
- protected short inputPort;
- protected byte[] dataLayerSource;
- protected byte[] dataLayerDestination;
- protected short dataLayerVirtualLan;
- protected byte dataLayerVirtualLanPriorityCodePoint;
- protected short dataLayerType;
- protected byte networkTypeOfService;
- protected byte networkProtocol;
- protected int networkSource;
- protected int networkDestination;
- protected short transportSource;
- protected short transportDestination;
-
- /**
- * By default, create a OFMatch that matches everything (mostly because it's
- * the least amount of work to make a valid OFMatch)
- */
- public OFMatch() {
- this.wildcards = OFPFW_ALL;
- this.dataLayerDestination = new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0,
- 0x0 };
- this.dataLayerSource = new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
- this.dataLayerVirtualLan = VLAN_UNTAGGED;
- this.dataLayerVirtualLanPriorityCodePoint = 0;
- this.dataLayerType = 0;
- this.inputPort = 0;
- this.networkProtocol = 0;
- this.networkTypeOfService = 0;
- this.networkSource = 0;
- this.networkDestination = 0;
- this.transportDestination = 0;
- this.transportSource = 0;
- }
-
- /**
- * Get dl_dst
- *
- * @return an arrays of bytes
- */
- public byte[] getDataLayerDestination() {
- return this.dataLayerDestination;
- }
-
- /**
- * Set dl_dst
- *
- * @param dataLayerDestination
- */
- public OFMatch setDataLayerDestination(byte[] dataLayerDestination) {
- this.dataLayerDestination = dataLayerDestination;
- return this;
- }
-
- /**
- * Set dl_dst, but first translate to byte[] using HexString
- *
- * @param mac
- * A colon separated string of 6 pairs of octets, e..g.,
- * "00:17:42:EF:CD:8D"
- */
- public OFMatch setDataLayerDestination(String mac) {
- byte bytes[] = HexString.fromHexString(mac);
- if (bytes.length != 6)
- throw new IllegalArgumentException(
- "expected string with 6 octets, got '"
- + mac
- + "'");
- this.dataLayerDestination = bytes;
- return this;
- }
-
- /**
- * Get dl_src
- *
- * @return an array of bytes
- */
- public byte[] getDataLayerSource() {
- return this.dataLayerSource;
- }
-
- /**
- * Set dl_src
- *
- * @param dataLayerSource
- */
- public OFMatch setDataLayerSource(byte[] dataLayerSource) {
- this.dataLayerSource = dataLayerSource;
- return this;
- }
-
- /**
- * Set dl_src, but first translate to byte[] using HexString
- *
- * @param mac
- * A colon separated string of 6 pairs of octets, e..g.,
- * "00:17:42:EF:CD:8D"
- */
- public OFMatch setDataLayerSource(String mac) {
- byte bytes[] = HexString.fromHexString(mac);
- if (bytes.length != 6)
- throw new IllegalArgumentException(
- "expected string with 6 octets, got '"
- + mac
- + "'");
- this.dataLayerSource = bytes;
- return this;
- }
-
- /**
- * Get dl_type
- *
- * @return ether_type
- */
- public short getDataLayerType() {
- return this.dataLayerType;
- }
-
- /**
- * Set dl_type
- *
- * @param dataLayerType
- */
- public OFMatch setDataLayerType(short dataLayerType) {
- this.dataLayerType = dataLayerType;
- return this;
- }
-
- /**
- * Get dl_vlan
- *
- * @return vlan tag; VLAN_NONE == no tag
- */
- public short getDataLayerVirtualLan() {
- return this.dataLayerVirtualLan;
- }
-
- /**
- * Set dl_vlan
- *
- * @param dataLayerVirtualLan
- */
- public OFMatch setDataLayerVirtualLan(short dataLayerVirtualLan) {
- this.dataLayerVirtualLan = dataLayerVirtualLan;
- return this;
- }
-
- /**
- * Get dl_vlan_pcp
- *
- * @return
- */
- public byte getDataLayerVirtualLanPriorityCodePoint() {
- return this.dataLayerVirtualLanPriorityCodePoint;
- }
-
- /**
- * Set dl_vlan_pcp
- *
- * @param pcp
- */
- public OFMatch setDataLayerVirtualLanPriorityCodePoint(byte pcp) {
- this.dataLayerVirtualLanPriorityCodePoint = pcp;
- return this;
- }
-
- /**
- * Get in_port
- *
- * @return
- */
- public short getInputPort() {
- return this.inputPort;
- }
-
- /**
- * Set in_port
- *
- * @param inputPort
- */
- public OFMatch setInputPort(short inputPort) {
- this.inputPort = inputPort;
- return this;
- }
-
- /**
- * Get nw_dst
- *
- * @return
- */
- public int getNetworkDestination() {
- return this.networkDestination;
- }
-
- /**
- * Set nw_dst
- *
- * @param networkDestination
- */
- public OFMatch setNetworkDestination(int networkDestination) {
- this.networkDestination = networkDestination;
- return this;
- }
-
- /**
- * Parse this match's wildcard fields and return the number of significant
- * bits in the IP destination field. NOTE: this returns the number of bits
- * that are fixed, i.e., like CIDR, not the number of bits that are free
- * like OpenFlow encodes.
- *
- * @return a number between 0 (matches all IPs) and 63 ( 32>= implies exact
- * match)
- */
- public int getNetworkDestinationMaskLen() {
- return Math.max(32 - ((wildcards & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT),
- 0);
- }
-
- /**
- * Parse this match's wildcard fields and return the number of significant
- * bits in the IP destination field. NOTE: this returns the number of bits
- * that are fixed, i.e., like CIDR, not the number of bits that are free
- * like OpenFlow encodes.
- *
- * @return a number between 0 (matches all IPs) and 32 (exact match)
- */
- public int getNetworkSourceMaskLen() {
- return Math.max(32 - ((wildcards & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT),
- 0);
- }
-
- /**
- * Get nw_proto
- *
- * @return
- */
- public byte getNetworkProtocol() {
- return this.networkProtocol;
- }
-
- /**
- * Set nw_proto
- *
- * @param networkProtocol
- */
- public OFMatch setNetworkProtocol(byte networkProtocol) {
- this.networkProtocol = networkProtocol;
- return this;
- }
-
- /**
- * Get nw_src
- *
- * @return
- */
- public int getNetworkSource() {
- return this.networkSource;
- }
-
- /**
- * Set nw_src
- *
- * @param networkSource
- */
- public OFMatch setNetworkSource(int networkSource) {
- this.networkSource = networkSource;
- return this;
- }
-
- /**
- * Get nw_tos OFMatch stores the ToS bits as top 6-bits, so right shift by 2
- * bits before returning the value
- *
- * @return : 6-bit DSCP value (0-63)
- */
- public byte getNetworkTypeOfService() {
- return (byte) ((this.networkTypeOfService >> 2) & 0x3f);
- }
-
- /**
- * Set nw_tos OFMatch stores the ToS bits as top 6-bits, so left shift by 2
- * bits before storing the value
- *
- * @param networkTypeOfService
- * : 6-bit DSCP value (0-63)
- */
- public OFMatch setNetworkTypeOfService(byte networkTypeOfService) {
- this.networkTypeOfService = (byte) (networkTypeOfService << 2);
- return this;
- }
-
- /**
- * Get tp_dst
- *
- * @return
- */
- public short getTransportDestination() {
- return this.transportDestination;
- }
-
- /**
- * Set tp_dst
- *
- * @param transportDestination
- */
- public OFMatch setTransportDestination(short transportDestination) {
- this.transportDestination = transportDestination;
- return this;
- }
-
- /**
- * Get tp_src
- *
- * @return
- */
- public short getTransportSource() {
- return this.transportSource;
- }
-
- /**
- * Set tp_src
- *
- * @param transportSource
- */
- public OFMatch setTransportSource(short transportSource) {
- this.transportSource = transportSource;
- return this;
- }
-
- /**
- * Get wildcards
- *
- * @return
- */
- public int getWildcards() {
- return this.wildcards;
- }
-
- /**
- * Get wildcards
- *
- * @return
- */
- public Wildcards getWildcardObj() {
- return Wildcards.of(wildcards);
- }
-
- /**
- * Set wildcards
- *
- * @param wildcards
- */
- public OFMatch setWildcards(int wildcards) {
- this.wildcards = wildcards;
- return this;
- }
-
- /** set the wildcard using the Wildcards convenience object */
- public OFMatch setWildcards(Wildcards wildcards) {
- this.wildcards = wildcards.getInt();
- return this;
- }
-
- /**
- * Initializes this OFMatch structure with the corresponding data from the
- * specified packet. Must specify the input port, to ensure that
- * this.in_port is set correctly. Specify OFPort.NONE or OFPort.ANY if input
- * port not applicable or available
- *
- * @param packetData
- * The packet's data
- * @param inputPort
- * the port the packet arrived on
- */
- public OFMatch loadFromPacket(byte[] packetData, short inputPort) {
- short scratch;
- int transportOffset = 34;
- ByteBuffer packetDataBB = ByteBuffer.wrap(packetData);
- int limit = packetDataBB.limit();
-
- this.wildcards = 0; // all fields have explicit entries
-
- this.inputPort = inputPort;
-
- if (inputPort == OFPort.OFPP_ALL.getValue())
- this.wildcards |= OFPFW_IN_PORT;
-
- assert (limit >= 14);
- // dl dst
- this.dataLayerDestination = new byte[6];
- packetDataBB.get(this.dataLayerDestination);
- // dl src
- this.dataLayerSource = new byte[6];
- packetDataBB.get(this.dataLayerSource);
- // dl type
- this.dataLayerType = packetDataBB.getShort();
-
- if (getDataLayerType() != (short) 0x8100) { // need cast to avoid signed
- // bug
- setDataLayerVirtualLan((short) 0xffff);
- setDataLayerVirtualLanPriorityCodePoint((byte) 0);
- } else {
- // has vlan tag
- scratch = packetDataBB.getShort();
- setDataLayerVirtualLan((short) (0xfff & scratch));
- setDataLayerVirtualLanPriorityCodePoint((byte) ((0xe000 & scratch) >> 13));
- this.dataLayerType = packetDataBB.getShort();
- }
-
- switch (getDataLayerType()) {
- case 0x0800:
- // ipv4
- // check packet length
- scratch = packetDataBB.get();
- scratch = (short) (0xf & scratch);
- transportOffset = (packetDataBB.position() - 1)
- + (scratch * 4);
- // nw tos (dscp)
- scratch = packetDataBB.get();
- setNetworkTypeOfService((byte) ((0xfc & scratch) >> 2));
- // nw protocol
- packetDataBB.position(packetDataBB.position() + 7);
- this.networkProtocol = packetDataBB.get();
- // nw src
- packetDataBB.position(packetDataBB.position() + 2);
- this.networkSource = packetDataBB.getInt();
- // nw dst
- this.networkDestination = packetDataBB.getInt();
- packetDataBB.position(transportOffset);
- break;
- case 0x0806:
- // arp
- int arpPos = packetDataBB.position();
- // opcode
- scratch = packetDataBB.getShort(arpPos + 6);
- setNetworkProtocol((byte) (0xff & scratch));
-
- scratch = packetDataBB.getShort(arpPos + 2);
- // if ipv4 and addr len is 4
- if (scratch == 0x800 && packetDataBB.get(arpPos + 5) == 4) {
- // nw src
- this.networkSource = packetDataBB.getInt(arpPos + 14);
- // nw dst
- this.networkDestination = packetDataBB.getInt(arpPos + 24);
- } else {
- setNetworkSource(0);
- setNetworkDestination(0);
- }
- break;
- default:
- setNetworkTypeOfService((byte) 0);
- setNetworkProtocol((byte) 0);
- setNetworkSource(0);
- setNetworkDestination(0);
- break;
- }
-
- switch (getNetworkProtocol()) {
- case 0x01:
- // icmp
- // type
- this.transportSource = U8.f(packetDataBB.get());
- // code
- this.transportDestination = U8.f(packetDataBB.get());
- break;
- case 0x06:
- // tcp
- // tcp src
- this.transportSource = packetDataBB.getShort();
- // tcp dest
- this.transportDestination = packetDataBB.getShort();
- break;
- case 0x11:
- // udp
- // udp src
- this.transportSource = packetDataBB.getShort();
- // udp dest
- this.transportDestination = packetDataBB.getShort();
- break;
- default:
- setTransportDestination((short) 0);
- setTransportSource((short) 0);
- break;
- }
- return this;
- }
-
- /**
- * Read this message off the wire from the specified ByteBuffer
- *
- * @param data
- */
- public void readFrom(ChannelBuffer data) {
- this.wildcards = data.readInt();
- this.inputPort = data.readShort();
- this.dataLayerSource = new byte[6];
- data.readBytes(this.dataLayerSource);
- this.dataLayerDestination = new byte[6];
- data.readBytes(this.dataLayerDestination);
- this.dataLayerVirtualLan = data.readShort();
- this.dataLayerVirtualLanPriorityCodePoint = data.readByte();
- data.readByte(); // pad
- this.dataLayerType = data.readShort();
- this.networkTypeOfService = data.readByte();
- this.networkProtocol = data.readByte();
- data.readByte(); // pad
- data.readByte(); // pad
- this.networkSource = data.readInt();
- this.networkDestination = data.readInt();
- this.transportSource = data.readShort();
- this.transportDestination = data.readShort();
- }
-
- /**
- * Write this message's binary format to the specified ByteBuffer
- *
- * @param data
- */
- public void writeTo(ChannelBuffer data) {
- data.writeInt(wildcards);
- data.writeShort(inputPort);
- data.writeBytes(this.dataLayerSource);
- data.writeBytes(this.dataLayerDestination);
- data.writeShort(dataLayerVirtualLan);
- data.writeByte(dataLayerVirtualLanPriorityCodePoint);
- data.writeByte((byte) 0x0); // pad
- data.writeShort(dataLayerType);
- data.writeByte(networkTypeOfService);
- data.writeByte(networkProtocol);
- data.writeByte((byte) 0x0); // pad
- data.writeByte((byte) 0x0); // pad
- data.writeInt(networkSource);
- data.writeInt(networkDestination);
- data.writeShort(transportSource);
- data.writeShort(transportDestination);
- }
-
- @Override
- public int hashCode() {
- final int prime = 131;
- int result = 1;
- result = prime * result + Arrays.hashCode(dataLayerDestination);
- result = prime * result + Arrays.hashCode(dataLayerSource);
- result = prime * result + dataLayerType;
- result = prime * result + dataLayerVirtualLan;
- result = prime * result + dataLayerVirtualLanPriorityCodePoint;
- result = prime * result + inputPort;
- result = prime * result + networkDestination;
- result = prime * result + networkProtocol;
- result = prime * result + networkSource;
- result = prime * result + networkTypeOfService;
- result = prime * result + transportDestination;
- result = prime * result + transportSource;
- result = prime * result + wildcards;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFMatch)) {
- return false;
- }
- OFMatch other = (OFMatch) obj;
- if (!Arrays.equals(dataLayerDestination, other.dataLayerDestination)) {
- return false;
- }
- if (!Arrays.equals(dataLayerSource, other.dataLayerSource)) {
- return false;
- }
- if (dataLayerType != other.dataLayerType) {
- return false;
- }
- if (dataLayerVirtualLan != other.dataLayerVirtualLan) {
- return false;
- }
- if (dataLayerVirtualLanPriorityCodePoint != other.dataLayerVirtualLanPriorityCodePoint) {
- return false;
- }
- if (inputPort != other.inputPort) {
- return false;
- }
- if (networkDestination != other.networkDestination) {
- return false;
- }
- if (networkProtocol != other.networkProtocol) {
- return false;
- }
- if (networkSource != other.networkSource) {
- return false;
- }
- if (networkTypeOfService != other.networkTypeOfService) {
- return false;
- }
- if (transportDestination != other.transportDestination) {
- return false;
- }
- if (transportSource != other.transportSource) {
- return false;
- }
- if ((wildcards & OFMatch.OFPFW_ALL) != (other.wildcards & OFPFW_ALL)) { // only
- // consider
- // allocated
- // part
- // of
- // wildcards
- return false;
- }
- return true;
- }
-
- /**
- * Implement clonable interface
- */
- @Override
- public OFMatch clone() {
- try {
- OFMatch ret = (OFMatch) super.clone();
- ret.dataLayerDestination = this.dataLayerDestination.clone();
- ret.dataLayerSource = this.dataLayerSource.clone();
- return ret;
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Output a dpctl-styled string, i.e., only list the elements that are not
- * wildcarded A match-everything OFMatch outputs "OFMatch[]"
- *
- * @return
- * "OFMatch[dl_src:00:20:01:11:22:33,nw_src:192.168.0.0/24,tp_dst:80]"
- */
- @Override
- public String toString() {
- String str = "";
-
- // l1
- if ((wildcards & OFPFW_IN_PORT) == 0)
- str += "," + STR_IN_PORT + "="
- + U16.f(this.inputPort);
-
- // l2
- if ((wildcards & OFPFW_DL_DST) == 0)
- str += ","
- + STR_DL_DST
- + "="
- + HexString.toHexString(this.dataLayerDestination);
- if ((wildcards & OFPFW_DL_SRC) == 0)
- str += ","
- + STR_DL_SRC
- + "="
- + HexString.toHexString(this.dataLayerSource);
- if ((wildcards & OFPFW_DL_TYPE) == 0)
- str += ","
- + STR_DL_TYPE
- + "=0x"
- + Integer.toHexString(U16.f(this.dataLayerType));
- if ((wildcards & OFPFW_DL_VLAN) == 0)
- str += ","
- + STR_DL_VLAN
- + "=0x"
- + Integer.toHexString(U16.f(this.dataLayerVirtualLan));
- if ((wildcards & OFPFW_DL_VLAN_PCP) == 0)
- str += ","
- + STR_DL_VLAN_PCP
- + "="
- + Integer.toHexString(U8.f(this.dataLayerVirtualLanPriorityCodePoint));
-
- // l3
- if (getNetworkDestinationMaskLen() > 0)
- str += ","
- + STR_NW_DST
- + "="
- + cidrToString(networkDestination,
- getNetworkDestinationMaskLen());
- if (getNetworkSourceMaskLen() > 0)
- str += ","
- + STR_NW_SRC
- + "="
- + cidrToString(networkSource,
- getNetworkSourceMaskLen());
- if ((wildcards & OFPFW_NW_PROTO) == 0)
- str += "," + STR_NW_PROTO
- + "="
- + this.networkProtocol;
- if ((wildcards & OFPFW_NW_TOS) == 0)
- str += ","
- + STR_NW_TOS
- + "="
- + this.getNetworkTypeOfService();
-
- // l4
- if ((wildcards & OFPFW_TP_DST) == 0)
- str += ","
- + STR_TP_DST
- + "="
- + this.transportDestination;
- if ((wildcards & OFPFW_TP_SRC) == 0)
- str += "," + STR_TP_SRC + "="
- + this.transportSource;
- if ((str.length() > 0) && (str.charAt(0) == ','))
- str = str.substring(1); // trim
- // the
- // leading
- // ","
- // done
- return "OFMatch[" + str + "]";
- }
-
- /**
- * debug a set of wildcards
- */
- public static String debugWildCards(int wildcards) {
- String str = "";
-
- // l1
- if ((wildcards & OFPFW_IN_PORT) != 0) str += "|" + STR_IN_PORT;
-
- // l2
- if ((wildcards & OFPFW_DL_DST) != 0) str += "|" + STR_DL_DST;
- if ((wildcards & OFPFW_DL_SRC) != 0) str += "|" + STR_DL_SRC;
- if ((wildcards & OFPFW_DL_TYPE) != 0) str += "|" + STR_DL_TYPE;
- if ((wildcards & OFPFW_DL_VLAN) != 0) str += "|" + STR_DL_VLAN;
- if ((wildcards & OFPFW_DL_VLAN_PCP) != 0)
- str += "|"
- + STR_DL_VLAN_PCP;
-
- int nwDstMask = Math.max(32 - ((wildcards & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT),
- 0);
- int nwSrcMask = Math.max(32 - ((wildcards & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT),
- 0);
-
- // l3
- if (nwDstMask < 32)
- str += "|" + STR_NW_DST + "(/" + nwDstMask + ")";
-
- if (nwSrcMask < 32)
- str += "|" + STR_NW_SRC + "(/" + nwSrcMask + ")";
-
- if ((wildcards & OFPFW_NW_PROTO) != 0) str += "|" + STR_NW_PROTO;
- if ((wildcards & OFPFW_NW_TOS) != 0) str += "|" + STR_NW_TOS;
-
- // l4
- if ((wildcards & OFPFW_TP_DST) != 0) str += "|" + STR_TP_DST;
- if ((wildcards & OFPFW_TP_SRC) != 0) str += "|" + STR_TP_SRC;
- if ((str.length() > 0) && (str.charAt(0) == '|'))
- str = str.substring(1); // trim
- // the
- // leading
- // ","
- // done
- return str;
- }
-
- private String cidrToString(int ip, int prefix) {
- String str;
- if (prefix >= 32) {
- str = ipToString(ip);
- } else {
- // use the negation of mask to fake endian magic
- int mask = ~((1 << (32 - prefix)) - 1);
- str = ipToString(ip & mask) + "/" + prefix;
- }
-
- return str;
- }
-
- /**
- * Set this OFMatch's parameters based on a comma-separated key=value pair
- * dpctl-style string, e.g., from the output of OFMatch.toString() <br>
- * <p>
- * Supported keys/values include <br>
- * <p>
- * <TABLE border=1>
- * <TR>
- * <TD>KEY(s)
- * <TD>VALUE
- * </TR>
- * <TR>
- * <TD>"in_port","input_port"
- * <TD>integer
- * </TR>
- * <TR>
- * <TD>"dl_src","eth_src", "dl_dst","eth_dst"
- * <TD>hex-string
- * </TR>
- * <TR>
- * <TD>"dl_type", "dl_vlan", "dl_vlan_pcp"
- * <TD>integer
- * </TR>
- * <TR>
- * <TD>"nw_src", "nw_dst", "ip_src", "ip_dst"
- * <TD>CIDR-style netmask
- * </TR>
- * <TR>
- * <TD>"tp_src","tp_dst"
- * <TD>integer (max 64k)
- * </TR>
- * </TABLE>
- * <p>
- * The CIDR-style netmasks assume 32 netmask if none given, so:
- * "128.8.128.118/32" is the same as "128.8.128.118"
- *
- * @param match
- * a key=value comma separated string, e.g.
- * "in_port=5,ip_dst=192.168.0.0/16,tp_src=80"
- * @throws IllegalArgumentException
- * on unexpected key or value
- */
-
- public void fromString(String match) throws IllegalArgumentException {
- if (match.equals("") || match.equalsIgnoreCase("any")
- || match.equalsIgnoreCase("all") || match.equals("[]"))
- match = "OFMatch[]";
- String[] tokens = match.split("[\\[,\\]]");
- String[] values;
- int initArg = 0;
- if (tokens[0].equals("OFMatch")) initArg = 1;
- this.wildcards = OFPFW_ALL;
- int i;
- for (i = initArg; i < tokens.length; i++) {
- values = tokens[i].split("=");
- if (values.length != 2)
- throw new IllegalArgumentException(
- "Token "
- + tokens[i]
- + " does not have form 'key=value' parsing "
- + match);
- values[0] = values[0].toLowerCase(); // try to make this case insens
- if (values[0].equals(STR_IN_PORT)
- || values[0].equals("input_port")) {
- this.inputPort = U16.t(Integer.valueOf(values[1]));
- this.wildcards &= ~OFPFW_IN_PORT;
- } else if (values[0].equals(STR_DL_DST)
- || values[0].equals("eth_dst")) {
- this.dataLayerDestination = HexString.fromHexString(values[1]);
- this.wildcards &= ~OFPFW_DL_DST;
- } else if (values[0].equals(STR_DL_SRC)
- || values[0].equals("eth_src")) {
- this.dataLayerSource = HexString.fromHexString(values[1]);
- this.wildcards &= ~OFPFW_DL_SRC;
- } else if (values[0].equals(STR_DL_TYPE)
- || values[0].equals("eth_type")) {
- if (values[1].startsWith("0x"))
- this.dataLayerType = U16.t(Integer.valueOf(values[1].replaceFirst("0x",
- ""),
- 16));
- else
- this.dataLayerType = U16.t(Integer.valueOf(values[1]));
- this.wildcards &= ~OFPFW_DL_TYPE;
- } else if (values[0].equals(STR_DL_VLAN)) {
- if (values[1].startsWith("0x"))
- this.dataLayerVirtualLan = U16.t(Integer.valueOf(values[1].replaceFirst("0x",
- ""),
- 16));
- else
- this.dataLayerVirtualLan = U16.t(Integer.valueOf(values[1]));
- this.wildcards &= ~OFPFW_DL_VLAN;
- } else if (values[0].equals(STR_DL_VLAN_PCP)) {
- this.dataLayerVirtualLanPriorityCodePoint = U8.t(Short.valueOf(values[1]));
- this.wildcards &= ~OFPFW_DL_VLAN_PCP;
- } else if (values[0].equals(STR_NW_DST)
- || values[0].equals("ip_dst")) {
- setFromCIDR(values[1], STR_NW_DST);
- } else if (values[0].equals(STR_NW_SRC)
- || values[0].equals("ip_src")) {
- setFromCIDR(values[1], STR_NW_SRC);
- } else if (values[0].equals(STR_NW_PROTO)) {
- if (values[1].startsWith("0x"))
- this.networkProtocol = U8.t(Short.valueOf(values[1].replaceFirst("0x",""),16));
- else
- this.networkProtocol = U8.t(Short.valueOf(values[1]));
- this.wildcards &= ~OFPFW_NW_PROTO;
- } else if (values[0].equals(STR_NW_TOS)) {
- this.setNetworkTypeOfService(U8.t(Short.valueOf(values[1])));
- this.wildcards &= ~OFPFW_NW_TOS;
- } else if (values[0].equals(STR_TP_DST)) {
- this.transportDestination = U16.t(Integer.valueOf(values[1]));
- this.wildcards &= ~OFPFW_TP_DST;
- } else if (values[0].equals(STR_TP_SRC)) {
- this.transportSource = U16.t(Integer.valueOf(values[1]));
- this.wildcards &= ~OFPFW_TP_SRC;
- } else {
- throw new IllegalArgumentException("unknown token "
- + tokens[i] + " parsing "
- + match);
- }
- }
- }
-
- /**
- * Set the networkSource or networkDestionation address and their wildcards
- * from the CIDR string
- *
- * @param cidr
- * "192.168.0.0/16" or "172.16.1.5"
- * @param which
- * one of STR_NW_DST or STR_NW_SRC
- * @throws IllegalArgumentException
- */
- private
- void
- setFromCIDR(String cidr, String which)
- throws IllegalArgumentException {
- String values[] = cidr.split("/");
- String[] ip_str = values[0].split("\\.");
- int ip = 0;
- ip += Integer.valueOf(ip_str[0]) << 24;
- ip += Integer.valueOf(ip_str[1]) << 16;
- ip += Integer.valueOf(ip_str[2]) << 8;
- ip += Integer.valueOf(ip_str[3]);
- int prefix = 32; // all bits are fixed, by default
-
- if (values.length >= 2) prefix = Integer.valueOf(values[1]);
- int mask = 32 - prefix;
- if (which.equals(STR_NW_DST)) {
- this.networkDestination = ip;
- this.wildcards = (wildcards & ~OFPFW_NW_DST_MASK)
- | (mask << OFPFW_NW_DST_SHIFT);
- } else if (which.equals(STR_NW_SRC)) {
- this.networkSource = ip;
- this.wildcards = (wildcards & ~OFPFW_NW_SRC_MASK)
- | (mask << OFPFW_NW_SRC_SHIFT);
- }
- }
-
- protected static String ipToString(int ip) {
- return Integer.toString(U8.f((byte) ((ip & 0xff000000) >> 24)))
- + "." + Integer.toString((ip & 0x00ff0000) >> 16) + "."
- + Integer.toString((ip & 0x0000ff00) >> 8) + "."
- + Integer.toString(ip & 0x000000ff);
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.beans.IntrospectionException;
-import java.beans.PropertyDescriptor;
-import java.beans.SimpleBeanInfo;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Extra info for how to treat OFMatch as a JavaBean
- *
- * For some (inane!) reason, using chained setters in OFMatch breaks a lot of the JavaBean defaults.
- *
- * We don't really use OFMatch as a java bean, but there are a lot of nice XML utils that work for
- * free if OFMatch follows the java bean paradigm.
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- *
- */
-
-public class OFMatchBeanInfo extends SimpleBeanInfo {
-
- @Override
- public PropertyDescriptor[] getPropertyDescriptors() {
- List<PropertyDescriptor> descs = new LinkedList<PropertyDescriptor>();
- Field[] fields = OFMatch.class.getDeclaredFields();
- String name;
- for (int i=0; i< fields.length; i++) {
- int mod = fields[i].getModifiers();
- if(Modifier.isFinal(mod) || // don't expose static or final fields
- Modifier.isStatic(mod))
- continue;
-
- name = fields[i].getName();
- Class<?> type = fields[i].getType();
-
- try {
- descs.add(new PropertyDescriptor(name,
- name2getter(OFMatch.class, name),
- name2setter(OFMatch.class, name, type)));
- } catch (IntrospectionException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
- return descs.toArray(new PropertyDescriptor[0]);
- }
-
-
- private Method name2setter(Class<OFMatch> c, String name, Class<?> type) {
- String mName = "set" + toLeadingCaps(name);
- Method m = null;
- try {
- m = c.getMethod(mName, new Class[]{ type});
- } catch (SecurityException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- return m;
- }
-
- private Method name2getter(Class<OFMatch> c, String name) {
- String mName= "get" + toLeadingCaps(name);
- Method m = null;
- try {
- m = c.getMethod(mName, new Class[]{});
- } catch (SecurityException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- return m;
- }
-
- private String toLeadingCaps(String s) {
- char[] array = s.toCharArray();
- array[0] = Character.toUpperCase(array[0]);
- return String.valueOf(array, 0, array.length);
- }
-}
+++ /dev/null
-/**
- * Copyright 2013, Big Switch Networks, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License. You may obtain
- * a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- **/
-
-package org.openflow.protocol;
-
-import org.openflow.util.HexString;
-
-public class OFMatchWithSwDpid {
- protected OFMatch ofMatch;
- protected long switchDataPathId;
-
- public OFMatchWithSwDpid() {
- this.ofMatch = new OFMatch();
- this.switchDataPathId = 0;
- }
-
- public OFMatchWithSwDpid(OFMatch ofm, long swDpid) {
- this.ofMatch = ofm.clone();
- this.switchDataPathId = swDpid;
- }
- public OFMatch getOfMatch() {
- return ofMatch;
- }
-
- public void setOfMatch(OFMatch ofMatch) {
- this.ofMatch = ofMatch.clone();
- }
-
- public long getSwitchDataPathId() {
- return this.switchDataPathId;
- }
-
- public OFMatchWithSwDpid setSwitchDataPathId(long dpid) {
- this.switchDataPathId = dpid;
- return this;
- }
-
- @Override
- public String toString() {
- return "OFMatchWithSwDpid [" + HexString.toHexString(switchDataPathId) + ofMatch + "]";
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.concurrent.ConcurrentHashMap;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.HexString;
-import org.openflow.util.U16;
-import org.openflow.util.U32;
-import org.openflow.util.U8;
-
-/**
- * The base class for all OpenFlow protocol messages. This class contains the
- * equivalent of the ofp_header which is present in all OpenFlow messages.
- *
- * @author David Erickson (daviderickson@cs.stanford.edu) - Feb 3, 2010
- * @author Rob Sherwood (rob.sherwood@stanford.edu) - Feb 3, 2010
- */
-public class OFMessage {
- public static final int MAXIMUM_LENGTH = (1 << 16) - 1;
- public static byte OFP_VERSION = 0x01;
- public static int MINIMUM_LENGTH = 8;
-
- protected byte version;
- protected OFType type;
- protected short length;
- protected int xid;
-
- private ConcurrentHashMap<String, Object> storage;
-
- public OFMessage() {
- storage = null;
- this.version = OFP_VERSION;
- }
-
- protected synchronized ConcurrentHashMap<String, Object> getMessageStore() {
- if (storage == null) {
- storage = new ConcurrentHashMap<String, Object>();;
- }
- return storage;
- }
-
- /**
- * Get the length of this message
- *
- * @return
- */
- public short getLength() {
- return length;
- }
-
- /**
- * Get the length of this message, unsigned
- *
- * @return
- */
- public int getLengthU() {
- return U16.f(length);
- }
-
- /**
- * Set the length of this message
- *
- * @param length
- */
- public OFMessage setLength(short length) {
- this.length = length;
- return this;
- }
-
- /**
- * Set the length of this message, unsigned
- *
- * @param length
- */
- public OFMessage setLengthU(int length) {
- this.length = U16.t(length);
- return this;
- }
-
- /**
- * Get the type of this message
- *
- * @return
- */
- public OFType getType() {
- return type;
- }
-
- /**
- * Set the type of this message
- *
- * @param type
- */
- public void setType(OFType type) {
- this.type = type;
- }
-
- /**
- * Get the OpenFlow version of this message
- *
- * @return
- */
- public byte getVersion() {
- return version;
- }
-
- /**
- * Set the OpenFlow version of this message
- *
- * @param version
- */
- public void setVersion(byte version) {
- this.version = version;
- }
-
- /**
- * Get the transaction id of this message
- *
- * @return
- */
- public int getXid() {
- return xid;
- }
-
- /**
- * Set the transaction id of this message
- *
- * @param xid
- */
- public void setXid(int xid) {
- this.xid = xid;
- }
-
- /**
- * Read this message off the wire from the specified ByteBuffer
- * @param data
- */
- public void readFrom(ChannelBuffer data) {
- this.version = data.readByte();
- this.type = OFType.valueOf(data.readByte());
- this.length = data.readShort();
- this.xid = data.readInt();
- }
-
- /**
- * Write this message's binary format to the specified ByteBuffer
- * @param data
- */
- public void writeTo(ChannelBuffer data) {
- data.writeByte(version);
- data.writeByte(type.getTypeValue());
- data.writeShort(length);
- data.writeInt(xid);
- }
-
- /**
- * Returns a summary of the message
- * @return "ofmsg=v=$version;t=$type:l=$len:xid=$xid"
- */
- @Override
- public String toString() {
- return "ofmsg" +
- ":v=" + U8.f(this.getVersion()) +
- ";t=" + this.getType() +
- ";l=" + this.getLengthU() +
- ";x=" + U32.f(this.getXid());
- }
-
- @Override
- public int hashCode() {
- final int prime = 97;
- int result = 1;
- result = prime * result + length;
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- result = prime * result + version;
- result = prime * result + xid;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFMessage)) {
- return false;
- }
- OFMessage other = (OFMessage) obj;
- if (length != other.length) {
- return false;
- }
- if (type == null) {
- if (other.type != null) {
- return false;
- }
- } else if (!type.equals(other.type)) {
- return false;
- }
- if (version != other.version) {
- return false;
- }
- if (xid != other.xid) {
- return false;
- }
- return true;
- }
-
- /*
- public static String getDataAsString(IOFSwitch sw, OFMessage msg) {
-
-
- Ethernet eth;
- StringBuffer sb = new StringBuffer("");
-
- DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
- Date date = new Date();
-
- sb.append(dateFormat.format(date));
- sb.append(" ");
-
- switch (msg.getType()) {
- case PACKET_IN:
- OFPacketIn pktIn = (OFPacketIn) msg;
- sb.append("packet_in [ ");
- sb.append(sw.getStringId());
- sb.append(" -> Controller");
- sb.append(" ]");
-
- sb.append("\ntotal length: ");
- sb.append(pktIn.getTotalLength());
- sb.append("\nin_port: ");
- sb.append(pktIn.getInPort());
- sb.append("\ndata_length: ");
- sb.append(pktIn.getTotalLength() - OFPacketIn.MINIMUM_LENGTH);
- sb.append("\nbuffer: ");
- sb.append(pktIn.getBufferId());
-
- break;
-
- case PACKET_OUT:
- OFPacketOut pktOut = (OFPacketOut) msg;
- sb.append("packet_out [ ");
- sb.append("Controller -> ");
- sb.append(HexString.toHexString(sw.getId()));
- sb.append(" ]");
-
- sb.append("\nin_port: ");
- sb.append(pktOut.getInPort());
- sb.append("\nactions_len: ");
- sb.append(pktOut.getActionsLength());
- if (pktOut.getActions() != null) {
- sb.append("\nactions: ");
- sb.append(pktOut.getActions().toString());
- }
- break;
-
- case FLOW_MOD:
- OFFlowMod fm = (OFFlowMod) msg;
- sb.append("flow_mod [ ");
- sb.append("Controller -> ");
- sb.append(HexString.toHexString(sw.getId()));
- sb.append(" ]");
-
-
- sb.append("\nADD: cookie: ");
- sb.append(fm.getCookie());
- sb.append(" idle: ");
- sb.append(fm.getIdleTimeout());
- sb.append(" hard: ");
- sb.append(fm.getHardTimeout());
- sb.append(" pri: ");
- sb.append(fm.getPriority());
- sb.append(" buf: ");
- sb.append(fm.getBufferId());
- sb.append(" flg: ");
- sb.append(fm.getFlags());
- if (fm.getActions() != null) {
- sb.append("\nactions: ");
- sb.append(fm.getActions().toString());
- }
- break;
-
- default:
- sb.append("[Unknown Packet]");
- }
-
- sb.append("\n\n");
- return sb.toString();
-
- }
- */
-
-
- // Check if this is really required
- /*
- public static byte[] getData(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
- return OFMessage.getDataAsString(sw, msg, cntx).getBytes();
- }
- */
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import org.openflow.protocol.OFMessage;
-
-public class OFMessageContextStore<V> {
- protected OFMessage msg;
- String namespace;
-
- public OFMessageContextStore(OFMessage msg, String namespace) {
- this.msg = msg;
- this.namespace = namespace;
- }
-
- @SuppressWarnings("unchecked")
- public V get(String key) {
- return (V)msg.getMessageStore().get(namespace + "|" + key);
- }
-
- public void put(String key, V value) {
- msg.getMessageStore().put(namespace + "|" + key, value);
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.util.Arrays;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.U16;
-import org.openflow.util.U32;
-import org.openflow.util.U8;
-
-/**
- * Represents an ofp_packet_in
- *
- * @author David Erickson (daviderickson@cs.stanford.edu) - Feb 8, 2010
- */
-public class OFPacketIn extends OFMessage {
- public static short MINIMUM_LENGTH = 18;
-
- public enum OFPacketInReason {
- NO_MATCH, ACTION
- }
-
- protected int bufferId;
- protected short totalLength;
- protected short inPort;
- protected OFPacketInReason reason;
- protected byte[] packetData;
-
- public OFPacketIn() {
- super();
- this.type = OFType.PACKET_IN;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * Get buffer_id
- * @return
- */
- public int getBufferId() {
- return this.bufferId;
- }
-
- /**
- * Set buffer_id
- * @param bufferId
- */
- public OFPacketIn setBufferId(int bufferId) {
- this.bufferId = bufferId;
- return this;
- }
-
- /**
- * Returns the packet data
- * @return
- */
- public byte[] getPacketData() {
- return this.packetData;
- }
-
- /**
- * Sets the packet data, and updates the length of this message
- * @param packetData
- */
- public OFPacketIn setPacketData(byte[] packetData) {
- this.packetData = packetData;
- this.length = U16.t(OFPacketIn.MINIMUM_LENGTH + packetData.length);
- return this;
- }
-
- /**
- * Get in_port
- * @return
- */
- public short getInPort() {
- return this.inPort;
- }
-
- /**
- * Set in_port
- * @param inPort
- */
- public OFPacketIn setInPort(short inPort) {
- this.inPort = inPort;
- return this;
- }
-
- /**
- * Get reason
- * @return
- */
- public OFPacketInReason getReason() {
- return this.reason;
- }
-
- /**
- * Set reason
- * @param reason
- */
- public OFPacketIn setReason(OFPacketInReason reason) {
- this.reason = reason;
- return this;
- }
-
- /**
- * Get total_len
- * @return
- */
- public short getTotalLength() {
- return this.totalLength;
- }
-
- /**
- * Set total_len
- * @param totalLength
- */
- public OFPacketIn setTotalLength(short totalLength) {
- this.totalLength = totalLength;
- return this;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.bufferId = data.readInt();
- this.totalLength = data.readShort();
- this.inPort = data.readShort();
- this.reason = OFPacketInReason.values()[U8.f(data.readByte())];
- data.readByte(); // pad
- this.packetData = new byte[getLengthU() - MINIMUM_LENGTH];
- data.readBytes(this.packetData);
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeInt(bufferId);
- data.writeShort(totalLength);
- data.writeShort(inPort);
- data.writeByte((byte) reason.ordinal());
- data.writeByte((byte) 0x0); // pad
- data.writeBytes(this.packetData);
- }
-
- @Override
- public int hashCode() {
- final int prime = 283;
- int result = super.hashCode();
- result = prime * result + bufferId;
- result = prime * result + inPort;
- result = prime * result + Arrays.hashCode(packetData);
- result = prime * result + ((reason == null) ? 0 : reason.hashCode());
- result = prime * result + totalLength;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPacketIn)) {
- return false;
- }
- OFPacketIn other = (OFPacketIn) obj;
- if (bufferId != other.bufferId) {
- return false;
- }
- if (inPort != other.inPort) {
- return false;
- }
- if (!Arrays.equals(packetData, other.packetData)) {
- return false;
- }
- if (reason == null) {
- if (other.reason != null) {
- return false;
- }
- } else if (!reason.equals(other.reason)) {
- return false;
- }
- if (totalLength != other.totalLength) {
- return false;
- }
- return true;
- }
-
- public String toString() {
- String myStr = super.toString();
- return "packetIn" +
- ":bufferId=" + U32.f(this.bufferId) + myStr;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.action.OFAction;
-import org.openflow.protocol.factory.OFActionFactory;
-import org.openflow.protocol.factory.OFActionFactoryAware;
-import org.openflow.util.HexString;
-import org.openflow.util.U16;
-
-/**
- * Represents an ofp_packet_out message
- *
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 12, 2010
- */
-public class OFPacketOut extends OFMessage implements OFActionFactoryAware {
- public static int MINIMUM_LENGTH = 16;
- public static int BUFFER_ID_NONE = 0xffffffff;
-
- protected OFActionFactory actionFactory;
- protected int bufferId;
- protected short inPort;
- protected short actionsLength;
- protected List<OFAction> actions;
- protected byte[] packetData;
-
- public OFPacketOut() {
- super();
- this.type = OFType.PACKET_OUT;
- this.length = U16.t(MINIMUM_LENGTH);
- this.bufferId = BUFFER_ID_NONE;
- }
-
- /**
- * Get buffer_id
- * @return
- */
- public int getBufferId() {
- return this.bufferId;
- }
-
- /**
- * Set buffer_id
- * @param bufferId
- */
- public OFPacketOut setBufferId(int bufferId) {
- if (packetData != null && packetData.length > 0 && bufferId != BUFFER_ID_NONE) {
- throw new IllegalArgumentException(
- "PacketOut should not have both bufferId and packetData set");
- }
- this.bufferId = bufferId;
- return this;
- }
-
- /**
- * Returns the packet data
- * @return
- */
- public byte[] getPacketData() {
- return this.packetData;
- }
-
- /**
- * Sets the packet data
- * @param packetData
- */
- public OFPacketOut setPacketData(byte[] packetData) {
- if (packetData != null && packetData.length > 0 && bufferId != BUFFER_ID_NONE) {
- throw new IllegalArgumentException(
- "PacketOut should not have both bufferId and packetData set");
- }
- this.packetData = packetData;
- return this;
- }
-
- /**
- * Get in_port
- * @return
- */
- public short getInPort() {
- return this.inPort;
- }
-
- /**
- * Set in_port
- * @param inPort
- */
- public OFPacketOut setInPort(short inPort) {
- this.inPort = inPort;
- return this;
- }
-
- /**
- * Set in_port. Convenience method using OFPort enum.
- * @param inPort
- */
- public OFPacketOut setInPort(OFPort inPort) {
- this.inPort = inPort.getValue();
- return this;
- }
-
- /**
- * Get actions_len
- * @return
- */
- public short getActionsLength() {
- return this.actionsLength;
- }
-
- /**
- * Get actions_len, unsigned
- * @return
- */
- public int getActionsLengthU() {
- return U16.f(this.actionsLength);
- }
-
- /**
- * Set actions_len
- * @param actionsLength
- */
- public OFPacketOut setActionsLength(short actionsLength) {
- this.actionsLength = actionsLength;
- return this;
- }
-
- /**
- * Returns the actions contained in this message
- * @return a list of ordered OFAction objects
- */
- public List<OFAction> getActions() {
- return this.actions;
- }
-
- /**
- * Sets the list of actions on this message
- * @param actions a list of ordered OFAction objects
- */
- public OFPacketOut setActions(List<OFAction> actions) {
- this.actions = actions;
- return this;
- }
-
- @Override
- public void setActionFactory(OFActionFactory actionFactory) {
- this.actionFactory = actionFactory;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.bufferId = data.readInt();
- this.inPort = data.readShort();
- this.actionsLength = data.readShort();
- if ( this.actionFactory == null)
- throw new RuntimeException("ActionFactory not set");
- this.actions = this.actionFactory.parseActions(data, getActionsLengthU());
- this.packetData = new byte[getLengthU() - MINIMUM_LENGTH - getActionsLengthU()];
- data.readBytes(this.packetData);
- validate();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- validate();
- super.writeTo(data);
- data.writeInt(bufferId);
- data.writeShort(inPort);
- data.writeShort(actionsLength);
- for (OFAction action : actions) {
- action.writeTo(data);
- }
- if (this.packetData != null)
- data.writeBytes(this.packetData);
- }
-
- /** validate the invariants of this OFMessage hold */
- public void validate() {
- if (!((bufferId != BUFFER_ID_NONE) ^ (packetData != null && packetData.length > 0))) {
- throw new IllegalStateException(
- "OFPacketOut must have exactly one of (bufferId, packetData) set (not one, not both)");
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 293;
- int result = super.hashCode();
- result = prime * result + ((actions == null) ? 0 : actions.hashCode());
- result = prime * result + actionsLength;
- result = prime * result + bufferId;
- result = prime * result + inPort;
- result = prime * result + Arrays.hashCode(packetData);
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPacketOut)) {
- return false;
- }
- OFPacketOut other = (OFPacketOut) obj;
- if (actions == null) {
- if (other.actions != null) {
- return false;
- }
- } else if (!actions.equals(other.actions)) {
- return false;
- }
- if (actionsLength != other.actionsLength) {
- return false;
- }
- if (bufferId != other.bufferId) {
- return false;
- }
- if (inPort != other.inPort) {
- return false;
- }
- if (!Arrays.equals(packetData, other.packetData)) {
- return false;
- }
- return true;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "OFPacketOut [actionFactory=" + actionFactory + ", actions="
- + actions + ", actionsLength=" + actionsLength + ", bufferId=0x"
- + Integer.toHexString(bufferId) + ", inPort=" + inPort + ", packetData="
- + HexString.toHexString(packetData) + "]";
- }
-}
+++ /dev/null
-/**
-* Copyright 2012, Andrew Ferguson, Brown University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.U16;
-
-/**
- * Represents ofp_packet_queue
- * @author Andrew Ferguson (adf@cs.brown.edu)
- */
-public class OFPacketQueue {
- public static int MINIMUM_LENGTH = 8;
-
- protected int queueId;
- protected short length;
- protected List<OFQueueProp> properties = new ArrayList<OFQueueProp>();
-
- public OFPacketQueue() {
- this.queueId = -1;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- public OFPacketQueue(int queueId) {
- this.queueId = queueId;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * @return the queueId
- */
- public long getQueueId() {
- return queueId;
- }
-
- /**
- * @param queueId the queueId to set
- */
- public void setQueueId(int queueId) {
- this.queueId = queueId;
- }
-
- /**
- * @return the queue's properties
- */
- public List<OFQueueProp> getProperties() {
- return properties;
- }
-
- /**
- * @param properties the properties to set
- */
- public void setProperties(List<OFQueueProp> properties) {
- this.properties = properties;
-
- this.length = U16.t(MINIMUM_LENGTH);
- for (OFQueueProp prop : properties) {
- this.length += prop.getLength();
- }
- }
-
- /**
- * @return the length
- */
- public short getLength() {
- return length;
- }
-
- public void readFrom(ChannelBuffer data) {
- this.queueId = data.readInt();
- this.length = data.readShort();
- data.readShort(); // pad
-
- int availLength = (this.length - MINIMUM_LENGTH);
- this.properties.clear();
-
- while (availLength > 0) {
- OFQueueProp prop = new OFQueueProp();
- prop.readFrom(data);
- properties.add(prop);
- availLength -= prop.getLength();
- }
- }
-
- public void writeTo(ChannelBuffer data) {
- data.writeInt(queueId);
- data.writeShort(length);
- data.writeShort(0); // pad
-
- for (OFQueueProp prop : properties) {
- prop.writeTo(data);
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 359;
- int result = super.hashCode();
- result = prime * result + queueId;
- result = prime * result + length;
- result = prime * result + properties.hashCode();
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPacketQueue)) {
- return false;
- }
- OFPacketQueue other = (OFPacketQueue) obj;
- if (queueId != other.queueId) {
- return false;
- }
- if (! properties.equals(other.properties)) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-import java.util.Arrays;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Represents ofp_phy_port
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 25, 2010
- */
-public class OFPhysicalPort {
- public static int MINIMUM_LENGTH = 48;
- public static int OFP_ETH_ALEN = 6;
-
- public enum OFPortConfig {
- OFPPC_PORT_DOWN (1 << 0) {
- public String toString() {
- return "port-down (0x1)";
- }
- },
- OFPPC_NO_STP (1 << 1) {
- public String toString() {
- return "no-stp (0x2)";
- }
- },
- OFPPC_NO_RECV (1 << 2) {
- public String toString() {
- return "no-recv (0x4)";
- }
- },
- OFPPC_NO_RECV_STP (1 << 3) {
- public String toString() {
- return "no-recv-stp (0x8)";
- }
- },
- OFPPC_NO_FLOOD (1 << 4) {
- public String toString() {
- return "no-flood (0x10)";
- }
- },
- OFPPC_NO_FWD (1 << 5) {
- public String toString() {
- return "no-fwd (0x20)";
- }
- },
- OFPPC_NO_PACKET_IN (1 << 6) {
- public String toString() {
- return "no-pkt-in (0x40)";
- }
- };
-
- protected int value;
-
- private OFPortConfig(int value) {
- this.value = value;
- }
-
- /**
- * @return the value
- */
- public int getValue() {
- return value;
- }
- }
-
- public enum OFPortState {
- OFPPS_LINK_DOWN (1 << 0) {
- public String toString() {
- return "link-down (0x1)";
- }
- },
- OFPPS_STP_LISTEN (0 << 8) {
- public String toString() {
- return "listen (0x0)";
- }
- },
- OFPPS_STP_LEARN (1 << 8) {
- public String toString() {
- return "learn-no-relay (0x100)";
- }
- },
- OFPPS_STP_FORWARD (2 << 8) {
- public String toString() {
- return "forward (0x200)";
- }
- },
- OFPPS_STP_BLOCK (3 << 8) {
- public String toString() {
- return "block-broadcast (0x300)";
- }
- },
- OFPPS_STP_MASK (3 << 8) {
- public String toString() {
- return "block-broadcast (0x300)";
- }
- };
-
- protected int value;
-
- private OFPortState(int value) {
- this.value = value;
- }
-
- /**
- * @return the value
- */
- public int getValue() {
- return value;
- }
- }
-
- public enum OFPortFeatures {
- OFPPF_10MB_HD (1 << 0) {
- public String toString() {
- return "10mb-hd (0x1)";
- }
- },
- OFPPF_10MB_FD (1 << 1) {
- public String toString() {
- return "10mb-fd (0x2)";
- }
- },
- OFPPF_100MB_HD (1 << 2) {
- public String toString() {
- return "100mb-hd (0x4)";
- }
- },
- OFPPF_100MB_FD (1 << 3) {
- public String toString() {
- return "100mb-fd (0x8)";
- }
- },
- OFPPF_1GB_HD (1 << 4) {
- public String toString() {
- return "1gb-hd (0x10)";
- }
- },
- OFPPF_1GB_FD (1 << 5) {
- public String toString() {
- return "1gb-fd (0x20)";
- }
- },
- OFPPF_10GB_FD (1 << 6) {
- public String toString() {
- return "10gb-fd (0x40)";
- }
- },
- OFPPF_COPPER (1 << 7) {
- public String toString() {
- return "copper (0x80)";
- }
- },
- OFPPF_FIBER (1 << 8) {
- public String toString() {
- return "fiber (0x100)";
- }
- },
- OFPPF_AUTONEG (1 << 9) {
- public String toString() {
- return "autoneg (0x200)";
- }
- },
- OFPPF_PAUSE (1 << 10) {
- public String toString() {
- return "pause (0x400)";
- }
- },
- OFPPF_PAUSE_ASYM (1 << 11) {
- public String toString() {
- return "pause-asym (0x800)";
- }
- };
-
- protected int value;
-
- private OFPortFeatures(int value) {
- this.value = value;
- }
-
- /**
- * @return the value
- */
- public int getValue() {
- return value;
- }
- }
-
- protected short portNumber;
- protected byte[] hardwareAddress;
- protected String name;
- protected int config;
- protected int state;
- protected int currentFeatures;
- protected int advertisedFeatures;
- protected int supportedFeatures;
- protected int peerFeatures;
-
- /**
- * @return the portNumber
- */
- public short getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param portNumber the portNumber to set
- */
- public void setPortNumber(short portNumber) {
- this.portNumber = portNumber;
- }
-
- /**
- * @return the hardwareAddress
- */
- public byte[] getHardwareAddress() {
- return hardwareAddress;
- }
-
- /**
- * @param hardwareAddress the hardwareAddress to set
- */
- public void setHardwareAddress(byte[] hardwareAddress) {
- if (hardwareAddress.length != OFP_ETH_ALEN)
- throw new RuntimeException("Hardware address must have length "
- + OFP_ETH_ALEN);
- this.hardwareAddress = hardwareAddress;
- }
-
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- /**
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * @return the config
- */
- public int getConfig() {
- return config;
- }
-
- /**
- * @param config the config to set
- */
- public void setConfig(int config) {
- this.config = config;
- }
-
- /**
- * @return the state
- */
- public int getState() {
- return state;
- }
-
- /**
- * @param state the state to set
- */
- public void setState(int state) {
- this.state = state;
- }
-
- /**
- * @return the currentFeatures
- */
- public int getCurrentFeatures() {
- return currentFeatures;
- }
-
- /**
- * @param currentFeatures the currentFeatures to set
- */
- public void setCurrentFeatures(int currentFeatures) {
- this.currentFeatures = currentFeatures;
- }
-
- /**
- * @return the advertisedFeatures
- */
- public int getAdvertisedFeatures() {
- return advertisedFeatures;
- }
-
- /**
- * @param advertisedFeatures the advertisedFeatures to set
- */
- public void setAdvertisedFeatures(int advertisedFeatures) {
- this.advertisedFeatures = advertisedFeatures;
- }
-
- /**
- * @return the supportedFeatures
- */
- public int getSupportedFeatures() {
- return supportedFeatures;
- }
-
- /**
- * @param supportedFeatures the supportedFeatures to set
- */
- public void setSupportedFeatures(int supportedFeatures) {
- this.supportedFeatures = supportedFeatures;
- }
-
- /**
- * @return the peerFeatures
- */
- public int getPeerFeatures() {
- return peerFeatures;
- }
-
- /**
- * @param peerFeatures the peerFeatures to set
- */
- public void setPeerFeatures(int peerFeatures) {
- this.peerFeatures = peerFeatures;
- }
-
- /**
- * Read this message off the wire from the specified ByteBuffer
- * @param data
- */
- public void readFrom(ChannelBuffer data) {
- this.portNumber = data.readShort();
- if (this.hardwareAddress == null)
- this.hardwareAddress = new byte[OFP_ETH_ALEN];
- data.readBytes(this.hardwareAddress);
- byte[] name = new byte[16];
- data.readBytes(name);
- // find the first index of 0
- int index = 0;
- for (byte b : name) {
- if (0 == b)
- break;
- ++index;
- }
- this.name = new String(Arrays.copyOf(name, index),
- Charset.forName("ascii"));
- this.config = data.readInt();
- this.state = data.readInt();
- this.currentFeatures = data.readInt();
- this.advertisedFeatures = data.readInt();
- this.supportedFeatures = data.readInt();
- this.peerFeatures = data.readInt();
- }
-
- /**
- * Write this message's binary format to the specified ByteBuffer
- * @param data
- */
- public void writeTo(ChannelBuffer data) {
- data.writeShort(this.portNumber);
- data.writeBytes(hardwareAddress);
- try {
- byte[] name = this.name.getBytes("ASCII");
- if (name.length < 16) {
- data.writeBytes(name);
- for (int i = name.length; i < 16; ++i) {
- data.writeByte((byte) 0);
- }
- } else {
- data.writeBytes(name, 0, 15);
- data.writeByte((byte) 0);
- }
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- data.writeInt(this.config);
- data.writeInt(this.state);
- data.writeInt(this.currentFeatures);
- data.writeInt(this.advertisedFeatures);
- data.writeInt(this.supportedFeatures);
- data.writeInt(this.peerFeatures);
- }
-
- @Override
- public int hashCode() {
- final int prime = 307;
- int result = 1;
- result = prime * result + advertisedFeatures;
- result = prime * result + config;
- result = prime * result + currentFeatures;
- result = prime * result + Arrays.hashCode(hardwareAddress);
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + peerFeatures;
- result = prime * result + portNumber;
- result = prime * result + state;
- result = prime * result + supportedFeatures;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPhysicalPort)) {
- return false;
- }
- OFPhysicalPort other = (OFPhysicalPort) obj;
- if (advertisedFeatures != other.advertisedFeatures) {
- return false;
- }
- if (config != other.config) {
- return false;
- }
- if (currentFeatures != other.currentFeatures) {
- return false;
- }
- if (!Arrays.equals(hardwareAddress, other.hardwareAddress)) {
- return false;
- }
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (peerFeatures != other.peerFeatures) {
- return false;
- }
- if (portNumber != other.portNumber) {
- return false;
- }
- if (state != other.state) {
- return false;
- }
- if (supportedFeatures != other.supportedFeatures) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-public enum OFPort {
- OFPP_MAX ((short)0xff00),
- OFPP_IN_PORT ((short)0xfff8),
- OFPP_TABLE ((short)0xfff9),
- OFPP_NORMAL ((short)0xfffa),
- OFPP_FLOOD ((short)0xfffb),
- OFPP_ALL ((short)0xfffc),
- OFPP_CONTROLLER ((short)0xfffd),
- OFPP_LOCAL ((short)0xfffe),
- OFPP_NONE ((short)0xffff);
-
- protected short value;
-
- private OFPort(short value) {
- this.value = value;
- }
-
- /**
- * @return the value
- */
- public short getValue() {
- return value;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.util.Arrays;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.U16;
-
-/**
- * Represents an ofp_port_mod message
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPortMod extends OFMessage {
- public static int MINIMUM_LENGTH = 32;
-
- protected short portNumber;
- protected byte[] hardwareAddress;
- protected int config;
- protected int mask;
- protected int advertise;
-
- public OFPortMod() {
- super();
- this.type = OFType.PORT_MOD;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * @return the portNumber
- */
- public short getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param portNumber the portNumber to set
- */
- public void setPortNumber(short portNumber) {
- this.portNumber = portNumber;
- }
-
- /**
- * @return the hardwareAddress
- */
- public byte[] getHardwareAddress() {
- return hardwareAddress;
- }
-
- /**
- * @param hardwareAddress the hardwareAddress to set
- */
- public void setHardwareAddress(byte[] hardwareAddress) {
- if (hardwareAddress.length != OFPhysicalPort.OFP_ETH_ALEN)
- throw new RuntimeException("Hardware address must have length "
- + OFPhysicalPort.OFP_ETH_ALEN);
- this.hardwareAddress = hardwareAddress;
- }
-
- /**
- * @return the config
- */
- public int getConfig() {
- return config;
- }
-
- /**
- * @param config the config to set
- */
- public void setConfig(int config) {
- this.config = config;
- }
-
- /**
- * @return the mask
- */
- public int getMask() {
- return mask;
- }
-
- /**
- * @param mask the mask to set
- */
- public void setMask(int mask) {
- this.mask = mask;
- }
-
- /**
- * @return the advertise
- */
- public int getAdvertise() {
- return advertise;
- }
-
- /**
- * @param advertise the advertise to set
- */
- public void setAdvertise(int advertise) {
- this.advertise = advertise;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.portNumber = data.readShort();
- if (this.hardwareAddress == null)
- this.hardwareAddress = new byte[OFPhysicalPort.OFP_ETH_ALEN];
- data.readBytes(this.hardwareAddress);
- this.config = data.readInt();
- this.mask = data.readInt();
- this.advertise = data.readInt();
- data.readInt(); // pad
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeShort(this.portNumber);
- data.writeBytes(this.hardwareAddress);
- data.writeInt(this.config);
- data.writeInt(this.mask);
- data.writeInt(this.advertise);
- data.writeInt(0); // pad
- }
-
- @Override
- public int hashCode() {
- final int prime = 311;
- int result = super.hashCode();
- result = prime * result + advertise;
- result = prime * result + config;
- result = prime * result + Arrays.hashCode(hardwareAddress);
- result = prime * result + mask;
- result = prime * result + portNumber;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPortMod)) {
- return false;
- }
- OFPortMod other = (OFPortMod) obj;
- if (advertise != other.advertise) {
- return false;
- }
- if (config != other.config) {
- return false;
- }
- if (!Arrays.equals(hardwareAddress, other.hardwareAddress)) {
- return false;
- }
- if (mask != other.mask) {
- return false;
- }
- if (portNumber != other.portNumber) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.U16;
-
-/**
- * Represents an ofp_port_status message
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPortStatus extends OFMessage {
- public static int MINIMUM_LENGTH = 64;
-
- public enum OFPortReason {
- OFPPR_ADD,
- OFPPR_DELETE,
- OFPPR_MODIFY
- }
-
- protected byte reason;
- protected OFPhysicalPort desc;
-
- /**
- * @return the reason
- */
- public byte getReason() {
- return reason;
- }
-
- /**
- * @param reason the reason to set
- */
- public void setReason(byte reason) {
- this.reason = reason;
- }
-
- /**
- * @return the desc
- */
- public OFPhysicalPort getDesc() {
- return desc;
- }
-
- /**
- * @param desc the desc to set
- */
- public void setDesc(OFPhysicalPort desc) {
- this.desc = desc;
- }
-
- public OFPortStatus() {
- super();
- this.type = OFType.PORT_STATUS;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.reason = data.readByte();
- data.readerIndex(data.readerIndex() + 7); // skip 7 bytes of padding
- if (this.desc == null)
- this.desc = new OFPhysicalPort();
- this.desc.readFrom(data);
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeByte(this.reason);
- for (int i = 0; i < 7; ++i)
- data.writeByte((byte) 0);
- this.desc.writeTo(data);
- }
-
- @Override
- public int hashCode() {
- final int prime = 313;
- int result = super.hashCode();
- result = prime * result + ((desc == null) ? 0 : desc.hashCode());
- result = prime * result + reason;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFPortStatus)) {
- return false;
- }
- OFPortStatus other = (OFPortStatus) obj;
- if (desc == null) {
- if (other.desc != null) {
- return false;
- }
- } else if (!desc.equals(other.desc)) {
- return false;
- }
- if (reason != other.reason) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright 2012, Andrew Ferguson, Brown University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.U16;
-
-/**
- * Represents an ofp_queue_get_config_request message
- * @author Andrew Ferguson (adf@cs.brown.edu)
- */
-public class OFQueueGetConfigReply extends OFMessage {
- public static int MINIMUM_LENGTH = 16;
-
- protected short portNumber;
- protected List<OFPacketQueue> queues = new ArrayList<OFPacketQueue>();
-
- public OFQueueGetConfigReply() {
- super();
- this.type = OFType.QUEUE_GET_CONFIG_REPLY;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * @return the portNumber
- */
- public short getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param portNumber the portNumber to set
- */
- public void setPortNumber(short portNumber) {
- this.portNumber = portNumber;
- }
-
- /**
- * @return the port's queues
- */
- public List<OFPacketQueue> getQueues() {
- return queues;
- }
-
- /**
- * @param queues the queues to set
- */
- public void setQueues(List<OFPacketQueue> queues) {
- this.queues.clear();
- this.queues.addAll(queues);
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.portNumber = data.readShort();
- data.readInt(); // pad
- data.readShort(); // pad
-
- int availLength = (this.length - MINIMUM_LENGTH);
- this.queues.clear();
-
- while (availLength > 0) {
- OFPacketQueue queue = new OFPacketQueue();
- queue.readFrom(data);
- queues.add(queue);
- availLength -= queue.getLength();
- }
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeShort(this.portNumber);
- data.writeInt(0); // pad
- data.writeShort(0); // pad
-
- for (OFPacketQueue queue : queues) {
- queue.writeTo(data);
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 349;
- int result = super.hashCode();
- result = prime * result + portNumber;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFQueueGetConfigReply)) {
- return false;
- }
- OFQueueGetConfigReply other = (OFQueueGetConfigReply) obj;
- if (portNumber != other.portNumber) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright 2012, Andrew Ferguson, Brown University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.U16;
-
-/**
- * Represents an ofp_queue_get_config_request message
- * @author Andrew Ferguson (adf@cs.brown.edu)
- */
-public class OFQueueGetConfigRequest extends OFMessage {
- public static int MINIMUM_LENGTH = 12;
-
- protected short portNumber;
-
- public OFQueueGetConfigRequest(short portNumber) {
- super();
- this.type = OFType.QUEUE_GET_CONFIG_REQUEST;
- this.length = U16.t(MINIMUM_LENGTH);
- this.portNumber = portNumber;
- }
-
- public OFQueueGetConfigRequest() {
- this((short) 0);
- }
-
- /**
- * @return the portNumber
- */
- public short getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param portNumber the portNumber to set
- */
- public void setPortNumber(short portNumber) {
- this.portNumber = portNumber;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.portNumber = data.readShort();
- data.readShort(); // pad
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeShort(this.portNumber);
- data.writeShort(0); // pad
- }
-
- @Override
- public int hashCode() {
- final int prime = 347;
- int result = super.hashCode();
- result = prime * result + portNumber;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFQueueGetConfigRequest)) {
- return false;
- }
- OFQueueGetConfigRequest other = (OFQueueGetConfigRequest) obj;
- if (portNumber != other.portNumber) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright 2012, Andrew Ferguson, Brown University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.U16;
-
-public class OFQueueProp {
- private int NONE_MINIMUM_LENGTH = 8;
- private int RATE_MINIMUM_LENGTH = 16;
-
- public enum OFQueuePropType {
- OFPQT_NONE (0),
- OFPQT_MIN_RATE (1),
- OFPQT_MAX_RATE (2);
-
- protected int value;
-
- private OFQueuePropType(int value) {
- this.value = value;
- }
-
- /**
- * @return the value
- */
- public int getValue() {
- return value;
- }
-
- public static OFQueuePropType fromShort(short x) {
- switch (x) {
- case 0:
- return OFPQT_NONE;
- case 1:
- return OFPQT_MIN_RATE;
- case 2:
- return OFPQT_MAX_RATE;
- }
- return null;
- }
- }
-
- protected OFQueuePropType type;
- protected short length;
- protected short rate = -1; // not valid if type == OFPQT_NONE
-
- public OFQueueProp() {
- this.type = OFQueuePropType.OFPQT_NONE;
- this.length = U16.t(NONE_MINIMUM_LENGTH);
- }
-
- /**
- * @return the type
- */
- public OFQueuePropType getType() {
- return type;
- }
-
- /**
- * @param type the type to set
- */
- public void setType(OFQueuePropType type) {
- this.type = type;
-
- switch (type) {
- case OFPQT_NONE:
- this.length = U16.t(NONE_MINIMUM_LENGTH);
- break;
- case OFPQT_MIN_RATE:
- this.length = U16.t(RATE_MINIMUM_LENGTH);
- break;
- case OFPQT_MAX_RATE:
- this.length = U16.t(RATE_MINIMUM_LENGTH);
- break;
- }
- }
-
- /**
- * @return the rate
- */
- public short getRate() {
- return rate;
- }
-
- /**
- * @param rate the rate to set
- */
- public void setRate(short rate) {
- this.rate = rate;
- }
-
- /**
- * @return the length
- */
- public short getLength() {
- return length;
- }
-
- public void readFrom(ChannelBuffer data) {
- this.type = OFQueuePropType.fromShort(data.readShort());
- this.length = data.readShort();
- data.readInt(); // pad
-
- if (this.type == OFQueuePropType.OFPQT_MIN_RATE ||
- this.type == OFQueuePropType.OFPQT_MAX_RATE) {
- assert(this.length == RATE_MINIMUM_LENGTH);
-
- this.rate = data.readShort();
- data.readInt(); // pad
- data.readShort(); // pad
- } else {
- assert(this.length == NONE_MINIMUM_LENGTH);
- }
- }
-
- public void writeTo(ChannelBuffer data) {
- data.writeShort(this.type.getValue());
- data.writeShort(this.length);
- data.writeInt(0); // pad
-
- if (this.type == OFQueuePropType.OFPQT_MIN_RATE ||
- this.type == OFQueuePropType.OFPQT_MAX_RATE) {
- data.writeShort(this.rate);
- data.writeInt(0); // pad
- data.writeShort(0); // pad
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 353;
- int result = super.hashCode();
- result = prime * result + type.getValue();
- result = prime * result + rate;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFQueueProp)) {
- return false;
- }
- OFQueueProp other = (OFQueueProp) obj;
- if (type != other.type) {
- return false;
- }
- if (type == OFQueuePropType.OFPQT_MIN_RATE ||
- type == OFQueuePropType.OFPQT_MAX_RATE) {
- if (rate != other.rate) {
- return false;
- }
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-/**
- * Represents an OFPT_SET_CONFIG type message
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFSetConfig extends OFSwitchConfig {
- public OFSetConfig() {
- super();
- this.type = OFType.SET_CONFIG;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.util.List;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.factory.OFStatisticsFactory;
-import org.openflow.protocol.factory.OFStatisticsFactoryAware;
-import org.openflow.protocol.statistics.OFStatistics;
-import org.openflow.protocol.statistics.OFStatisticsType;
-
-
-/**
- * Base class for statistics requests/replies
- *
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 27, 2010
- */
-public abstract class OFStatisticsMessageBase extends OFMessage implements
- OFStatisticsFactoryAware {
- public static int MINIMUM_LENGTH = 12;
-
- protected OFStatisticsFactory statisticsFactory;
- protected OFStatisticsType statisticType;
- protected short flags;
-
- // TODO: this should be List<? extends OFStatistics>, to
- // allow for type safe assignments of lists of specific message
- protected List<? extends OFStatistics> statistics;
-
- /**
- * @return the statisticType
- */
- public OFStatisticsType getStatisticType() {
- return statisticType;
- }
-
- /**
- * @param statisticType the statisticType to set
- */
- public void setStatisticType(OFStatisticsType statisticType) {
- this.statisticType = statisticType;
- }
-
- /**
- * @return the flags
- */
- public short getFlags() {
- return flags;
- }
-
- /**
- * @param flags the flags to set
- */
- public void setFlags(short flags) {
- this.flags = flags;
- }
-
- /**
- * @return the statistics
- */
- public List<? extends OFStatistics> getStatistics() {
- return statistics;
- }
-
- /**
- * return the first statistics request in the list of statistics, for
- * statistics messages that expect exactly one message in their body (e.g.,
- * flow stats request, port statsrequest)
- *
- * @return the first and only element in the list of statistics
- * @throw IllegalArgumentException if the list does not contain exactly one
- * element
- */
- public OFStatistics getFirstStatistics() {
- if (statistics == null ) {
- throw new IllegalArgumentException("Invariant violation: statistics message of type "+statisticType+" is null");
- }
- if (statistics.size() != 1) {
- throw new IllegalArgumentException("Invariant violation: statistics message of type "+statisticType+" contains "+statistics.size() +" statreq/reply messages in its body (should be 1)");
- }
-
- return statistics.get(0);
- }
-
- /**
- * @param statistics the statistics to set
- */
- public void setStatistics(List<? extends OFStatistics> statistics) {
- this.statistics = statistics;
- }
-
- @Override
- public void setStatisticsFactory(OFStatisticsFactory statisticsFactory) {
- this.statisticsFactory = statisticsFactory;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.statisticType = OFStatisticsType.valueOf(data.readShort(), this
- .getType());
- this.flags = data.readShort();
- if (this.statisticsFactory == null)
- throw new RuntimeException("OFStatisticsFactory not set");
- this.statistics = statisticsFactory.parseStatistics(this.getType(),
- this.statisticType, data, super.getLengthU() - MINIMUM_LENGTH);
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeShort(this.statisticType.getTypeValue());
- data.writeShort(this.flags);
- if (this.statistics != null) {
- for (OFStatistics statistic : this.statistics) {
- statistic.writeTo(data);
- }
- }
- }
-
- @Override
- public int hashCode() {
- final int prime = 317;
- int result = super.hashCode();
- result = prime * result + flags;
- result = prime * result
- + ((statisticType == null) ? 0 : statisticType.hashCode());
- result = prime * result
- + ((statistics == null) ? 0 : statistics.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFStatisticsMessageBase)) {
- return false;
- }
- OFStatisticsMessageBase other = (OFStatisticsMessageBase) obj;
- if (flags != other.flags) {
- return false;
- }
- if (statisticType == null) {
- if (other.statisticType != null) {
- return false;
- }
- } else if (!statisticType.equals(other.statisticType)) {
- return false;
- }
- if (statistics == null) {
- if (other.statistics != null) {
- return false;
- }
- } else if (!statistics.equals(other.statistics)) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import org.openflow.util.U16;
-
-/**
- * Represents an ofp_stats_reply message
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFStatisticsReply extends OFStatisticsMessageBase {
- public enum OFStatisticsReplyFlags {
- REPLY_MORE (1 << 0);
-
- protected short type;
-
- OFStatisticsReplyFlags(int type) {
- this.type = (short) type;
- }
-
- public short getTypeValue() {
- return type;
- }
- }
-
- public OFStatisticsReply() {
- super();
- this.type = OFType.STATS_REPLY;
- this.length = U16.t(OFStatisticsMessageBase.MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import org.openflow.util.U16;
-
-/**
- * Represents an ofp_stats_request message
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFStatisticsRequest extends OFStatisticsMessageBase {
- public OFStatisticsRequest() {
- super();
- this.type = OFType.STATS_REQUEST;
- this.length = U16.t(OFStatisticsMessageBase.MINIMUM_LENGTH);
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Base class representing ofp_switch_config based messages
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public abstract class OFSwitchConfig extends OFMessage {
- public static int MINIMUM_LENGTH = 12;
-
- public enum OFConfigFlags {
- OFPC_FRAG_NORMAL,
- OFPC_FRAG_DROP,
- OFPC_FRAG_REASM,
- OFPC_FRAG_MASK
- }
-
- protected short flags;
- protected short missSendLength;
-
- public OFSwitchConfig() {
- super();
- super.setLengthU(MINIMUM_LENGTH);
- }
-
- /**
- * @return the flags
- */
- public short getFlags() {
- return flags;
- }
-
- /**
- * @param flags the flags to set
- */
- public OFSwitchConfig setFlags(short flags) {
- this.flags = flags;
- return this;
- }
-
- /**
- * @return the missSendLength
- */
- public short getMissSendLength() {
- return missSendLength;
- }
-
- /**
- * @param missSendLength the missSendLength to set
- */
- public OFSwitchConfig setMissSendLength(short missSendLength) {
- this.missSendLength = missSendLength;
- return this;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.flags = data.readShort();
- this.missSendLength = data.readShort();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeShort(this.flags);
- data.writeShort(this.missSendLength);
- }
-
- @Override
- public int hashCode() {
- final int prime = 331;
- int result = super.hashCode();
- result = prime * result + flags;
- result = prime * result + missSendLength;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFSwitchConfig)) {
- return false;
- }
- OFSwitchConfig other = (OFSwitchConfig) obj;
- if (flags != other.flags) {
- return false;
- }
- if (missSendLength != other.missSendLength) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.lang.reflect.Constructor;
-
-/**
- * List of OpenFlow types and mappings to wire protocol value and derived
- * classes
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- * @author David Erickson (daviderickson@cs.stanford.edu)
- *
- */
-public enum OFType {
- HELLO (0, OFHello.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFHello();
- }}),
- ERROR (1, OFError.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFError();
- }}),
- ECHO_REQUEST (2, OFEchoRequest.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFEchoRequest();
- }}),
- ECHO_REPLY (3, OFEchoReply.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFEchoReply();
- }}),
- VENDOR (4, OFVendor.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFVendor();
- }}),
- FEATURES_REQUEST (5, OFFeaturesRequest.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFFeaturesRequest();
- }}),
- FEATURES_REPLY (6, OFFeaturesReply.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFFeaturesReply();
- }}),
- GET_CONFIG_REQUEST (7, OFGetConfigRequest.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFGetConfigRequest();
- }}),
- GET_CONFIG_REPLY (8, OFGetConfigReply.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFGetConfigReply();
- }}),
- SET_CONFIG (9, OFSetConfig.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFSetConfig();
- }}),
- PACKET_IN (10, OFPacketIn.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFPacketIn();
- }}),
- FLOW_REMOVED (11, OFFlowRemoved.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFFlowRemoved();
- }}),
- PORT_STATUS (12, OFPortStatus.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFPortStatus();
- }}),
- PACKET_OUT (13, OFPacketOut.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFPacketOut();
- }}),
- FLOW_MOD (14, OFFlowMod.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFFlowMod();
- }}),
- PORT_MOD (15, OFPortMod.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFPortMod();
- }}),
- STATS_REQUEST (16, OFStatisticsRequest.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFStatisticsRequest();
- }}),
- STATS_REPLY (17, OFStatisticsReply.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFStatisticsReply();
- }}),
- BARRIER_REQUEST (18, OFBarrierRequest.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFBarrierRequest();
- }}),
- BARRIER_REPLY (19, OFBarrierReply.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFBarrierReply();
- }}),
- QUEUE_GET_CONFIG_REQUEST (20, OFQueueGetConfigRequest.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFQueueGetConfigRequest();
- }}),
- QUEUE_GET_CONFIG_REPLY (21, OFQueueGetConfigReply.class, new Instantiable<OFMessage>() {
- @Override
- public OFMessage instantiate() {
- return new OFQueueGetConfigReply();
- }});
-
- static OFType[] mapping;
-
- protected Class<? extends OFMessage> clazz;
- protected Constructor<? extends OFMessage> constructor;
- protected Instantiable<OFMessage> instantiable;
- protected byte type;
-
- /**
- * Store some information about the OpenFlow type, including wire protocol
- * type number, length, and derived class
- *
- * @param type Wire protocol number associated with this OFType
- * @param clazz The Java class corresponding to this type of OpenFlow
- * message
- * @param instantiator An Instantiator<OFMessage> implementation that creates an
- * instance of the specified OFMessage
- */
- OFType(int type, Class<? extends OFMessage> clazz, Instantiable<OFMessage> instantiator) {
- this.type = (byte) type;
- this.clazz = clazz;
- this.instantiable = instantiator;
- try {
- this.constructor = clazz.getConstructor(new Class[]{});
- } catch (Exception e) {
- throw new RuntimeException(
- "Failure getting constructor for class: " + clazz, e);
- }
- OFType.addMapping(this.type, this);
- }
-
- /**
- * Adds a mapping from type value to OFType enum
- *
- * @param i OpenFlow wire protocol type
- * @param t type
- */
- static public void addMapping(byte i, OFType t) {
- if (mapping == null)
- mapping = new OFType[32];
- OFType.mapping[i] = t;
- }
-
- /**
- * Remove a mapping from type value to OFType enum
- *
- * @param i OpenFlow wire protocol type
- */
- static public void removeMapping(byte i) {
- OFType.mapping[i] = null;
- }
-
- /**
- * Given a wire protocol OpenFlow type number, return the OFType associated
- * with it
- *
- * @param i wire protocol number
- * @return OFType enum type
- */
-
- static public OFType valueOf(Byte i) {
- return OFType.mapping[i];
- }
-
- /**
- * @return Returns the wire protocol value corresponding to this OFType
- */
- public byte getTypeValue() {
- return this.type;
- }
-
- /**
- * @return return the OFMessage subclass corresponding to this OFType
- */
- public Class<? extends OFMessage> toClass() {
- return clazz;
- }
-
- /**
- * Returns the no-argument Constructor of the implementation class for
- * this OFType
- * @return the constructor
- */
- public Constructor<? extends OFMessage> getConstructor() {
- return constructor;
- }
-
- /**
- * Returns a new instance of the OFMessage represented by this OFType
- * @return the new object
- */
- public OFMessage newInstance() {
- return instantiable.instantiate();
- }
-
- /**
- * @return the instantiable
- */
- public Instantiable<OFMessage> getInstantiable() {
- return instantiable;
- }
-
- /**
- * @param instantiable the instantiable to set
- */
- public void setInstantiable(Instantiable<OFMessage> instantiable) {
- this.instantiable = instantiable;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.U16;
-import org.openflow.protocol.factory.OFVendorDataFactory;
-import org.openflow.protocol.factory.OFVendorDataFactoryAware;
-import org.openflow.protocol.vendor.OFVendorData;
-
-/**
- * Represents ofp_vendor_header
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFVendor extends OFMessage implements OFVendorDataFactoryAware {
- public static int MINIMUM_LENGTH = 12;
-
- protected int vendor;
- protected OFVendorData vendorData;
- protected OFVendorDataFactory vendorDataFactory;
-
- public OFVendor() {
- super();
- this.type = OFType.VENDOR;
- this.length = U16.t(MINIMUM_LENGTH);
- }
-
- /**
- * @return the vendor
- */
- public int getVendor() {
- return vendor;
- }
-
- /**
- * @param vendor the vendor to set
- */
- public void setVendor(int vendor) {
- this.vendor = vendor;
- }
-
- /**
- * @return the data
- */
- public OFVendorData getVendorData() {
- return vendorData;
- }
-
- /**
- * @param data the data to set
- */
- public void setVendorData(OFVendorData vendorData) {
- this.vendorData = vendorData;
- }
-
- @Override
- public void setVendorDataFactory(OFVendorDataFactory vendorDataFactory) {
- this.vendorDataFactory = vendorDataFactory;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.vendor = data.readInt();
- if (vendorDataFactory == null)
- throw new RuntimeException("OFVendorDataFactory not set");
-
- this.vendorData = vendorDataFactory.parseVendorData(vendor,
- data, super.getLengthU() - MINIMUM_LENGTH);
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeInt(this.vendor);
- if (vendorData != null)
- vendorData.writeTo(data);
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 337;
- int result = super.hashCode();
- result = prime * result + vendor;
- if (vendorData != null)
- result = prime * result + vendorData.hashCode();
- return result;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (getClass() != obj.getClass())
- return false;
- OFVendor other = (OFVendor) obj;
- if (vendor != other.vendor)
- return false;
- if (vendorData == null) {
- if (other.vendorData != null) {
- return false;
- }
- } else if (!vendorData.equals(other.vendorData)) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
- * Copyright 2013, Big Switch Networks, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License. You may obtain
- * a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- **/
-
-package org.openflow.protocol;
-
-import java.util.ArrayList;
-import java.util.EnumSet;
-import java.util.Iterator;
-import java.util.List;
-
-
-/**
- * a more user friendly representation of the wildcards bits in an OpenFlow
- * match. The Wildcards object is
- * <ul>
- * <li>immutable (i.e., threadsafe)</li>
- * <li>instance managed (don't instantiate it yourself), instead call "of"</li>
- * <ul>
- * <p>
- * You can construct a Wildcard object from either its integer representation
- * </p>
- * <code>
- * Wildcard.of(0x3820e0);
- * </code>
- * <p>
- * Or start with either an empty or full wildcard, and select/unselect foo.
- * </p>
- * <code>
- * Wildcard w = Wildcards.NONE
- * .set(Flag.DL_SRC, Flag. DL_DST, Flag.DL_VLAN_PCP)
- * .setNwDstMask(8)
- * .setNwSrcMask(8);
- * </code>
- * <p>
- * <b>Remember:</b> Wildcards objects are immutable. set... operations have
- * <b>NO EFFECT</b> on the current wildcard object. You HAVE to use the returned
- * changed object.
- * </p>
- *
- * @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
- */
-public class Wildcards {
-
- public final static Wildcards FULL = new Wildcards(OFMatch.OFPFW_ALL_SANITIZED);
- private static final int FULL_INT = FULL.getInt();
-
- public final static Wildcards EXACT = new Wildcards(0);
-
- // floodlight common case: matches on inport + l2
- public final static int INT_INPORT_L2_MATCH = 0x3820e0;
- public final static Wildcards INPORT_L2_MATCH = new Wildcards(
- INT_INPORT_L2_MATCH);
-
- /**
- * enum type for the binary flags that can be set in the wildcards field of
- * an OFMatch. Replaces the unwieldy c-ish int constants in OFMatch.
- */
- public static enum Flag {
- IN_PORT(OFMatch.OFPFW_IN_PORT), /* Switch input port. */
- DL_VLAN(OFMatch.OFPFW_DL_VLAN), /* VLAN id. */
- DL_SRC(OFMatch.OFPFW_DL_SRC), /* Ethernet source address. */
- DL_DST(OFMatch.OFPFW_DL_DST), /* Ethernet destination addr */
- DL_TYPE(OFMatch.OFPFW_DL_TYPE), /* Ethernet frame type. */
- NW_PROTO(OFMatch.OFPFW_NW_PROTO), /* IP protocol. */
- TP_SRC(OFMatch.OFPFW_TP_SRC), /* TCP/UDP source port. */
- TP_DST(OFMatch.OFPFW_TP_DST), /* TCP/UDP destination port. */
- DL_VLAN_PCP(OFMatch.OFPFW_DL_VLAN_PCP), /* VLAN priority. */
- NW_SRC(-1) { /*
- * virtual NW_SRC flag => translates to the strange 6 bits
- * in the header
- */
- @Override
- boolean isBolean() {
- return false;
- }
-
- @Override
- int getInt(int flags) {
- return ((flags & OFMatch.OFPFW_NW_SRC_MASK) >> OFMatch.OFPFW_NW_SRC_SHIFT);
- }
-
- @Override
- int setInt(int flags, int srcMask) {
- return (flags & ~OFMatch.OFPFW_NW_SRC_MASK) | (srcMask << OFMatch.OFPFW_NW_SRC_SHIFT);
- }
-
- @Override
- int wildcard(int flags) {
- return flags & ~OFMatch.OFPFW_NW_SRC_MASK;
- }
-
- @Override
- int matchOn(int flags) {
- return flags | OFMatch.OFPFW_NW_SRC_ALL;
- }
-
- @Override
- boolean isPartiallyOn(int flags) {
- int intValue = getInt(flags);
- return intValue > 0 && intValue < 32;
- }
-
- @Override
- boolean isFullyOn(int flags) {
- return getInt(flags) >= 32;
- }
-
- },
- NW_DST(-1) { /*
- * virtual NW_SRC flag => translates to the strange 6 bits
- * in the header
- */
- @Override
- boolean isBolean() {
- return false;
- }
-
- @Override
- int getInt(int flags) {
- return ((flags & OFMatch.OFPFW_NW_DST_MASK) >> OFMatch.OFPFW_NW_DST_SHIFT);
- }
-
- @Override
- int setInt(int flags, int srcMask) {
- return (flags & ~OFMatch.OFPFW_NW_DST_MASK) | (srcMask << OFMatch.OFPFW_NW_DST_SHIFT);
- }
-
- @Override
- int wildcard(int flags) {
- return flags & ~OFMatch.OFPFW_NW_DST_MASK;
- }
-
- @Override
- int matchOn(int flags) {
- return flags | OFMatch.OFPFW_NW_DST_ALL;
- }
-
- @Override
- boolean isFullyOn(int flags) {
- return getInt(flags) >= 32;
- }
- },
- NW_TOS(OFMatch.OFPFW_NW_TOS); /* IP ToS (DSCP field, 6 bits). */
-
- final int bitPosition;
-
- Flag(int bitPosition) {
- this.bitPosition = bitPosition;
- }
-
- /**
- * @return a modified OF-1.0 flags field with this flag cleared (match
- * on this field)
- */
- int matchOn(int flags) {
- return flags & ~this.bitPosition;
- }
-
- /**
- * @return a modified OF-1.0 flags field with this flag set (wildcard
- * this field)
- */
- int wildcard(int flags) {
- return flags | this.bitPosition;
- }
-
- /**
- * @return true iff this is a true boolean flag that can either be off
- * or on.True in OF-1.0 for all fields except NW_SRC and NW_DST
- */
- boolean isBolean() {
- return false;
- }
-
- /**
- * @return true iff this wildcard field is currently 'partially on'.
- * Always false for true Boolean Flags. Can be true in OF-1.0
- * for NW_SRC, NW_DST.
- */
- boolean isPartiallyOn(int flags) {
- return false;
- }
-
- /**
- * @return true iff this wildcard field currently fully on (fully
- * wildcarded). Equivalent to the boolean flag being set in the
- * bitmask for bit flags, and to the wildcarded bit length set
- * to >=32 for NW_SRC and NW_DST
- * @param flags
- * @return
- */
- boolean isFullyOn(int flags) {
- return (flags & this.bitPosition) != 0;
- }
-
- /**
- * set the integer representation of this flag. only for NW_SRC and
- * NW_DST
- */
- int setInt(int flags, int srcMask) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * set the integer representation of this flag. only for NW_SRC and
- * NW_DST
- */
- int getInt(int flags) {
- throw new UnsupportedOperationException();
- }
-
-
- }
-
- private final int flags;
-
- /** private constructor. use Wildcard.of() instead */
- private Wildcards(int flags) {
- this.flags = flags;
- }
-
- /**
- * return a wildcard object matching the given int flags. May reuse / cache
- * frequently used wildcard instances. Don't rely on it though (use equals
- * not ==).
- *
- * @param flags
- * @return
- */
- public static Wildcards of(int paramFlags) {
- int flags = sanitizeInt(paramFlags);
- switch(flags) {
- case 0x0000:
- return EXACT;
- case OFMatch.OFPFW_ALL_SANITIZED:
- return FULL;
- case INT_INPORT_L2_MATCH:
- return INPORT_L2_MATCH;
- default:
- return new Wildcards(flags);
- }
- }
-
- /** convience method return a wildcard for exactly one set flag */
- public static Wildcards of(Wildcards.Flag setFlag) {
- return Wildcards.of(setFlag.wildcard(0));
- }
-
- /** convience method return a wildcard for exactly two set flags */
- public static Wildcards of(Wildcards.Flag setFlag, Wildcards.Flag setFlag2) {
- return Wildcards.of(setFlag.wildcard(setFlag2.wildcard(0)));
- }
-
- /** convience method return a wildcard for an arbitrary number of set flags */
- public static Wildcards of(Wildcards.Flag... setFlags) {
- int flags = 0;
- for (Wildcards.Flag flag : setFlags)
- flags = flag.wildcard(0);
- return Wildcards.of(flags);
- }
-
- /** convience method return a wildcards for ofmatches that match on one flag */
- public static Wildcards ofMatches(Wildcards.Flag setFlag) {
- return Wildcards.of(setFlag.matchOn(FULL_INT));
- }
-
- /**
- * convience method return a wildcard for for an ofmatch that match on two
- * flags
- */
- public static Wildcards ofMatches(Wildcards.Flag setFlag, Wildcards.Flag setFlag2) {
- return Wildcards.of(setFlag.matchOn(setFlag2.matchOn(FULL_INT)));
- }
-
- /**
- * convience method return a wildcard for an ofmatch that amtch on an
- * arbitrary number of set flags
- */
- public static Wildcards ofMatches(Wildcards.Flag... setFlags) {
- int flags = FULL_INT;
- for (Wildcards.Flag flag : setFlags)
- flags = flag.matchOn(flags);
- return Wildcards.of(flags);
- }
-
- /**
- * return a Wildcards object that has the given flags set
- * <p>
- * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
- * unmodified. </b>
- */
- public Wildcards wildcard(Wildcards.Flag flag) {
- int flags = flag.wildcard(this.flags);
- if (flags == this.flags)
- return this;
- else
- return new Wildcards(flags);
- }
-
- /**
- * return a Wildcards object that has the given flags set
- * <p>
- * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
- * unmodified. </b>
- */
- public Wildcards wildcard(Wildcards.Flag flag, Wildcards.Flag flag2) {
- int flags = flag.wildcard(flag2.wildcard(this.flags));
- if (flags == this.flags)
- return this;
- else
- return new Wildcards(flags);
- }
-
- /**
- * return a Wildcards object that has the given flags wildcarded
- * <p>
- * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
- * unmodified. </b>
- */
- public Wildcards wildcard(Wildcards.Flag... setFlags) {
- int flags = this.flags;
- for (Wildcards.Flag flag : setFlags)
- flags = flag.wildcard(flags);
- if (flags == this.flags)
- return this;
- else
- return new Wildcards(flags);
- }
-
- /**
- * return a Wildcards object that matches on exactly the given flag
- * <p>
- * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
- * unmodified. </b>
- */
- public Wildcards matchOn(Wildcards.Flag flag) {
- int flags = flag.matchOn(this.flags);
- if (flags == this.flags)
- return this;
- else
- return new Wildcards(flags);
- }
-
- /**
- * return a Wildcards object that matches on exactly the given flags
- * <p>
- * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
- * unmodified. </b>
- */
- public Wildcards matchOn(Wildcards.Flag flag, Wildcards.Flag flag2) {
- int flags = flag.matchOn(flag2.matchOn(this.flags));
- if (flags == this.flags)
- return this;
- else
- return new Wildcards(flags);
- }
-
- /**
- * return a Wildcards object that matches on exactly the given flags
- * <p>
- * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
- * unmodified. </b>
- */
- public Wildcards matchOn(Wildcards.Flag... setFlags) {
- int flags = this.flags;
- for (Wildcards.Flag flag : setFlags)
- flags = flag.matchOn(flags);
- if (flags == this.flags)
- return this;
- else
- return new Wildcards(flags);
- }
-
- /**
- * return the nw src mask in normal CIDR style, e.g., 8 means x.x.x.x/8
- * means 8 bits wildcarded
- */
- public int getNwSrcMask() {
- return Math.max(0, 32 - Flag.NW_SRC.getInt(flags));
- }
-
- /**
- * return the nw dst mask in normal CIDR style, e.g., 8 means x.x.x.x/8
- * means 8 bits wildcarded
- */
- public int getNwDstMask() {
- return Math.max(0, 32 - Flag.NW_DST.getInt(flags));
- }
-
- /**
- * return a Wildcard object that has the given nwSrcCidrMask set.
- * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
- * unmodified. </b>
- *
- * @param srcCidrMask
- * source mask to set in <b>normal CIDR notation</b>, i.e., 8
- * means x.x.x.x/8
- * @return a modified object
- */
- public Wildcards withNwSrcMask(int srcCidrMask) {
- int flags = Flag.NW_SRC.setInt(this.flags, Math.max(0, 32 - srcCidrMask));
- if (flags == this.flags)
- return this;
- else
- return new Wildcards(flags);
- }
-
- /**
- * return a Wildcard object that has the given nwDstCidrMask set.
- * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
- * unmodified. </b>
- *
- * @param dstCidrMask
- * dest mask to set in <b>normal CIDR notation</b>, i.e., 8 means
- * x.x.x.x/8
- * @return a modified object
- */
- public Wildcards withNwDstMask(int dstCidrMask) {
- int flags = Flag.NW_DST.setInt(this.flags, Math.max(0, 32 - dstCidrMask));
- if (flags == this.flags)
- return this;
- else
- return new Wildcards(flags);
- }
-
- /**
- * return a Wildcard object that is inverted to this wildcard object.
- * <b>NOTE:</b> NOT a mutator function. 'this' wildcard object stays
- * unmodified. </b>
- * @return a modified object
- */
- public Wildcards inverted() {
- return Wildcards.of(flags ^ OFMatch.OFPFW_ALL_SANITIZED);
- }
-
- public boolean isWildcarded(Flag flag) {
- return flag.isFullyOn(flags);
- }
-
- /**
- * return all wildcard flags that are fully wildcarded as an EnumSet. Do not
- * modify. Note: some flags (like NW_SRC and NW_DST) that are partially
- * wildcarded are not returned in this set.
- *
- * @return the EnumSet of wildcards
- */
- public EnumSet<Wildcards.Flag> getWildcardedFlags() {
- EnumSet<Wildcards.Flag> res = EnumSet.noneOf(Wildcards.Flag.class);
- for (Wildcards.Flag flag : Flag.values()) {
- if (flag.isFullyOn(flags)) {
- res.add(flag);
- }
- }
- return res;
- }
-
- /** return the OpenFlow 'wire' integer representation of these wildcards */
- public int getInt() {
- return flags;
- }
-
- /**
- * return the OpenFlow 'wire' integer representation of these wildcards.
- * Sanitize nw_src and nw_dst to be max. 32 (values > 32 are technically
- * possible, but don't make semantic sense)
- */
- public static int sanitizeInt(int flags) {
- if (((flags & OFMatch.OFPFW_NW_SRC_MASK) >> OFMatch.OFPFW_NW_SRC_SHIFT) > 32) {
- flags = (flags & ~OFMatch.OFPFW_NW_SRC_MASK) | OFMatch.OFPFW_NW_SRC_ALL;
- }
- if (((flags & OFMatch.OFPFW_NW_DST_MASK) >> OFMatch.OFPFW_NW_DST_SHIFT) > 32) {
- flags = (flags & ~OFMatch.OFPFW_NW_DST_MASK) | OFMatch.OFPFW_NW_DST_ALL;
- }
- return flags;
- }
-
- /**
- * is this a wildcard set that has all flags set + and full (/0) nw_src and
- * nw_dst wildcarding ?
- */
- public boolean isFull() {
- return flags == OFMatch.OFPFW_ALL || flags == OFMatch.OFPFW_ALL_SANITIZED;
- }
-
- /** is this a wildcard of an exact match */
- public boolean isExact() {
- return flags == 0;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + flags;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Wildcards other = (Wildcards) obj;
- if (flags != other.flags)
- return false;
- return true;
- }
-
-
-
-}
\ No newline at end of file
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.action;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.U16;
-
-/**
- * The base class for all OpenFlow Actions.
- *
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-public class OFAction implements Cloneable {
- /**
- * Note the true minimum length for this header is 8 including a pad to 64
- * bit alignment, however as this base class is used for demuxing an
- * incoming Action, it is only necessary to read the first 4 bytes. All
- * Actions extending this class are responsible for reading/writing the
- * first 8 bytes, including the pad if necessary.
- */
- public static int MINIMUM_LENGTH = 4;
- public static int OFFSET_LENGTH = 2;
- public static int OFFSET_TYPE = 0;
-
- protected OFActionType type;
- protected short length;
-
- /**
- * Get the length of this message
- *
- * @return
- */
- public short getLength() {
- return length;
- }
-
- /**
- * Get the length of this message, unsigned
- *
- * @return
- */
- public int getLengthU() {
- return U16.f(length);
- }
-
- /**
- * Set the length of this message
- *
- * @param length
- */
- public OFAction setLength(short length) {
- this.length = length;
- return this;
- }
-
- /**
- * Get the type of this message
- *
- * @return OFActionType enum
- */
- public OFActionType getType() {
- return this.type;
- }
-
- /**
- * Set the type of this message
- *
- * @param type
- */
- public void setType(OFActionType type) {
- this.type = type;
- }
-
- /**
- * Returns a summary of the message
- * @return "ofmsg=v=$version;t=$type:l=$len:xid=$xid"
- */
- public String toString() {
- return "ofaction" +
- ";t=" + this.getType() +
- ";l=" + this.getLength();
- }
-
- /**
- * Given the output from toString(),
- * create a new OFAction
- * @param val
- * @return
- */
- public static OFAction fromString(String val) {
- String tokens[] = val.split(";");
- if (!tokens[0].equals("ofaction"))
- throw new IllegalArgumentException("expected 'ofaction' but got '" +
- tokens[0] + "'");
- String type_tokens[] = tokens[1].split("=");
- String len_tokens[] = tokens[2].split("=");
- OFAction action = new OFAction();
- action.setLength(Short.valueOf(len_tokens[1]));
- action.setType(OFActionType.valueOf(type_tokens[1]));
- return action;
- }
-
- public void readFrom(ChannelBuffer data) {
- this.type = OFActionType.valueOf(data.readShort());
- this.length = data.readShort();
- // Note missing PAD, see MINIMUM_LENGTH comment for details
- }
-
- public void writeTo(ChannelBuffer data) {
- data.writeShort(type.getTypeValue());
- data.writeShort(length);
- // Note missing PAD, see MINIMUM_LENGTH comment for details
- }
-
- @Override
- public int hashCode() {
- final int prime = 347;
- int result = 1;
- result = prime * result + length;
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFAction)) {
- return false;
- }
- OFAction other = (OFAction) obj;
- if (length != other.length) {
- return false;
- }
- if (type == null) {
- if (other.type != null) {
- return false;
- }
- } else if (!type.equals(other.type)) {
- return false;
- }
- return true;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#clone()
- */
- @Override
- public OFAction clone() throws CloneNotSupportedException {
- return (OFAction) super.clone();
- }
-
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-/**
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-package org.openflow.protocol.action;
-
-import java.util.Arrays;
-
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.OFPhysicalPort;
-
-/**
- * Represents an ofp_action_dl_addr
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-public abstract class OFActionDataLayer extends OFAction {
- public static int MINIMUM_LENGTH = 16;
-
- protected byte[] dataLayerAddress;
-
- /**
- * @return the dataLayerAddress
- */
- public byte[] getDataLayerAddress() {
- return dataLayerAddress;
- }
-
- /**
- * @param dataLayerAddress the dataLayerAddress to set
- */
- public void setDataLayerAddress(byte[] dataLayerAddress) {
- this.dataLayerAddress = dataLayerAddress;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- if (this.dataLayerAddress == null)
- this.dataLayerAddress = new byte[OFPhysicalPort.OFP_ETH_ALEN];
- data.readBytes(this.dataLayerAddress);
- data.readInt();
- data.readShort();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeBytes(this.dataLayerAddress);
- data.writeInt(0);
- data.writeShort((short) 0);
- }
-
- @Override
- public int hashCode() {
- final int prime = 347;
- int result = super.hashCode();
- result = prime * result + Arrays.hashCode(dataLayerAddress);
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFActionDataLayer)) {
- return false;
- }
- OFActionDataLayer other = (OFActionDataLayer) obj;
- if (!Arrays.equals(dataLayerAddress, other.dataLayerAddress)) {
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.action;
-
-/**
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFActionDataLayerDestination extends OFActionDataLayer {
- public OFActionDataLayerDestination() {
- super();
- super.setType(OFActionType.SET_DL_DST);
- super.setLength((short) OFActionDataLayer.MINIMUM_LENGTH);
- }
-
- public OFActionDataLayerDestination(byte[] address) {
- this();
- this.dataLayerAddress = address;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.action;
-
-/**
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFActionDataLayerSource extends OFActionDataLayer {
- public OFActionDataLayerSource() {
- super();
- super.setType(OFActionType.SET_DL_SRC);
- super.setLength((short) OFActionDataLayer.MINIMUM_LENGTH);
- }
-
- public OFActionDataLayerSource(byte[] address) {
- this();
- this.dataLayerAddress = address;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-/**
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-package org.openflow.protocol.action;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Represents an ofp_action_enqueue
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-public class OFActionEnqueue extends OFAction {
- public static int MINIMUM_LENGTH = 16;
-
- protected short port;
- protected int queueId;
-
- public OFActionEnqueue() {
- super.setType(OFActionType.OPAQUE_ENQUEUE);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- public OFActionEnqueue(short port, int queueId) {
- this();
- this.port = port;
- this.queueId = queueId;
- }
-
- /**
- * Get the output port
- * @return
- */
- public short getPort() {
- return this.port;
- }
-
- /**
- * Set the output port
- * @param port
- */
- public void setPort(short port) {
- this.port = port;
- }
-
- /**
- * @return the queueId
- */
- public int getQueueId() {
- return queueId;
- }
-
- /**
- * @param queueId the queueId to set
- */
- public void setQueueId(int queueId) {
- this.queueId = queueId;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.port = data.readShort();
- data.readShort();
- data.readInt();
- this.queueId = data.readInt();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeShort(this.port);
- data.writeShort((short) 0);
- data.writeInt(0);
- data.writeInt(this.queueId);
- }
-
- @Override
- public int hashCode() {
- final int prime = 349;
- int result = super.hashCode();
- result = prime * result + port;
- result = prime * result + queueId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFActionEnqueue)) {
- return false;
- }
- OFActionEnqueue other = (OFActionEnqueue) obj;
- if (port != other.port) {
- return false;
- }
- if (queueId != other.queueId) {
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-/**
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-package org.openflow.protocol.action;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Represents an ofp_action_nw_addr
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-public abstract class OFActionNetworkLayerAddress extends OFAction {
- public static int MINIMUM_LENGTH = 8;
-
- protected int networkAddress;
-
- /**
- * @return the networkAddress
- */
- public int getNetworkAddress() {
- return networkAddress;
- }
-
- /**
- * @param networkAddress the networkAddress to set
- */
- public void setNetworkAddress(int networkAddress) {
- this.networkAddress = networkAddress;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.networkAddress = data.readInt();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeInt(this.networkAddress);
- }
-
- @Override
- public int hashCode() {
- final int prime = 353;
- int result = super.hashCode();
- result = prime * result + networkAddress;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFActionNetworkLayerAddress)) {
- return false;
- }
- OFActionNetworkLayerAddress other = (OFActionNetworkLayerAddress) obj;
- if (networkAddress != other.networkAddress) {
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.action;
-
-/**
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFActionNetworkLayerDestination extends OFActionNetworkLayerAddress {
- public OFActionNetworkLayerDestination() {
- super();
- super.setType(OFActionType.SET_NW_DST);
- super.setLength((short) OFActionNetworkLayerAddress.MINIMUM_LENGTH);
- }
-
- public OFActionNetworkLayerDestination(int ip) {
- this();
- this.networkAddress = ip;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.action;
-
-/**
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFActionNetworkLayerSource extends OFActionNetworkLayerAddress {
- public OFActionNetworkLayerSource() {
- super();
- super.setType(OFActionType.SET_NW_SRC);
- super.setLength((short) OFActionNetworkLayerAddress.MINIMUM_LENGTH);
- }
-
- public OFActionNetworkLayerSource(int ip) {
- this();
- this.networkAddress = ip;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-/**
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-package org.openflow.protocol.action;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Represents an ofp_action_enqueue
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-public class OFActionNetworkTypeOfService extends OFAction {
- public static int MINIMUM_LENGTH = 8;
-
- protected byte networkTypeOfService;
-
- public OFActionNetworkTypeOfService() {
- super.setType(OFActionType.SET_NW_TOS);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- public OFActionNetworkTypeOfService(byte tos) {
- this();
- this.networkTypeOfService = tos;
- }
-
-
- /**
- * @return the networkTypeOfService
- */
- public byte getNetworkTypeOfService() {
- return networkTypeOfService;
- }
-
- /**
- * @param networkTypeOfService the networkTypeOfService to set
- */
- public void setNetworkTypeOfService(byte networkTypeOfService) {
- this.networkTypeOfService = networkTypeOfService;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.networkTypeOfService = data.readByte();
- data.readShort();
- data.readByte();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeByte(this.networkTypeOfService);
- data.writeShort((short) 0);
- data.writeByte((byte) 0);
- }
-
- @Override
- public int hashCode() {
- final int prime = 359;
- int result = super.hashCode();
- result = prime * result + networkTypeOfService;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFActionNetworkTypeOfService)) {
- return false;
- }
- OFActionNetworkTypeOfService other = (OFActionNetworkTypeOfService) obj;
- if (networkTypeOfService != other.networkTypeOfService) {
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-/**
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-package org.openflow.protocol.action;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.U16;
-
-/**
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- */
-public class OFActionOutput extends OFAction implements Cloneable {
- public static int MINIMUM_LENGTH = 8;
-
- protected short port;
- protected short maxLength;
-
- public OFActionOutput() {
- super.setType(OFActionType.OUTPUT);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- /**
- * Create an Output Action sending packets out the specified
- * OpenFlow port.
- *
- * This is the most common creation pattern for OFActions.
- *
- * @param port
- */
-
- public OFActionOutput(short port) {
- this(port, (short) 65535);
- }
-
- /**
- * Create an Output Action specifying both the port AND
- * the snaplen of the packet to send out that port.
- * The length field is only meaningful when port == OFPort.OFPP_CONTROLLER
- * @param port
- * @param maxLength The maximum number of bytes of the packet to send.
- * Most hardware only supports this value for OFPP_CONTROLLER
- */
-
- public OFActionOutput(short port, short maxLength) {
- super();
- super.setType(OFActionType.OUTPUT);
- super.setLength((short) MINIMUM_LENGTH);
- this.port = port;
- this.maxLength = maxLength;
- }
-
- /**
- * Get the output port
- * @return
- */
- public short getPort() {
- return this.port;
- }
-
- /**
- * Set the output port
- * @param port
- */
- public OFActionOutput setPort(short port) {
- this.port = port;
- return this;
- }
-
- /**
- * Get the max length to send to the controller
- * @return
- */
- public short getMaxLength() {
- return this.maxLength;
- }
-
- /**
- * Set the max length to send to the controller
- * @param maxLength
- */
- public OFActionOutput setMaxLength(short maxLength) {
- this.maxLength = maxLength;
- return this;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.port = data.readShort();
- this.maxLength = data.readShort();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeShort(port);
- data.writeShort(maxLength);
- }
-
- @Override
- public int hashCode() {
- final int prime = 367;
- int result = super.hashCode();
- result = prime * result + maxLength;
- result = prime * result + port;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFActionOutput)) {
- return false;
- }
- OFActionOutput other = (OFActionOutput) obj;
- if (maxLength != other.maxLength) {
- return false;
- }
- if (port != other.port) {
- return false;
- }
- return true;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "OFActionOutput [maxLength=" + maxLength + ", port=" + U16.f(port)
- + ", length=" + length + ", type=" + type + "]";
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-/**
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-package org.openflow.protocol.action;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-
-/**
- * Represents an ofp_action_strip_vlan
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-public class OFActionStripVirtualLan extends OFAction {
- public static int MINIMUM_LENGTH = 8;
-
- public OFActionStripVirtualLan() {
- super();
- super.setType(OFActionType.STRIP_VLAN);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- // PAD
- data.readInt();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- // PAD
- data.writeInt(0);
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-/**
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-package org.openflow.protocol.action;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Represents an ofp_action_tp_port
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-public abstract class OFActionTransportLayer extends OFAction {
- public static int MINIMUM_LENGTH = 8;
-
- protected short transportPort;
-
- /**
- * @return the transportPort
- */
- public short getTransportPort() {
- return transportPort;
- }
-
- /**
- * @param transportPort the transportPort to set
- */
- public void setTransportPort(short transportPort) {
- this.transportPort = transportPort;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.transportPort = data.readShort();
- data.readShort();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeShort(this.transportPort);
- data.writeShort((short) 0);
- }
-
- @Override
- public int hashCode() {
- final int prime = 373;
- int result = super.hashCode();
- result = prime * result + transportPort;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFActionTransportLayer)) {
- return false;
- }
- OFActionTransportLayer other = (OFActionTransportLayer) obj;
- if (transportPort != other.transportPort) {
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.action;
-
-/**
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFActionTransportLayerDestination extends OFActionTransportLayer {
- public OFActionTransportLayerDestination() {
- super();
- super.setType(OFActionType.SET_TP_DST);
- super.setLength((short) OFActionTransportLayer.MINIMUM_LENGTH);
- }
-
- public OFActionTransportLayerDestination(short port) {
- this();
- this.transportPort = port;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.action;
-
-/**
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFActionTransportLayerSource extends OFActionTransportLayer {
- public OFActionTransportLayerSource() {
- super();
- super.setType(OFActionType.SET_TP_SRC);
- super.setLength((short) OFActionTransportLayer.MINIMUM_LENGTH);
- }
-
- public OFActionTransportLayerSource(short port) {
- this();
- this.transportPort = port;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-/**
- *
- */
-package org.openflow.protocol.action;
-
-import java.lang.reflect.Constructor;
-
-import org.openflow.protocol.Instantiable;
-
-/**
- * List of OpenFlow Action types and mappings to wire protocol value and
- * derived classes
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public enum OFActionType {
- OUTPUT (0, OFActionOutput.class, new Instantiable<OFAction>() {
- @Override
- public OFAction instantiate() {
- return new OFActionOutput();
- }}),
- SET_VLAN_ID (1, OFActionVirtualLanIdentifier.class, new Instantiable<OFAction>() {
- @Override
- public OFAction instantiate() {
- return new OFActionVirtualLanIdentifier();
- }}),
- SET_VLAN_PCP (2, OFActionVirtualLanPriorityCodePoint.class, new Instantiable<OFAction>() {
- @Override
- public OFAction instantiate() {
- return new OFActionVirtualLanPriorityCodePoint();
- }}),
- STRIP_VLAN (3, OFActionStripVirtualLan.class, new Instantiable<OFAction>() {
- @Override
- public OFAction instantiate() {
- return new OFActionStripVirtualLan();
- }}),
- SET_DL_SRC (4, OFActionDataLayerSource.class, new Instantiable<OFAction>() {
- @Override
- public OFAction instantiate() {
- return new OFActionDataLayerSource();
- }}),
- SET_DL_DST (5, OFActionDataLayerDestination.class, new Instantiable<OFAction>() {
- @Override
- public OFAction instantiate() {
- return new OFActionDataLayerDestination();
- }}),
- SET_NW_SRC (6, OFActionNetworkLayerSource.class, new Instantiable<OFAction>() {
- @Override
- public OFAction instantiate() {
- return new OFActionNetworkLayerSource();
- }}),
- SET_NW_DST (7, OFActionNetworkLayerDestination.class, new Instantiable<OFAction>() {
- @Override
- public OFAction instantiate() {
- return new OFActionNetworkLayerDestination();
- }}),
- SET_NW_TOS (8, OFActionNetworkTypeOfService.class, new Instantiable<OFAction>() {
- @Override
- public OFAction instantiate() {
- return new OFActionNetworkTypeOfService();
- }}),
- SET_TP_SRC (9, OFActionTransportLayerSource.class, new Instantiable<OFAction>() {
- @Override
- public OFAction instantiate() {
- return new OFActionTransportLayerSource();
- }}),
- SET_TP_DST (10, OFActionTransportLayerDestination.class, new Instantiable<OFAction>() {
- @Override
- public OFAction instantiate() {
- return new OFActionTransportLayerDestination();
- }}),
- OPAQUE_ENQUEUE (11, OFActionEnqueue.class, new Instantiable<OFAction>() {
- @Override
- public OFAction instantiate() {
- return new OFActionEnqueue();
- }}),
- VENDOR (0xffff, OFActionVendor.class, new Instantiable<OFAction>() {
- @Override
- public OFAction instantiate() {
- return new OFActionVendorGeneric();
- }});
-
- protected static OFActionType[] mapping;
-
- protected Class<? extends OFAction> clazz;
- protected Constructor<? extends OFAction> constructor;
- protected Instantiable<OFAction> instantiable;
- protected int minLen;
- protected short type;
-
- /**
- * Store some information about the OpenFlow Action type, including wire
- * protocol type number, length, and derrived class
- *
- * @param type Wire protocol number associated with this OFType
- * @param clazz The Java class corresponding to this type of OpenFlow Action
- * @param instantiable the instantiable for the OFAction this type represents
- */
- OFActionType(int type, Class<? extends OFAction> clazz, Instantiable<OFAction> instantiable) {
- this.type = (short) type;
- this.clazz = clazz;
- this.instantiable = instantiable;
- try {
- this.constructor = clazz.getConstructor(new Class[]{});
- } catch (Exception e) {
- throw new RuntimeException(
- "Failure getting constructor for class: " + clazz, e);
- }
- OFActionType.addMapping(this.type, this);
- }
-
- /**
- * Adds a mapping from type value to OFActionType enum
- *
- * @param i OpenFlow wire protocol Action type value
- * @param t type
- */
- static public void addMapping(short i, OFActionType t) {
- if (mapping == null)
- mapping = new OFActionType[16];
- // bring higher mappings down to the edge of our array
- if (i < 0)
- i = (short) (16 + i);
- OFActionType.mapping[i] = t;
- }
-
- /**
- * Given a wire protocol OpenFlow type number, return the OFType associated
- * with it
- *
- * @param i wire protocol number
- * @return OFType enum type
- */
-
- static public OFActionType valueOf(short i) {
- if (i < 0)
- i = (short) (16+i);
- return OFActionType.mapping[i];
- }
-
- /**
- * @return Returns the wire protocol value corresponding to this
- * OFActionType
- */
- public short getTypeValue() {
- return this.type;
- }
-
- /**
- * @return return the OFAction subclass corresponding to this OFActionType
- */
- public Class<? extends OFAction> toClass() {
- return clazz;
- }
-
- /**
- * Returns the no-argument Constructor of the implementation class for
- * this OFActionType
- * @return the constructor
- */
- public Constructor<? extends OFAction> getConstructor() {
- return constructor;
- }
-
- /**
- * Returns a new instance of the OFAction represented by this OFActionType
- * @return the new object
- */
- public OFAction newInstance() {
- return instantiable.instantiate();
- }
-
- /**
- * @return the instantiable
- */
- public Instantiable<OFAction> getInstantiable() {
- return instantiable;
- }
-
- /**
- * @param instantiable the instantiable to set
- */
- public void setInstantiable(Instantiable<OFAction> instantiable) {
- this.instantiable = instantiable;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.action;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public abstract class OFActionVendor extends OFAction {
- public static int MINIMUM_LENGTH = 8;
-
- protected int vendor;
-
- public OFActionVendor() {
- super();
- super.setType(OFActionType.VENDOR);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- /**
- * @return the vendor
- */
- public int getVendor() {
- return vendor;
- }
-
- /**
- * @param vendor the vendor to set
- */
- public void setVendor(int vendor) {
- this.vendor = vendor;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.vendor = data.readInt();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeInt(this.vendor);
- }
-
- @Override
- public int hashCode() {
- final int prime = 379;
- int result = super.hashCode();
- result = prime * result + vendor;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFActionVendor)) {
- return false;
- }
- OFActionVendor other = (OFActionVendor) obj;
- if (vendor != other.vendor) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- return super.toString() + "; vendor=" + vendor;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.action;
-
-
-import java.util.Arrays;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/** A generic / unparsed vendor action. This action is returned by
- * BasicFactory.readFromWire if no more specific OFVendorActionFactory
- * is registered.
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
- */
-public class OFActionVendorGeneric extends OFActionVendor {
- public static int MINIMUM_LENGTH = 8;
-
- private final static byte[] EMPTY_ARRAY = new byte[0];
-
- protected byte[] vendorData;
-
- public OFActionVendorGeneric() {
- super();
- }
-
- public byte[] getVendorData() {
- return vendorData;
- }
-
- public void setVendorData(byte[] vendorData) {
- this.vendorData = vendorData;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
-
- int vendorDataLength = this.getLength() - MINIMUM_LENGTH;
- if (vendorDataLength > 0) {
- vendorData = new byte[vendorDataLength];
- data.readBytes(vendorData);
- } else {
- vendorData = EMPTY_ARRAY;
- }
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeInt(this.vendor);
- data.writeBytes(vendorData);
- }
-
- @Override
- public int hashCode() {
- final int prime = 379;
- int result = super.hashCode();
- result = prime * result + Arrays.hashCode(vendorData);
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFActionVendorGeneric)) {
- return false;
- }
- OFActionVendorGeneric other = (OFActionVendorGeneric) obj;
- if (!Arrays.equals(vendorData, other.vendorData)) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-/**
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-package org.openflow.protocol.action;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Represents an ofp_action_vlan_vid
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-public class OFActionVirtualLanIdentifier extends OFAction {
- public static int MINIMUM_LENGTH = 8;
-
- protected short virtualLanIdentifier;
-
- public OFActionVirtualLanIdentifier() {
- super.setType(OFActionType.SET_VLAN_ID);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- public OFActionVirtualLanIdentifier(short vlanId) {
- this();
- this.virtualLanIdentifier = vlanId;
- }
-
- /**
- * @return the virtualLanIdentifier
- */
- public short getVirtualLanIdentifier() {
- return virtualLanIdentifier;
- }
-
- /**
- * @param virtualLanIdentifier the virtualLanIdentifier to set
- */
- public void setVirtualLanIdentifier(short virtualLanIdentifier) {
- this.virtualLanIdentifier = virtualLanIdentifier;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.virtualLanIdentifier = data.readShort();
- data.readShort();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeShort(this.virtualLanIdentifier);
- data.writeShort((short) 0);
- }
-
- @Override
- public int hashCode() {
- final int prime = 383;
- int result = super.hashCode();
- result = prime * result + virtualLanIdentifier;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFActionVirtualLanIdentifier)) {
- return false;
- }
- OFActionVirtualLanIdentifier other = (OFActionVirtualLanIdentifier) obj;
- if (virtualLanIdentifier != other.virtualLanIdentifier) {
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-/**
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-package org.openflow.protocol.action;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Represents an ofp_action_vlan_pcp
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-public class OFActionVirtualLanPriorityCodePoint extends OFAction {
- public static int MINIMUM_LENGTH = 8;
-
- protected byte virtualLanPriorityCodePoint;
-
- public OFActionVirtualLanPriorityCodePoint() {
- super.setType(OFActionType.SET_VLAN_PCP);
- super.setLength((short) MINIMUM_LENGTH);
- }
-
- public OFActionVirtualLanPriorityCodePoint(byte priority) {
- this();
- this.virtualLanPriorityCodePoint = priority;
- }
-
- /**
- * @return the virtualLanPriorityCodePoint
- */
- public byte getVirtualLanPriorityCodePoint() {
- return virtualLanPriorityCodePoint;
- }
-
- /**
- * @param virtualLanPriorityCodePoint the virtualLanPriorityCodePoint to set
- */
- public void setVirtualLanPriorityCodePoint(byte virtualLanPriorityCodePoint) {
- this.virtualLanPriorityCodePoint = virtualLanPriorityCodePoint;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
- this.virtualLanPriorityCodePoint = data.readByte();
- data.readShort(); // pad
- data.readByte(); // pad
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeByte(this.virtualLanPriorityCodePoint);
- data.writeShort((short) 0);
- data.writeByte((byte) 0);
- }
-
- @Override
- public int hashCode() {
- final int prime = 389;
- int result = super.hashCode();
- result = prime * result + virtualLanPriorityCodePoint;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (!(obj instanceof OFActionVirtualLanPriorityCodePoint)) {
- return false;
- }
- OFActionVirtualLanPriorityCodePoint other = (OFActionVirtualLanPriorityCodePoint) obj;
- if (virtualLanPriorityCodePoint != other.virtualLanPriorityCodePoint) {
- return false;
- }
- return true;
- }
-}
\ No newline at end of file
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.factory;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.OFMessage;
-import org.openflow.protocol.OFType;
-import org.openflow.protocol.action.OFAction;
-import org.openflow.protocol.action.OFActionType;
-import org.openflow.protocol.action.OFActionVendor;
-import org.openflow.protocol.statistics.OFStatistics;
-import org.openflow.protocol.statistics.OFStatisticsType;
-import org.openflow.protocol.statistics.OFVendorStatistics;
-import org.openflow.protocol.vendor.OFByteArrayVendorData;
-import org.openflow.protocol.vendor.OFVendorData;
-import org.openflow.protocol.vendor.OFVendorDataType;
-import org.openflow.protocol.vendor.OFVendorId;
-
-
-/**
- * A basic OpenFlow factory that supports naive creation of both Messages and
- * Actions.
- *
- * @author David Erickson (daviderickson@cs.stanford.edu)
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- *
- */
-public class BasicFactory implements OFMessageFactory, OFActionFactory,
- OFStatisticsFactory, OFVendorDataFactory {
-
- private final OFVendorActionRegistry vendorActionRegistry;
-
- public BasicFactory() {
- vendorActionRegistry = OFVendorActionRegistry.getInstance();
- }
-
- /**
- * create and return a new instance of a message for OFType t. Also injects
- * factories for those message types that implement the *FactoryAware
- * interfaces.
- *
- * @return a newly created instance that may be modified / used freely by
- * the caller
- */
- @Override
- public OFMessage getMessage(OFType t) {
- OFMessage message = t.newInstance();
- injectFactories(message);
- return message;
- }
-
- @Override
- public List<OFMessage> parseMessage(ChannelBuffer data) throws MessageParseException {
- List<OFMessage> msglist = new ArrayList<OFMessage>();
- OFMessage msg = null;
-
- while (data.readableBytes() >= OFMessage.MINIMUM_LENGTH) {
- data.markReaderIndex();
- msg = this.parseMessageOne(data);
- if (msg == null) {
- data.resetReaderIndex();
- break;
- }
- else {
- msglist.add(msg);
- }
- }
-
- if (msglist.size() == 0) {
- return null;
- }
- return msglist;
-
- }
-
- public OFMessage parseMessageOne(ChannelBuffer data) throws MessageParseException {
- try {
- OFMessage demux = new OFMessage();
- OFMessage ofm = null;
-
- if (data.readableBytes() < OFMessage.MINIMUM_LENGTH)
- return ofm;
-
- data.markReaderIndex();
- demux.readFrom(data);
- data.resetReaderIndex();
-
- if (demux.getLengthU() > data.readableBytes())
- return ofm;
-
- ofm = getMessage(demux.getType());
- if (ofm == null)
- return null;
-
- injectFactories(ofm);
- ofm.readFrom(data);
- if (OFMessage.class.equals(ofm.getClass())) {
- // advance the position for un-implemented messages
- data.readerIndex(data.readerIndex()+(ofm.getLengthU() -
- OFMessage.MINIMUM_LENGTH));
- }
-
- return ofm;
- } catch (Exception e) {
- /* Write the offending data along with the error message */
- data.resetReaderIndex();
- String msg =
- "Message Parse Error for packet:" + dumpBuffer(data) +
- "\nException: " + e.toString();
- data.resetReaderIndex();
-
- throw new MessageParseException(msg, e);
- }
- }
-
-
-
-
- private void injectFactories(OFMessage ofm) {
- if (ofm instanceof OFActionFactoryAware) {
- ((OFActionFactoryAware)ofm).setActionFactory(this);
- }
- if (ofm instanceof OFMessageFactoryAware) {
- ((OFMessageFactoryAware)ofm).setMessageFactory(this);
- }
- if (ofm instanceof OFStatisticsFactoryAware) {
- ((OFStatisticsFactoryAware)ofm).setStatisticsFactory(this);
- }
- if (ofm instanceof OFVendorDataFactoryAware) {
- ((OFVendorDataFactoryAware)ofm).setVendorDataFactory(this);
- }
- }
-
- @Override
- public OFAction getAction(OFActionType t) {
- return t.newInstance();
- }
-
- @Override
- public List<OFAction> parseActions(ChannelBuffer data, int length) {
- return parseActions(data, length, 0);
- }
-
- @Override
- public List<OFAction> parseActions(ChannelBuffer data, int length, int limit) {
- List<OFAction> results = new ArrayList<OFAction>();
- OFAction demux = new OFAction();
- OFAction ofa;
- int end = data.readerIndex() + length;
-
- while (limit == 0 || results.size() <= limit) {
- if ((data.readableBytes() < OFAction.MINIMUM_LENGTH ||
- (data.readerIndex() + OFAction.MINIMUM_LENGTH) > end))
- return results;
-
- data.markReaderIndex();
- demux.readFrom(data);
- data.resetReaderIndex();
-
- if ((demux.getLengthU() > data.readableBytes() ||
- (data.readerIndex() + demux.getLengthU()) > end))
- return results;
-
- ofa = parseActionOne(demux.getType(), data);
- results.add(ofa);
- }
-
- return results;
- }
-
- private OFAction parseActionOne(OFActionType type, ChannelBuffer data) {
- OFAction ofa;
- data.markReaderIndex();
- ofa = getAction(type);
- ofa.readFrom(data);
-
- if(type == OFActionType.VENDOR) {
- OFActionVendor vendorAction = (OFActionVendor) ofa;
-
- OFVendorActionFactory vendorActionFactory = vendorActionRegistry.get(vendorAction.getVendor());
-
- if(vendorActionFactory != null) {
- // if we have a specific vendorActionFactory for this vendor id,
- // delegate to it for vendor-specific reparsing of the message
- data.resetReaderIndex();
- OFActionVendor newAction = vendorActionFactory.readFrom(data);
- if(newAction != null)
- ofa = newAction;
- }
- }
-
- if (OFAction.class.equals(ofa.getClass())) {
- // advance the position for un-implemented messages
- data.readerIndex(data.readerIndex()+(ofa.getLengthU() -
- OFAction.MINIMUM_LENGTH));
- }
- return ofa;
- }
-
- @Override
- public OFActionFactory getActionFactory() {
- return this;
- }
-
- @Override
- public OFStatistics getStatistics(OFType t, OFStatisticsType st) {
- return st.newInstance(t);
- }
-
- @Override
- public List<OFStatistics> parseStatistics(OFType t, OFStatisticsType st,
- ChannelBuffer data, int length) {
- return parseStatistics(t, st, data, length, 0);
- }
-
- /**
- * @param t
- * OFMessage type: should be one of stats_request or stats_reply
- * @param st
- * statistics type of this message, e.g., DESC, TABLE
- * @param data
- * buffer to read from
- * @param length
- * length of statistics
- * @param limit
- * number of statistics to grab; 0 == all
- *
- * @return list of statistics
- */
-
- @Override
- public List<OFStatistics> parseStatistics(OFType t, OFStatisticsType st,
- ChannelBuffer data, int length, int limit) {
- List<OFStatistics> results = new ArrayList<OFStatistics>();
- OFStatistics statistics = getStatistics(t, st);
-
- int start = data.readerIndex();
- int count = 0;
-
- while (limit == 0 || results.size() <= limit) {
- // TODO Create a separate MUX/DEMUX path for vendor stats
- if (statistics instanceof OFVendorStatistics)
- ((OFVendorStatistics)statistics).setLength(length);
-
- /**
- * can't use data.remaining() here, b/c there could be other data
- * buffered past this message
- */
- if ((length - count) >= statistics.getLength()) {
- if (statistics instanceof OFActionFactoryAware)
- ((OFActionFactoryAware)statistics).setActionFactory(this);
- statistics.readFrom(data);
- results.add(statistics);
- count += statistics.getLength();
- statistics = getStatistics(t, st);
- } else {
- if (count < length) {
- /**
- * Nasty case: partial/incomplete statistic found even
- * though we have a full message. Found when NOX sent
- * agg_stats request with wrong agg statistics length (52
- * instead of 56)
- *
- * just throw the rest away, or we will break framing
- */
- data.readerIndex(start + length);
- }
- return results;
- }
- }
- return results; // empty; no statistics at all
- }
-
-
- @Override
- public OFVendorData getVendorData(OFVendorId vendorId,
- OFVendorDataType vendorDataType) {
- if (vendorDataType == null)
- return null;
-
- return vendorDataType.newInstance();
- }
-
- /**
- * Attempts to parse and return the OFVendorData contained in the given
- * ChannelBuffer, beginning right after the vendor id.
- * @param vendor the vendor id that was parsed from the OFVendor message.
- * @param data the ChannelBuffer from which to parse the vendor data
- * @param length the length to the end of the enclosing message.
- * @return an OFVendorData instance
- */
- @Override
- public OFVendorData parseVendorData(int vendor, ChannelBuffer data,
- int length) {
- OFVendorDataType vendorDataType = null;
- OFVendorId vendorId = OFVendorId.lookupVendorId(vendor);
- if (vendorId != null) {
- data.markReaderIndex();
- vendorDataType = vendorId.parseVendorDataType(data, length);
- data.resetReaderIndex();
- }
-
- OFVendorData vendorData = getVendorData(vendorId, vendorDataType);
- if (vendorData == null)
- vendorData = new OFByteArrayVendorData();
-
- vendorData.readFrom(data, length);
-
- return vendorData;
- }
-
- public static String dumpBuffer(ChannelBuffer data) {
- // NOTE: Reads all the bytes in buffer from current read offset.
- // Set/Reset ReaderIndex if you want to read from a different location
- int len = data.readableBytes();
- StringBuffer sb = new StringBuffer();
- for (int i=0 ; i<len; i++) {
- if (i%32 == 0) sb.append("\n");
- if (i%4 == 0) sb.append(" ");
- sb.append(String.format("%02x", data.getUnsignedByte(i)));
- }
- return sb.toString();
- }
-
-}
+++ /dev/null
-/**
- * Copyright 2013, Big Switch Networks, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License. You may obtain
- * a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- **/
-
-package org.openflow.protocol.factory;
-
-/**
- * Exception thrown when an openflow message fails to parse properly
- */
-public class MessageParseException extends Exception {
- /**
- *
- */
- private static final long serialVersionUID = -75893812926304726L;
-
- public MessageParseException() {
- super();
- }
-
- public MessageParseException(String message, Throwable cause) {
- super(message, cause);
- this.setStackTrace(cause.getStackTrace());
- }
-
- public MessageParseException(String message) {
- super(message);
- }
-
- public MessageParseException(Throwable cause) {
- super(cause);
- this.setStackTrace(cause.getStackTrace());
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.factory;
-
-import java.util.List;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.action.OFAction;
-import org.openflow.protocol.action.OFActionType;
-
-
-/**
- * The interface to factories used for retrieving OFAction instances. All
- * methods are expected to be thread-safe.
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public interface OFActionFactory {
- /**
- * Retrieves an OFAction instance corresponding to the specified
- * OFActionType
- * @param t the type of the OFAction to be retrieved
- * @return an OFAction instance
- */
- public OFAction getAction(OFActionType t);
-
- /**
- * Attempts to parse and return all OFActions contained in the given
- * ByteBuffer, beginning at the ByteBuffer's position, and ending at
- * position+length.
- * @param data the ChannelBuffer to parse for OpenFlow actions
- * @param length the number of Bytes to examine for OpenFlow actions
- * @return a list of OFAction instances
- */
- public List<OFAction> parseActions(ChannelBuffer data, int length);
-
- /**
- * Attempts to parse and return all OFActions contained in the given
- * ByteBuffer, beginning at the ByteBuffer's position, and ending at
- * position+length.
- * @param data the ChannelBuffer to parse for OpenFlow actions
- * @param length the number of Bytes to examine for OpenFlow actions
- * @param limit the maximum number of messages to return, 0 means no limit
- * @return a list of OFAction instances
- */
- public List<OFAction> parseActions(ChannelBuffer data, int length, int limit);
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.factory;
-
-/**
- * Objects implementing this interface are expected to be instantiated with an
- * instance of an OFActionFactory
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public interface OFActionFactoryAware {
- /**
- * Sets the OFActionFactory
- * @param actionFactory
- */
- public void setActionFactory(OFActionFactory actionFactory);
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.factory;
-
-import java.util.List;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.OFMessage;
-import org.openflow.protocol.OFType;
-
-
-/**
- * The interface to factories used for retrieving OFMessage instances. All
- * methods are expected to be thread-safe.
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public interface OFMessageFactory {
- /**
- * Retrieves an OFMessage instance corresponding to the specified OFType
- * @param t the type of the OFMessage to be retrieved
- * @return an OFMessage instance
- */
- public OFMessage getMessage(OFType t);
-
- /**
- * Attempts to parse and return a OFMessages contained in the given
- * ChannelBuffer, beginning at the ChannelBuffer's position, and ending at the
- * after the first parsed message
- * @param data the ChannelBuffer to parse for an OpenFlow message
- * @return a list of OFMessage instances
- * @throws MessageParseException
- */
- public List<OFMessage> parseMessage(ChannelBuffer data) throws MessageParseException;
-
- /**
- * Retrieves an OFActionFactory
- * @return an OFActionFactory
- */
- public OFActionFactory getActionFactory();
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-/**
- *
- */
-package org.openflow.protocol.factory;
-
-/**
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- *
- */
-public interface OFMessageFactoryAware {
-
- /**
- * Sets the message factory for this object
- *
- * @param factory
- */
- void setMessageFactory(OFMessageFactory factory);
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.factory;
-
-import java.util.List;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.OFType;
-import org.openflow.protocol.statistics.OFStatistics;
-import org.openflow.protocol.statistics.OFStatisticsType;
-
-
-/**
- * The interface to factories used for retrieving OFStatistics instances. All
- * methods are expected to be thread-safe.
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public interface OFStatisticsFactory {
- /**
- * Retrieves an OFStatistics instance corresponding to the specified
- * OFStatisticsType
- * @param t the type of the containing OFMessage, only accepts statistics
- * request or reply
- * @param st the type of the OFStatistics to be retrieved
- * @return an OFStatistics instance
- */
- public OFStatistics getStatistics(OFType t, OFStatisticsType st);
-
- /**
- * Attempts to parse and return all OFStatistics contained in the given
- * ByteBuffer, beginning at the ByteBuffer's position, and ending at
- * position+length.
- * @param t the type of the containing OFMessage, only accepts statistics
- * request or reply
- * @param st the type of the OFStatistics to be retrieved
- * @param data the ChannelBuffer to parse for OpenFlow Statistics
- * @param length the number of Bytes to examine for OpenFlow Statistics
- * @return a list of OFStatistics instances
- */
- public List<OFStatistics> parseStatistics(OFType t,
- OFStatisticsType st, ChannelBuffer data, int length);
-
- /**
- * Attempts to parse and return all OFStatistics contained in the given
- * ByteBuffer, beginning at the ByteBuffer's position, and ending at
- * position+length.
- * @param t the type of the containing OFMessage, only accepts statistics
- * request or reply
- * @param st the type of the OFStatistics to be retrieved
- * @param data the ChannelBuffer to parse for OpenFlow Statistics
- * @param length the number of Bytes to examine for OpenFlow Statistics
- * @param limit the maximum number of messages to return, 0 means no limit
- * @return a list of OFStatistics instances
- */
- public List<OFStatistics> parseStatistics(OFType t,
- OFStatisticsType st, ChannelBuffer data, int length, int limit);
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.factory;
-
-/**
- * Objects implementing this interface are expected to be instantiated with an
- * instance of an OFStatisticsFactory
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public interface OFStatisticsFactoryAware {
- /**
- * Sets the OFStatisticsFactory
- * @param statisticsFactory
- */
- public void setStatisticsFactory(OFStatisticsFactory statisticsFactory);
-}
+++ /dev/null
-/**
- * Copyright 2013, Big Switch Networks, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License. You may obtain
- * a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- **/
-
-package org.openflow.protocol.factory;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.action.OFActionVendor;
-
-/** Interface contract for an actionfactory that creates vendor-specific actions.
- * VendorActionFactories are registered with the BasicFactory for a specific
- * vendor id.
- * <p>
- * <b>Note:</b> Implementations are expected to be thread-safe.
- *
- * @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
- */
-public interface OFVendorActionFactory {
-
- /** parse the data from the wire, create and return a vendor-specific action.
- *
- * @param data contains a serialized vendor action at the current readerPosition.
- * The full message is guaranteed to be available in the buffer.
- *
- * @return upon success returns a newly allocated vendor-specific
- * action instance, and advances the readerPosition in data for the
- * entire length. Upon failure, returns null and leaves the readerPosition
- * in data unmodified.
- */
- OFActionVendor readFrom(ChannelBuffer data);
-}
+++ /dev/null
-/**
- * Copyright 2013, Big Switch Networks, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License. You may obtain
- * a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- **/
-
-package org.openflow.protocol.factory;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/** Singleton registry object that holds a mapping from vendor ids to vendor-specific
- * mapping factories. Threadsafe.
- *
- * @author Andreas Wundsam <andreas.wundsam@bigswitch.com>
- */
-public class OFVendorActionRegistry {
- private static class InstanceHolder {
- private final static OFVendorActionRegistry instance = new OFVendorActionRegistry();
- }
-
- public static OFVendorActionRegistry getInstance() {
- return InstanceHolder.instance;
- }
- private final Map <Integer, OFVendorActionFactory> vendorActionFactories;
-
- public OFVendorActionRegistry() {
- vendorActionFactories = new ConcurrentHashMap<Integer, OFVendorActionFactory>();
- }
-
- public OFVendorActionFactory register(int vendorId, OFVendorActionFactory factory) {
- return vendorActionFactories.put(vendorId, factory);
- }
-
- public OFVendorActionFactory get(int vendorId) {
- return vendorActionFactories.get(vendorId);
- }
-
-
-}
+++ /dev/null
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson & Rob Sherwood, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.factory;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.vendor.OFVendorData;
-import org.openflow.protocol.vendor.OFVendorDataType;
-import org.openflow.protocol.vendor.OFVendorId;
-
-/**
- * The interface to factories used for parsing/creating OFVendorData instances.
- * All methods are expected to be thread-safe.
- *
- * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
- */
-public interface OFVendorDataFactory {
- /**
- * Retrieves an OFVendorData instance corresponding to the specified
- * OFVendorId and OFVendorDataType. There are 3 possible cases for
- * how this will be called:
- *
- * 1) If the vendor id in the OFVendor message is an unknown value,
- * then this method is called with both vendorId and vendorDataType
- * set to null. In this case typically the factory method should
- * return an instance of OFGenericVendorData that just contains
- * the raw byte array of the vendor data.
- *
- * 2) If the vendor id is known but no vendor data type has been
- * registered for the data in the message, then vendorId is set to
- * the appropriate OFVendorId instance and OFVendorDataType is set
- * to null. This would typically be handled the same way as #1
- *
- * 3) If both the vendor id and and vendor data type are known, then
- * typically you'd just call the method in OFVendorDataType to
- * instantiate the appropriate subclass of OFVendorData.
- *
- * @param vendorId the vendorId of the containing OFVendor message
- * @param vendorDataType the type of the OFVendorData to be retrieved
- * @return an OFVendorData instance
- */
- public OFVendorData getVendorData(OFVendorId vendorId,
- OFVendorDataType vendorDataType);
-
- /**
- * Attempts to parse and return the OFVendorData contained in the given
- * ChannelBuffer, beginning right after the vendor id.
- * @param vendorId the vendor id that was parsed from the OFVendor message.
- * @param data the ChannelBuffer from which to parse the vendor data
- * @param length the length to the end of the enclosing message.
- * @return an OFVendorData instance
- */
- public OFVendorData parseVendorData(int vendorId, ChannelBuffer data,
- int length);
-}
+++ /dev/null
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson & Rob Sherwood, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.factory;
-
-/**
- * Classes implementing this interface are expected to be instantiated with an
- * instance of an OFVendorDataFactory
- *
- * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
- */
-public interface OFVendorDataFactoryAware {
- public void setVendorDataFactory(OFVendorDataFactory vendorDataFactory);
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.statistics;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Represents an ofp_aggregate_stats_reply structure
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFAggregateStatisticsReply implements OFStatistics {
- protected long packetCount;
- protected long byteCount;
- protected int flowCount;
-
- /**
- * @return the packetCount
- */
- public long getPacketCount() {
- return packetCount;
- }
-
- /**
- * @param packetCount the packetCount to set
- */
- public void setPacketCount(long packetCount) {
- this.packetCount = packetCount;
- }
-
- /**
- * @return the byteCount
- */
- public long getByteCount() {
- return byteCount;
- }
-
- /**
- * @param byteCount the byteCount to set
- */
- public void setByteCount(long byteCount) {
- this.byteCount = byteCount;
- }
-
- /**
- * @return the flowCount
- */
- public int getFlowCount() {
- return flowCount;
- }
-
- /**
- * @param flowCount the flowCount to set
- */
- public void setFlowCount(int flowCount) {
- this.flowCount = flowCount;
- }
-
- @Override
- public int getLength() {
- return 24;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- this.packetCount = data.readLong();
- this.byteCount = data.readLong();
- this.flowCount = data.readInt();
- data.readInt(); // pad
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- data.writeLong(this.packetCount);
- data.writeLong(this.byteCount);
- data.writeInt(this.flowCount);
- data.writeInt(0); // pad
- }
-
- @Override
- public int hashCode() {
- final int prime = 397;
- int result = 1;
- result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
- result = prime * result + flowCount;
- result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFAggregateStatisticsReply)) {
- return false;
- }
- OFAggregateStatisticsReply other = (OFAggregateStatisticsReply) obj;
- if (byteCount != other.byteCount) {
- return false;
- }
- if (flowCount != other.flowCount) {
- return false;
- }
- if (packetCount != other.packetCount) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.statistics;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.OFMatch;
-
-/**
- * Represents an ofp_aggregate_stats_request structure
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFAggregateStatisticsRequest implements OFStatistics {
- protected OFMatch match;
- protected byte tableId;
- protected short outPort;
-
- /**
- * @return the match
- */
- public OFMatch getMatch() {
- return match;
- }
-
- /**
- * @param match the match to set
- */
- public void setMatch(OFMatch match) {
- this.match = match;
- }
-
- /**
- * @return the tableId
- */
- public byte getTableId() {
- return tableId;
- }
-
- /**
- * @param tableId the tableId to set
- */
- public void setTableId(byte tableId) {
- this.tableId = tableId;
- }
-
- /**
- * @return the outPort
- */
- public short getOutPort() {
- return outPort;
- }
-
- /**
- * @param outPort the outPort to set
- */
- public void setOutPort(short outPort) {
- this.outPort = outPort;
- }
-
- @Override
- public int getLength() {
- return 44;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- if (this.match == null)
- this.match = new OFMatch();
- this.match.readFrom(data);
- this.tableId = data.readByte();
- data.readByte(); // pad
- this.outPort = data.readShort();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- this.match.writeTo(data);
- data.writeByte(this.tableId);
- data.writeByte((byte) 0);
- data.writeShort(this.outPort);
- }
-
- @Override
- public int hashCode() {
- final int prime = 401;
- int result = 1;
- result = prime * result + ((match == null) ? 0 : match.hashCode());
- result = prime * result + outPort;
- result = prime * result + tableId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFAggregateStatisticsRequest)) {
- return false;
- }
- OFAggregateStatisticsRequest other = (OFAggregateStatisticsRequest) obj;
- if (match == null) {
- if (other.match != null) {
- return false;
- }
- } else if (!match.equals(other.match)) {
- return false;
- }
- if (outPort != other.outPort) {
- return false;
- }
- if (tableId != other.tableId) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.statistics;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.StringByteSerializer;
-
-/**
- * Represents an ofp_desc_stats structure
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFDescriptionStatistics implements OFStatistics {
- public static int DESCRIPTION_STRING_LENGTH = 256;
- public static int SERIAL_NUMBER_LENGTH = 32;
-
- protected String manufacturerDescription;
- protected String hardwareDescription;
- protected String softwareDescription;
- protected String serialNumber;
- protected String datapathDescription;
-
- /**
- * @return the manufacturerDescription
- */
- public String getManufacturerDescription() {
- return manufacturerDescription;
- }
-
- /**
- * @param manufacturerDescription the manufacturerDescription to set
- */
- public void setManufacturerDescription(String manufacturerDescription) {
- this.manufacturerDescription = manufacturerDescription;
- }
-
- /**
- * @return the hardwareDescription
- */
- public String getHardwareDescription() {
- return hardwareDescription;
- }
-
- /**
- * @param hardwareDescription the hardwareDescription to set
- */
- public void setHardwareDescription(String hardwareDescription) {
- this.hardwareDescription = hardwareDescription;
- }
-
- /**
- * @return the softwareDescription
- */
- public String getSoftwareDescription() {
- return softwareDescription;
- }
-
- /**
- * @param softwareDescription the softwareDescription to set
- */
- public void setSoftwareDescription(String softwareDescription) {
- this.softwareDescription = softwareDescription;
- }
-
- /**
- * @return the serialNumber
- */
- public String getSerialNumber() {
- return serialNumber;
- }
-
- /**
- * @param serialNumber the serialNumber to set
- */
- public void setSerialNumber(String serialNumber) {
- this.serialNumber = serialNumber;
- }
-
- /**
- * @return the datapathDescription
- */
- public String getDatapathDescription() {
- return datapathDescription;
- }
-
- /**
- * @param datapathDescription the datapathDescription to set
- */
- public void setDatapathDescription(String datapathDescription) {
- this.datapathDescription = datapathDescription;
- }
-
- @Override
- public int getLength() {
- return 1056;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- this.manufacturerDescription = StringByteSerializer.readFrom(data,
- DESCRIPTION_STRING_LENGTH);
- this.hardwareDescription = StringByteSerializer.readFrom(data,
- DESCRIPTION_STRING_LENGTH);
- this.softwareDescription = StringByteSerializer.readFrom(data,
- DESCRIPTION_STRING_LENGTH);
- this.serialNumber = StringByteSerializer.readFrom(data,
- SERIAL_NUMBER_LENGTH);
- this.datapathDescription = StringByteSerializer.readFrom(data,
- DESCRIPTION_STRING_LENGTH);
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH,
- this.manufacturerDescription);
- StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH,
- this.hardwareDescription);
- StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH,
- this.softwareDescription);
- StringByteSerializer.writeTo(data, SERIAL_NUMBER_LENGTH,
- this.serialNumber);
- StringByteSerializer.writeTo(data, DESCRIPTION_STRING_LENGTH,
- this.datapathDescription);
- }
-
- @Override
- public int hashCode() {
- final int prime = 409;
- int result = 1;
- result = prime
- * result
- + ((datapathDescription == null) ? 0 : datapathDescription
- .hashCode());
- result = prime
- * result
- + ((hardwareDescription == null) ? 0 : hardwareDescription
- .hashCode());
- result = prime
- * result
- + ((manufacturerDescription == null) ? 0
- : manufacturerDescription.hashCode());
- result = prime * result
- + ((serialNumber == null) ? 0 : serialNumber.hashCode());
- result = prime
- * result
- + ((softwareDescription == null) ? 0 : softwareDescription
- .hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFDescriptionStatistics)) {
- return false;
- }
- OFDescriptionStatistics other = (OFDescriptionStatistics) obj;
- if (datapathDescription == null) {
- if (other.datapathDescription != null) {
- return false;
- }
- } else if (!datapathDescription.equals(other.datapathDescription)) {
- return false;
- }
- if (hardwareDescription == null) {
- if (other.hardwareDescription != null) {
- return false;
- }
- } else if (!hardwareDescription.equals(other.hardwareDescription)) {
- return false;
- }
- if (manufacturerDescription == null) {
- if (other.manufacturerDescription != null) {
- return false;
- }
- } else if (!manufacturerDescription
- .equals(other.manufacturerDescription)) {
- return false;
- }
- if (serialNumber == null) {
- if (other.serialNumber != null) {
- return false;
- }
- } else if (!serialNumber.equals(other.serialNumber)) {
- return false;
- }
- if (softwareDescription == null) {
- if (other.softwareDescription != null) {
- return false;
- }
- } else if (!softwareDescription.equals(other.softwareDescription)) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- return "Switch Desc - Vendor: " + manufacturerDescription +
- " Model: " + hardwareDescription +
- " Make: " + datapathDescription +
- " Version: " + softwareDescription +
- " S/N: " + serialNumber;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.statistics;
-
-import java.util.List;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.OFMatch;
-import org.openflow.protocol.action.OFAction;
-import org.openflow.protocol.factory.OFActionFactory;
-import org.openflow.protocol.factory.OFActionFactoryAware;
-import org.openflow.util.U16;
-
-/**
- * Represents an ofp_flow_stats structure
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFFlowStatisticsReply implements OFStatistics, OFActionFactoryAware {
- public static int MINIMUM_LENGTH = 88;
-
- protected OFActionFactory actionFactory;
- protected short length = (short) MINIMUM_LENGTH;
- protected byte tableId;
- protected OFMatch match;
- protected int durationSeconds;
- protected int durationNanoseconds;
- protected short priority;
- protected short idleTimeout;
- protected short hardTimeout;
- protected long cookie;
- protected long packetCount;
- protected long byteCount;
- protected List<OFAction> actions;
-
- /**
- * @return the tableId
- */
- public byte getTableId() {
- return tableId;
- }
-
- /**
- * @param tableId the tableId to set
- */
- public void setTableId(byte tableId) {
- this.tableId = tableId;
- }
-
- /**
- * @return the match
- */
- public OFMatch getMatch() {
- return match;
- }
-
- /**
- * @param match the match to set
- */
- public void setMatch(OFMatch match) {
- this.match = match;
- }
-
- /**
- * @return the durationSeconds
- */
- public int getDurationSeconds() {
- return durationSeconds;
- }
-
- /**
- * @param durationSeconds the durationSeconds to set
- */
- public void setDurationSeconds(int durationSeconds) {
- this.durationSeconds = durationSeconds;
- }
-
- /**
- * @return the durationNanoseconds
- */
- public int getDurationNanoseconds() {
- return durationNanoseconds;
- }
-
- /**
- * @param durationNanoseconds the durationNanoseconds to set
- */
- public void setDurationNanoseconds(int durationNanoseconds) {
- this.durationNanoseconds = durationNanoseconds;
- }
-
- /**
- * @return the priority
- */
- public short getPriority() {
- return priority;
- }
-
- /**
- * @param priority the priority to set
- */
- public void setPriority(short priority) {
- this.priority = priority;
- }
-
- /**
- * @return the idleTimeout
- */
- public short getIdleTimeout() {
- return idleTimeout;
- }
-
- /**
- * @param idleTimeout the idleTimeout to set
- */
- public void setIdleTimeout(short idleTimeout) {
- this.idleTimeout = idleTimeout;
- }
-
- /**
- * @return the hardTimeout
- */
- public short getHardTimeout() {
- return hardTimeout;
- }
-
- /**
- * @param hardTimeout the hardTimeout to set
- */
- public void setHardTimeout(short hardTimeout) {
- this.hardTimeout = hardTimeout;
- }
-
- /**
- * @return the cookie
- */
- public long getCookie() {
- return cookie;
- }
-
- /**
- * @param cookie the cookie to set
- */
- public void setCookie(long cookie) {
- this.cookie = cookie;
- }
-
- /**
- * @return the packetCount
- */
- public long getPacketCount() {
- return packetCount;
- }
-
- /**
- * @param packetCount the packetCount to set
- */
- public void setPacketCount(long packetCount) {
- this.packetCount = packetCount;
- }
-
- /**
- * @return the byteCount
- */
- public long getByteCount() {
- return byteCount;
- }
-
- /**
- * @param byteCount the byteCount to set
- */
- public void setByteCount(long byteCount) {
- this.byteCount = byteCount;
- }
-
- /**
- * @param length the length to set
- */
- public void setLength(short length) {
- this.length = length;
- }
-
- @Override
- public int getLength() {
- return U16.f(length);
- }
-
- /**
- * @param actionFactory the actionFactory to set
- */
- @Override
- public void setActionFactory(OFActionFactory actionFactory) {
- this.actionFactory = actionFactory;
- }
-
- /**
- * @return the actions
- */
- public List<OFAction> getActions() {
- return actions;
- }
-
- /**
- * @param actions the actions to set
- */
- public void setActions(List<OFAction> actions) {
- this.actions = actions;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- this.length = data.readShort();
- this.tableId = data.readByte();
- data.readByte(); // pad
- if (this.match == null)
- this.match = new OFMatch();
- this.match.readFrom(data);
- this.durationSeconds = data.readInt();
- this.durationNanoseconds = data.readInt();
- this.priority = data.readShort();
- this.idleTimeout = data.readShort();
- this.hardTimeout = data.readShort();
- data.readInt(); // pad
- data.readShort(); // pad
- this.cookie = data.readLong();
- this.packetCount = data.readLong();
- this.byteCount = data.readLong();
- if (this.actionFactory == null)
- throw new RuntimeException("OFActionFactory not set");
- this.actions = this.actionFactory.parseActions(data, getLength() -
- MINIMUM_LENGTH);
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- data.writeShort(this.length);
- data.writeByte(this.tableId);
- data.writeByte((byte) 0);
- this.match.writeTo(data);
- data.writeInt(this.durationSeconds);
- data.writeInt(this.durationNanoseconds);
- data.writeShort(this.priority);
- data.writeShort(this.idleTimeout);
- data.writeShort(this.hardTimeout);
- data.writeInt(0); // pad
- data.writeShort((short)0); // pad
- data.writeLong(this.cookie);
- data.writeLong(this.packetCount);
- data.writeLong(this.byteCount);
- if (actions != null) {
- for (OFAction action : actions) {
- action.writeTo(data);
- }
- }
- }
-
- @Override
- public String toString() {
- String str = "match=" + this.match;
- str += " tableId=" + this.tableId;
- str += " durationSeconds=" + this.durationSeconds;
- str += " durationNanoseconds=" + this.durationNanoseconds;
- str += " priority=" + this.priority;
- str += " idleTimeout=" + this.idleTimeout;
- str += " hardTimeout=" + this.hardTimeout;
- str += " cookie=" + this.cookie;
- str += " packetCount=" + this.packetCount;
- str += " byteCount=" + this.byteCount;
- str += " action=" + this.actions;
-
- return str;
- }
-
- @Override
- public int hashCode() {
- final int prime = 419;
- int result = 1;
- result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
- result = prime * result + (int) (cookie ^ (cookie >>> 32));
- result = prime * result + durationNanoseconds;
- result = prime * result + durationSeconds;
- result = prime * result + hardTimeout;
- result = prime * result + idleTimeout;
- result = prime * result + length;
- result = prime * result + ((match == null) ? 0 : match.hashCode());
- result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
- result = prime * result + priority;
- result = prime * result + tableId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFFlowStatisticsReply)) {
- return false;
- }
- OFFlowStatisticsReply other = (OFFlowStatisticsReply) obj;
- if (byteCount != other.byteCount) {
- return false;
- }
- if (cookie != other.cookie) {
- return false;
- }
- if (durationNanoseconds != other.durationNanoseconds) {
- return false;
- }
- if (durationSeconds != other.durationSeconds) {
- return false;
- }
- if (hardTimeout != other.hardTimeout) {
- return false;
- }
- if (idleTimeout != other.idleTimeout) {
- return false;
- }
- if (length != other.length) {
- return false;
- }
- if (match == null) {
- if (other.match != null) {
- return false;
- }
- } else if (!match.equals(other.match)) {
- return false;
- }
- if (packetCount != other.packetCount) {
- return false;
- }
- if (priority != other.priority) {
- return false;
- }
- if (tableId != other.tableId) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.statistics;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.OFMatch;
-
-/**
- * Represents an ofp_flow_stats_request structure
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFFlowStatisticsRequest implements OFStatistics {
- protected OFMatch match;
- protected byte tableId;
- protected short outPort;
-
- /**
- * @return the match
- */
- public OFMatch getMatch() {
- return match;
- }
-
- /**
- * @param match the match to set
- */
- public void setMatch(OFMatch match) {
- this.match = match;
- }
-
- /**
- * @return the tableId
- */
- public byte getTableId() {
- return tableId;
- }
-
- /**
- * @param tableId the tableId to set
- */
- public void setTableId(byte tableId) {
- this.tableId = tableId;
- }
-
- /**
- * @return the outPort
- */
- public short getOutPort() {
- return outPort;
- }
-
- /**
- * @param outPort the outPort to set
- */
- public void setOutPort(short outPort) {
- this.outPort = outPort;
- }
-
- @Override
- public int getLength() {
- return 44;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- if (this.match == null)
- this.match = new OFMatch();
- this.match.readFrom(data);
- this.tableId = data.readByte();
- data.readByte(); // pad
- this.outPort = data.readShort();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- this.match.writeTo(data);
- data.writeByte(this.tableId);
- data.writeByte((byte) 0);
- data.writeShort(this.outPort);
- }
-
- @Override
- public int hashCode() {
- final int prime = 421;
- int result = 1;
- result = prime * result + ((match == null) ? 0 : match.hashCode());
- result = prime * result + outPort;
- result = prime * result + tableId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFFlowStatisticsRequest)) {
- return false;
- }
- OFFlowStatisticsRequest other = (OFFlowStatisticsRequest) obj;
- if (match == null) {
- if (other.match != null) {
- return false;
- }
- } else if (!match.equals(other.match)) {
- return false;
- }
- if (outPort != other.outPort) {
- return false;
- }
- if (tableId != other.tableId) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.statistics;
-
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Represents an ofp_port_stats structure
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPortStatisticsReply implements OFStatistics {
- protected short portNumber;
- protected long receivePackets;
- protected long transmitPackets;
- protected long receiveBytes;
- protected long transmitBytes;
- protected long receiveDropped;
- protected long transmitDropped;
- protected long receiveErrors;
- protected long transmitErrors;
- protected long receiveFrameErrors;
- protected long receiveOverrunErrors;
- protected long receiveCRCErrors;
- protected long collisions;
-
- /**
- * @return the portNumber
- */
- public short getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param portNumber the portNumber to set
- */
- public void setPortNumber(short portNumber) {
- this.portNumber = portNumber;
- }
-
- /**
- * @return the receivePackets
- */
- public long getreceivePackets() {
- return receivePackets;
- }
-
- /**
- * @param receivePackets the receivePackets to set
- */
- public void setreceivePackets(long receivePackets) {
- this.receivePackets = receivePackets;
- }
-
- /**
- * @return the transmitPackets
- */
- public long getTransmitPackets() {
- return transmitPackets;
- }
-
- /**
- * @param transmitPackets the transmitPackets to set
- */
- public void setTransmitPackets(long transmitPackets) {
- this.transmitPackets = transmitPackets;
- }
-
- /**
- * @return the receiveBytes
- */
- public long getReceiveBytes() {
- return receiveBytes;
- }
-
- /**
- * @param receiveBytes the receiveBytes to set
- */
- public void setReceiveBytes(long receiveBytes) {
- this.receiveBytes = receiveBytes;
- }
-
- /**
- * @return the transmitBytes
- */
- public long getTransmitBytes() {
- return transmitBytes;
- }
-
- /**
- * @param transmitBytes the transmitBytes to set
- */
- public void setTransmitBytes(long transmitBytes) {
- this.transmitBytes = transmitBytes;
- }
-
- /**
- * @return the receiveDropped
- */
- public long getReceiveDropped() {
- return receiveDropped;
- }
-
- /**
- * @param receiveDropped the receiveDropped to set
- */
- public void setReceiveDropped(long receiveDropped) {
- this.receiveDropped = receiveDropped;
- }
-
- /**
- * @return the transmitDropped
- */
- public long getTransmitDropped() {
- return transmitDropped;
- }
-
- /**
- * @param transmitDropped the transmitDropped to set
- */
- public void setTransmitDropped(long transmitDropped) {
- this.transmitDropped = transmitDropped;
- }
-
- /**
- * @return the receiveErrors
- */
- public long getreceiveErrors() {
- return receiveErrors;
- }
-
- /**
- * @param receiveErrors the receiveErrors to set
- */
- public void setreceiveErrors(long receiveErrors) {
- this.receiveErrors = receiveErrors;
- }
-
- /**
- * @return the transmitErrors
- */
- public long getTransmitErrors() {
- return transmitErrors;
- }
-
- /**
- * @param transmitErrors the transmitErrors to set
- */
- public void setTransmitErrors(long transmitErrors) {
- this.transmitErrors = transmitErrors;
- }
-
- /**
- * @return the receiveFrameErrors
- */
- public long getReceiveFrameErrors() {
- return receiveFrameErrors;
- }
-
- /**
- * @param receiveFrameErrors the receiveFrameErrors to set
- */
- public void setReceiveFrameErrors(long receiveFrameErrors) {
- this.receiveFrameErrors = receiveFrameErrors;
- }
-
- /**
- * @return the receiveOverrunErrors
- */
- public long getReceiveOverrunErrors() {
- return receiveOverrunErrors;
- }
-
- /**
- * @param receiveOverrunErrors the receiveOverrunErrors to set
- */
- public void setReceiveOverrunErrors(long receiveOverrunErrors) {
- this.receiveOverrunErrors = receiveOverrunErrors;
- }
-
- /**
- * @return the receiveCRCErrors
- */
- public long getReceiveCRCErrors() {
- return receiveCRCErrors;
- }
-
- /**
- * @param receiveCRCErrors the receiveCRCErrors to set
- */
- public void setReceiveCRCErrors(long receiveCRCErrors) {
- this.receiveCRCErrors = receiveCRCErrors;
- }
-
- /**
- * @return the collisions
- */
- public long getCollisions() {
- return collisions;
- }
-
- /**
- * @param collisions the collisions to set
- */
- public void setCollisions(long collisions) {
- this.collisions = collisions;
- }
-
- @Override
- public int getLength() {
- return 104;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- this.portNumber = data.readShort();
- data.readShort(); // pad
- data.readInt(); // pad
- this.receivePackets = data.readLong();
- this.transmitPackets = data.readLong();
- this.receiveBytes = data.readLong();
- this.transmitBytes = data.readLong();
- this.receiveDropped = data.readLong();
- this.transmitDropped = data.readLong();
- this.receiveErrors = data.readLong();
- this.transmitErrors = data.readLong();
- this.receiveFrameErrors = data.readLong();
- this.receiveOverrunErrors = data.readLong();
- this.receiveCRCErrors = data.readLong();
- this.collisions = data.readLong();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- data.writeShort(this.portNumber);
- data.writeShort((short) 0); // pad
- data.writeInt(0); // pad
- data.writeLong(this.receivePackets);
- data.writeLong(this.transmitPackets);
- data.writeLong(this.receiveBytes);
- data.writeLong(this.transmitBytes);
- data.writeLong(this.receiveDropped);
- data.writeLong(this.transmitDropped);
- data.writeLong(this.receiveErrors);
- data.writeLong(this.transmitErrors);
- data.writeLong(this.receiveFrameErrors);
- data.writeLong(this.receiveOverrunErrors);
- data.writeLong(this.receiveCRCErrors);
- data.writeLong(this.collisions);
- }
-
- @Override
- public int hashCode() {
- final int prime = 431;
- int result = 1;
- result = prime * result + (int) (collisions ^ (collisions >>> 32));
- result = prime * result + portNumber;
- result = prime * result
- + (int) (receivePackets ^ (receivePackets >>> 32));
- result = prime * result + (int) (receiveBytes ^ (receiveBytes >>> 32));
- result = prime * result
- + (int) (receiveCRCErrors ^ (receiveCRCErrors >>> 32));
- result = prime * result
- + (int) (receiveDropped ^ (receiveDropped >>> 32));
- result = prime * result
- + (int) (receiveFrameErrors ^ (receiveFrameErrors >>> 32));
- result = prime * result
- + (int) (receiveOverrunErrors ^ (receiveOverrunErrors >>> 32));
- result = prime * result
- + (int) (receiveErrors ^ (receiveErrors >>> 32));
- result = prime * result
- + (int) (transmitBytes ^ (transmitBytes >>> 32));
- result = prime * result
- + (int) (transmitDropped ^ (transmitDropped >>> 32));
- result = prime * result
- + (int) (transmitErrors ^ (transmitErrors >>> 32));
- result = prime * result
- + (int) (transmitPackets ^ (transmitPackets >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPortStatisticsReply)) {
- return false;
- }
- OFPortStatisticsReply other = (OFPortStatisticsReply) obj;
- if (collisions != other.collisions) {
- return false;
- }
- if (portNumber != other.portNumber) {
- return false;
- }
- if (receivePackets != other.receivePackets) {
- return false;
- }
- if (receiveBytes != other.receiveBytes) {
- return false;
- }
- if (receiveCRCErrors != other.receiveCRCErrors) {
- return false;
- }
- if (receiveDropped != other.receiveDropped) {
- return false;
- }
- if (receiveFrameErrors != other.receiveFrameErrors) {
- return false;
- }
- if (receiveOverrunErrors != other.receiveOverrunErrors) {
- return false;
- }
- if (receiveErrors != other.receiveErrors) {
- return false;
- }
- if (transmitBytes != other.transmitBytes) {
- return false;
- }
- if (transmitDropped != other.transmitDropped) {
- return false;
- }
- if (transmitErrors != other.transmitErrors) {
- return false;
- }
- if (transmitPackets != other.transmitPackets) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.statistics;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Represents an ofp_port_stats_request structure
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFPortStatisticsRequest implements OFStatistics {
- protected short portNumber;
-
- /**
- * @return the portNumber
- */
- public short getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param portNumber the portNumber to set
- */
- public void setPortNumber(short portNumber) {
- this.portNumber = portNumber;
- }
-
- @Override
- public int getLength() {
- return 8;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- this.portNumber = data.readShort();
- data.readShort(); // pad
- data.readInt(); // pad
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- data.writeShort(this.portNumber);
- data.writeShort((short) 0); // pad
- data.writeInt(0); // pad
- }
-
- @Override
- public int hashCode() {
- final int prime = 433;
- int result = 1;
- result = prime * result + portNumber;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFPortStatisticsRequest)) {
- return false;
- }
- OFPortStatisticsRequest other = (OFPortStatisticsRequest) obj;
- if (portNumber != other.portNumber) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.statistics;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Represents an ofp_queue_stats structure
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFQueueStatisticsReply implements OFStatistics {
- protected short portNumber;
- protected int queueId;
- protected long transmitBytes;
- protected long transmitPackets;
- protected long transmitErrors;
-
- /**
- * @return the portNumber
- */
- public short getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param portNumber the portNumber to set
- */
- public void setPortNumber(short portNumber) {
- this.portNumber = portNumber;
- }
-
- /**
- * @return the queueId
- */
- public int getQueueId() {
- return queueId;
- }
-
- /**
- * @param queueId the queueId to set
- */
- public void setQueueId(int queueId) {
- this.queueId = queueId;
- }
-
- /**
- * @return the transmitBytes
- */
- public long getTransmitBytes() {
- return transmitBytes;
- }
-
- /**
- * @param transmitBytes the transmitBytes to set
- */
- public void setTransmitBytes(long transmitBytes) {
- this.transmitBytes = transmitBytes;
- }
-
- /**
- * @return the transmitPackets
- */
- public long getTransmitPackets() {
- return transmitPackets;
- }
-
- /**
- * @param transmitPackets the transmitPackets to set
- */
- public void setTransmitPackets(long transmitPackets) {
- this.transmitPackets = transmitPackets;
- }
-
- /**
- * @return the transmitErrors
- */
- public long getTransmitErrors() {
- return transmitErrors;
- }
-
- /**
- * @param transmitErrors the transmitErrors to set
- */
- public void setTransmitErrors(long transmitErrors) {
- this.transmitErrors = transmitErrors;
- }
-
- @Override
- public int getLength() {
- return 32;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- this.portNumber = data.readShort();
- data.readShort(); // pad
- this.queueId = data.readInt();
- this.transmitBytes = data.readLong();
- this.transmitPackets = data.readLong();
- this.transmitErrors = data.readLong();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- data.writeShort(this.portNumber);
- data.writeShort((short) 0); // pad
- data.writeInt(this.queueId);
- data.writeLong(this.transmitBytes);
- data.writeLong(this.transmitPackets);
- data.writeLong(this.transmitErrors);
- }
-
- @Override
- public int hashCode() {
- final int prime = 439;
- int result = 1;
- result = prime * result + portNumber;
- result = prime * result + queueId;
- result = prime * result
- + (int) (transmitBytes ^ (transmitBytes >>> 32));
- result = prime * result
- + (int) (transmitErrors ^ (transmitErrors >>> 32));
- result = prime * result
- + (int) (transmitPackets ^ (transmitPackets >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFQueueStatisticsReply)) {
- return false;
- }
- OFQueueStatisticsReply other = (OFQueueStatisticsReply) obj;
- if (portNumber != other.portNumber) {
- return false;
- }
- if (queueId != other.queueId) {
- return false;
- }
- if (transmitBytes != other.transmitBytes) {
- return false;
- }
- if (transmitErrors != other.transmitErrors) {
- return false;
- }
- if (transmitPackets != other.transmitPackets) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.statistics;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Represents an ofp_queue_stats_request structure
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFQueueStatisticsRequest implements OFStatistics {
- protected short portNumber;
- protected int queueId;
-
- /**
- * @return the portNumber
- */
- public short getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param portNumber the portNumber to set
- */
- public void setPortNumber(short portNumber) {
- this.portNumber = portNumber;
- }
-
- /**
- * @return the queueId
- */
- public int getQueueId() {
- return queueId;
- }
-
- /**
- * @param queueId the queueId to set
- */
- public void setQueueId(int queueId) {
- this.queueId = queueId;
- }
-
- @Override
- public int getLength() {
- return 8;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- this.portNumber = data.readShort();
- data.readShort(); // pad
- this.queueId = data.readInt();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- data.writeShort(this.portNumber);
- data.writeShort((short) 0); // pad
- data.writeInt(this.queueId);
- }
-
- @Override
- public int hashCode() {
- final int prime = 443;
- int result = 1;
- result = prime * result + portNumber;
- result = prime * result + queueId;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFQueueStatisticsRequest)) {
- return false;
- }
- OFQueueStatisticsRequest other = (OFQueueStatisticsRequest) obj;
- if (portNumber != other.portNumber) {
- return false;
- }
- if (queueId != other.queueId) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.statistics;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * The base class for all OpenFlow statistics.
- *
- * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
- */
-public interface OFStatistics {
- /**
- * Returns the wire length of this message in bytes
- * @return the length
- */
- public int getLength();
-
- /**
- * Read this message off the wire from the specified ByteBuffer
- * @param data
- */
- public void readFrom(ChannelBuffer data);
-
- /**
- * Write this message's binary format to the specified ByteBuffer
- * @param data
- */
- public void writeTo(ChannelBuffer data);
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.statistics;
-
-import java.lang.reflect.Constructor;
-
-import org.openflow.protocol.Instantiable;
-import org.openflow.protocol.OFType;
-
-public enum OFStatisticsType {
- DESC (0, OFDescriptionStatistics.class, OFDescriptionStatistics.class,
- new Instantiable<OFStatistics>() {
- @Override
- public OFStatistics instantiate() {
- return new OFDescriptionStatistics();
- }
- },
- new Instantiable<OFStatistics>() {
- @Override
- public OFStatistics instantiate() {
- return new OFDescriptionStatistics();
- }
- }),
- FLOW (1, OFFlowStatisticsRequest.class, OFFlowStatisticsReply.class,
- new Instantiable<OFStatistics>() {
- @Override
- public OFStatistics instantiate() {
- return new OFFlowStatisticsRequest();
- }
- },
- new Instantiable<OFStatistics>() {
- @Override
- public OFStatistics instantiate() {
- return new OFFlowStatisticsReply();
- }
- }),
- AGGREGATE (2, OFAggregateStatisticsRequest.class, OFAggregateStatisticsReply.class,
- new Instantiable<OFStatistics>() {
- @Override
- public OFStatistics instantiate() {
- return new OFAggregateStatisticsRequest();
- }
- },
- new Instantiable<OFStatistics>() {
- @Override
- public OFStatistics instantiate() {
- return new OFAggregateStatisticsReply();
- }
- }),
- TABLE (3, OFTableStatistics.class, OFTableStatistics.class,
- new Instantiable<OFStatistics>() {
- @Override
- public OFStatistics instantiate() {
- return new OFTableStatistics();
- }
- },
- new Instantiable<OFStatistics>() {
- @Override
- public OFStatistics instantiate() {
- return new OFTableStatistics();
- }
- }),
- PORT (4, OFPortStatisticsRequest.class, OFPortStatisticsReply.class,
- new Instantiable<OFStatistics>() {
- @Override
- public OFStatistics instantiate() {
- return new OFPortStatisticsRequest();
- }
- },
- new Instantiable<OFStatistics>() {
- @Override
- public OFStatistics instantiate() {
- return new OFPortStatisticsReply();
- }
- }),
- QUEUE (5, OFQueueStatisticsRequest.class, OFQueueStatisticsReply.class,
- new Instantiable<OFStatistics>() {
- @Override
- public OFStatistics instantiate() {
- return new OFQueueStatisticsRequest();
- }
- },
- new Instantiable<OFStatistics>() {
- @Override
- public OFStatistics instantiate() {
- return new OFQueueStatisticsReply();
- }
- }),
- VENDOR (0xffff, OFVendorStatistics.class, OFVendorStatistics.class,
- new Instantiable<OFStatistics>() {
- @Override
- public OFStatistics instantiate() {
- return new OFVendorStatistics();
- }
- },
- new Instantiable<OFStatistics>() {
- @Override
- public OFStatistics instantiate() {
- return new OFVendorStatistics();
- }
- });
-
- static OFStatisticsType[] requestMapping;
- static OFStatisticsType[] replyMapping;
-
- protected Class<? extends OFStatistics> requestClass;
- protected Constructor<? extends OFStatistics> requestConstructor;
- protected Instantiable<OFStatistics> requestInstantiable;
- protected Class<? extends OFStatistics> replyClass;
- protected Constructor<? extends OFStatistics> replyConstructor;
- protected Instantiable<OFStatistics> replyInstantiable;
- protected short type;
-
- /**
- * Store some information about the OpenFlow Statistic type, including wire
- * protocol type number, and derived class
- *
- * @param type Wire protocol number associated with this OFStatisticsType
- * @param requestClass The Statistics Java class to return when the
- * containing OFType is STATS_REQUEST
- * @param replyClass The Statistics Java class to return when the
- * containing OFType is STATS_REPLY
- */
- OFStatisticsType(int type, Class<? extends OFStatistics> requestClass,
- Class<? extends OFStatistics> replyClass,
- Instantiable<OFStatistics> requestInstantiable,
- Instantiable<OFStatistics> replyInstantiable) {
- this.type = (short) type;
- this.requestClass = requestClass;
- try {
- this.requestConstructor = requestClass.getConstructor(new Class[]{});
- } catch (Exception e) {
- throw new RuntimeException(
- "Failure getting constructor for class: " + requestClass, e);
- }
-
- this.replyClass = replyClass;
- try {
- this.replyConstructor = replyClass.getConstructor(new Class[]{});
- } catch (Exception e) {
- throw new RuntimeException(
- "Failure getting constructor for class: " + replyClass, e);
- }
- this.requestInstantiable = requestInstantiable;
- this.replyInstantiable = replyInstantiable;
- OFStatisticsType.addMapping(this.type, OFType.STATS_REQUEST, this);
- OFStatisticsType.addMapping(this.type, OFType.STATS_REPLY, this);
- }
-
- /**
- * Adds a mapping from type value to OFStatisticsType enum
- *
- * @param i OpenFlow wire protocol type
- * @param t type of containing OFMessage, only accepts STATS_REQUEST or
- * STATS_REPLY
- * @param st type
- */
- static public void addMapping(short i, OFType t, OFStatisticsType st) {
- if (i < 0)
- i = (short) (16+i);
- if (t == OFType.STATS_REQUEST) {
- if (requestMapping == null)
- requestMapping = new OFStatisticsType[16];
- OFStatisticsType.requestMapping[i] = st;
- } else if (t == OFType.STATS_REPLY){
- if (replyMapping == null)
- replyMapping = new OFStatisticsType[16];
- OFStatisticsType.replyMapping[i] = st;
- } else {
- throw new RuntimeException(t.toString() + " is an invalid OFType");
- }
- }
-
- /**
- * Remove a mapping from type value to OFStatisticsType enum
- *
- * @param i OpenFlow wire protocol type
- * @param t type of containing OFMessage, only accepts STATS_REQUEST or
- * STATS_REPLY
- */
- static public void removeMapping(short i, OFType t) {
- if (i < 0)
- i = (short) (16+i);
- if (t == OFType.STATS_REQUEST) {
- requestMapping[i] = null;
- } else if (t == OFType.STATS_REPLY){
- replyMapping[i] = null;
- } else {
- throw new RuntimeException(t.toString() + " is an invalid OFType");
- }
- }
-
- /**
- * Given a wire protocol OpenFlow type number, return the OFStatisticsType
- * associated with it
- *
- * @param i wire protocol number
- * @param t type of containing OFMessage, only accepts STATS_REQUEST or
- * STATS_REPLY
- * @return OFStatisticsType enum type
- */
- static public OFStatisticsType valueOf(short i, OFType t) {
- if (i < 0)
- i = (short) (16+i);
- if (t == OFType.STATS_REQUEST) {
- return requestMapping[i];
- } else if (t == OFType.STATS_REPLY){
- return replyMapping[i];
- } else {
- throw new RuntimeException(t.toString() + " is an invalid OFType");
- }
- }
-
- /**
- * @return Returns the wire protocol value corresponding to this
- * OFStatisticsType
- */
- public short getTypeValue() {
- return this.type;
- }
-
- /**
- * @param t type of containing OFMessage, only accepts STATS_REQUEST or
- * STATS_REPLY
- * @return return the OFMessage subclass corresponding to this
- * OFStatisticsType
- */
- public Class<? extends OFStatistics> toClass(OFType t) {
- if (t == OFType.STATS_REQUEST) {
- return requestClass;
- } else if (t == OFType.STATS_REPLY){
- return replyClass;
- } else {
- throw new RuntimeException(t.toString() + " is an invalid OFType");
- }
- }
-
- /**
- * Returns the no-argument Constructor of the implementation class for
- * this OFStatisticsType, either request or reply based on the supplied
- * OFType
- *
- * @param t
- * @return
- */
- public Constructor<? extends OFStatistics> getConstructor(OFType t) {
- if (t == OFType.STATS_REQUEST) {
- return requestConstructor;
- } else if (t == OFType.STATS_REPLY) {
- return replyConstructor;
- } else {
- throw new RuntimeException(t.toString() + " is an invalid OFType");
- }
- }
-
- /**
- * @return the requestInstantiable
- */
- public Instantiable<OFStatistics> getRequestInstantiable() {
- return requestInstantiable;
- }
-
- /**
- * @param requestInstantiable the requestInstantiable to set
- */
- public void setRequestInstantiable(
- Instantiable<OFStatistics> requestInstantiable) {
- this.requestInstantiable = requestInstantiable;
- }
-
- /**
- * @return the replyInstantiable
- */
- public Instantiable<OFStatistics> getReplyInstantiable() {
- return replyInstantiable;
- }
-
- /**
- * @param replyInstantiable the replyInstantiable to set
- */
- public void setReplyInstantiable(Instantiable<OFStatistics> replyInstantiable) {
- this.replyInstantiable = replyInstantiable;
- }
-
- /**
- * Returns a new instance of the implementation class for
- * this OFStatisticsType, either request or reply based on the supplied
- * OFType
- *
- * @param t
- * @return
- */
- public OFStatistics newInstance(OFType t) {
- if (t == OFType.STATS_REQUEST) {
- return requestInstantiable.instantiate();
- } else if (t == OFType.STATS_REPLY) {
- return replyInstantiable.instantiate();
- } else {
- throw new RuntimeException(t.toString() + " is an invalid OFType");
- }
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.statistics;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.util.StringByteSerializer;
-
-/**
- * Represents an ofp_table_stats structure
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFTableStatistics implements OFStatistics {
- public static int MAX_TABLE_NAME_LEN = 32;
-
- protected byte tableId;
- protected String name;
- protected int wildcards;
- protected int maximumEntries;
- protected int activeCount;
- protected long lookupCount;
- protected long matchedCount;
-
- /**
- * @return the tableId
- */
- public byte getTableId() {
- return tableId;
- }
-
- /**
- * @param tableId the tableId to set
- */
- public void setTableId(byte tableId) {
- this.tableId = tableId;
- }
-
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- /**
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * @return the wildcards
- */
- public int getWildcards() {
- return wildcards;
- }
-
- /**
- * @param wildcards the wildcards to set
- */
- public void setWildcards(int wildcards) {
- this.wildcards = wildcards;
- }
-
- /**
- * @return the maximumEntries
- */
- public int getMaximumEntries() {
- return maximumEntries;
- }
-
- /**
- * @param maximumEntries the maximumEntries to set
- */
- public void setMaximumEntries(int maximumEntries) {
- this.maximumEntries = maximumEntries;
- }
-
- /**
- * @return the activeCount
- */
- public int getActiveCount() {
- return activeCount;
- }
-
- /**
- * @param activeCount the activeCount to set
- */
- public void setActiveCount(int activeCount) {
- this.activeCount = activeCount;
- }
-
- /**
- * @return the lookupCount
- */
- public long getLookupCount() {
- return lookupCount;
- }
-
- /**
- * @param lookupCount the lookupCount to set
- */
- public void setLookupCount(long lookupCount) {
- this.lookupCount = lookupCount;
- }
-
- /**
- * @return the matchedCount
- */
- public long getMatchedCount() {
- return matchedCount;
- }
-
- /**
- * @param matchedCount the matchedCount to set
- */
- public void setMatchedCount(long matchedCount) {
- this.matchedCount = matchedCount;
- }
-
- @Override
- public int getLength() {
- return 64;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- this.tableId = data.readByte();
- data.readByte(); // pad
- data.readByte(); // pad
- data.readByte(); // pad
- this.name = StringByteSerializer.readFrom(data, MAX_TABLE_NAME_LEN);
- this.wildcards = data.readInt();
- this.maximumEntries = data.readInt();
- this.activeCount = data.readInt();
- this.lookupCount = data.readLong();
- this.matchedCount = data.readLong();
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- data.writeByte(this.tableId);
- data.writeByte((byte) 0); // pad
- data.writeByte((byte) 0); // pad
- data.writeByte((byte) 0); // pad
- StringByteSerializer.writeTo(data, MAX_TABLE_NAME_LEN, this.name);
- data.writeInt(this.wildcards);
- data.writeInt(this.maximumEntries);
- data.writeInt(this.activeCount);
- data.writeLong(this.lookupCount);
- data.writeLong(this.matchedCount);
- }
-
- @Override
- public int hashCode() {
- final int prime = 449;
- int result = 1;
- result = prime * result + activeCount;
- result = prime * result + (int) (lookupCount ^ (lookupCount >>> 32));
- result = prime * result + (int) (matchedCount ^ (matchedCount >>> 32));
- result = prime * result + maximumEntries;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + tableId;
- result = prime * result + wildcards;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFTableStatistics)) {
- return false;
- }
- OFTableStatistics other = (OFTableStatistics) obj;
- if (activeCount != other.activeCount) {
- return false;
- }
- if (lookupCount != other.lookupCount) {
- return false;
- }
- if (matchedCount != other.matchedCount) {
- return false;
- }
- if (maximumEntries != other.maximumEntries) {
- return false;
- }
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (tableId != other.tableId) {
- return false;
- }
- if (wildcards != other.wildcards) {
- return false;
- }
- return true;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.statistics;
-
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * The base class for vendor implemented statistics
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-public class OFVendorStatistics implements OFStatistics {
- protected int vendor;
- protected byte[] body;
-
- // non-message fields
- protected int length = 0;
-
- @Override
- public void readFrom(ChannelBuffer data) {
- this.vendor = data.readInt();
- if (body == null)
- body = new byte[length - 4];
- data.readBytes(body);
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- data.writeInt(this.vendor);
- if (body != null)
- data.writeBytes(body);
- }
-
- @Override
- public int hashCode() {
- final int prime = 457;
- int result = 1;
- result = prime * result + vendor;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OFVendorStatistics)) {
- return false;
- }
- OFVendorStatistics other = (OFVendorStatistics) obj;
- if (vendor != other.vendor) {
- return false;
- }
- return true;
- }
-
- @Override
- public int getLength() {
- return length;
- }
-
- public void setLength(int length) {
- this.length = length;
- }
-}
+++ /dev/null
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson & Rob Sherwood, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.vendor;
-
-import org.openflow.protocol.Instantiable;
-
-/**
- * Subclass of OFVendorDataType that works with any vendor data format that
- * begins with a integral value to indicate the format of the remaining data.
- * It maps from the per-vendor-id integral data type code to the object
- * used to instantiate the class associated with that vendor data type.
- *
- * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
- */
-public class OFBasicVendorDataType extends OFVendorDataType {
-
- /**
- * The data type value at the beginning of the vendor data.
- */
- protected long type;
-
- /**
- * Construct an empty (i.e. no specified data type value) vendor data type.
- */
- public OFBasicVendorDataType() {
- super();
- this.type = 0;
- }
-
- /**
- * Store some information about the vendor data type, including wire protocol
- * type number, derived class and instantiator.
- *
- * @param type Wire protocol number associated with this vendor data type
- * @param instantiator An Instantiator<OFVendorData> implementation that
- * creates an instance of an appropriate subclass of OFVendorData.
- */
- public OFBasicVendorDataType(long type, Instantiable<OFVendorData> instantiator) {
- super(instantiator);
- this.type = type;
- }
-
- /**
- * @return Returns the wire protocol value corresponding to this OFVendorDataType
- */
- public long getTypeValue() {
- return this.type;
- }
-
- /**
- * @param type the wire protocol value for this data type
- */
- public void setTypeValue(long type) {
- this.type = type;
- }
-}
+++ /dev/null
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson & Rob Sherwood, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.vendor;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.Instantiable;
-
-/**
- * Basic subclass of OFVendorId that works with any vendor data format where
- * the data begins with an integral data type value.
- *
- * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
- */
-public class OFBasicVendorId extends OFVendorId {
-
- /**
- * The size of the data type value at the beginning of all vendor
- * data associated with this vendor id. The data type size must be
- * either 1, 2, 4 or 8.
- */
- protected int dataTypeSize;
-
- /**
- * Map of the vendor data types that have been registered for this
- * vendor id.
- */
- protected Map<Long, OFBasicVendorDataType> dataTypeMap =
- new HashMap<Long, OFBasicVendorDataType>();
-
- /**
- * Construct an OFVendorId that where the vendor data begins
- * with a data type value whose size is dataTypeSize.
- * @param id the id of the vendor, typically the OUI of a vendor
- * prefixed with 0.
- * @param dataTypeSize the size of the integral data type value
- * at the beginning of the vendor data. The value must be the
- * size of an integeral data type (i.e. either 1,2,4 or 8).
- */
- public OFBasicVendorId(int id, int dataTypeSize) {
- super(id);
- assert (dataTypeSize == 1) || (dataTypeSize == 2) ||
- (dataTypeSize == 4) || (dataTypeSize == 8);
- this.dataTypeSize = dataTypeSize;
- }
-
- /**
- * Get the size of the data type value at the beginning of the vendor
- * data. OFBasicVendorId assumes that this value is common across all of
- * the vendor data formats associated with a given vendor id.
- * @return
- */
- public int getDataTypeSize() {
- return dataTypeSize;
- }
-
- /**
- * Register a vendor data type with this vendor id.
- * @param vendorDataType
- */
- public void registerVendorDataType(OFBasicVendorDataType vendorDataType) {
- dataTypeMap.put(vendorDataType.getTypeValue(), vendorDataType);
- }
-
- /**
- * Lookup the OFVendorDataType instance that has been registered with
- * this vendor id.
- *
- * @param vendorDataType the integer code that was parsed from the
- * @return
- */
- public OFVendorDataType lookupVendorDataType(int vendorDataType) {
- return dataTypeMap.get(Long.valueOf(vendorDataType));
- }
-
- /**
- * This function parses enough of the data from the buffer to be able
- * to determine the appropriate OFVendorDataType for the data. It is meant
- * to be a reasonably generic implementation that will work for most
- * formats of vendor extensions. If the vendor data doesn't fit the
- * assumptions listed below, then this method will need to be overridden
- * to implement custom parsing.
- *
- * This implementation assumes that the vendor data begins with a data
- * type code that is used to distinguish different formats of vendor
- * data associated with a particular vendor ID.
- * The exact format of the data is vendor-defined, so we don't know how
- * how big the code is (or really even if there is a code). This code
- * assumes that the common case will be that the data does include
- * an initial type code (i.e. so that the vendor can have multiple
- * message/data types) and that the size is either 1, 2 or 4 bytes.
- * The size of the initial type code is configured by the subclass of
- * OFVendorId.
- *
- * @param data the channel buffer containing the vendor data.
- * @param length the length to the end of the enclosing message
- * @return the OFVendorDataType that can be used to instantiate the
- * appropriate subclass of OFVendorData.
- */
- public OFVendorDataType parseVendorDataType(ChannelBuffer data, int length) {
- OFVendorDataType vendorDataType = null;
-
- // Parse out the type code from the vendor data.
- long dataTypeValue = 0;
- if ((length == 0) || (length >= dataTypeSize)) {
- switch (dataTypeSize) {
- case 1:
- dataTypeValue = data.readByte();
- break;
- case 2:
- dataTypeValue = data.readShort();
- break;
- case 4:
- dataTypeValue = data.readInt();
- break;
- case 8:
- dataTypeValue = data.readLong();
- break;
- default:
- // This would be indicative of a coding error where the
- // dataTypeSize was specified incorrectly. This should have been
- // caught in the constructor for OFVendorId.
- assert false;
- }
-
- vendorDataType = dataTypeMap.get(dataTypeValue);
- }
-
- // If we weren't able to parse/map the data to a known OFVendorDataType,
- // then map it to a generic vendor data type.
- if (vendorDataType == null) {
- vendorDataType = new OFBasicVendorDataType(dataTypeValue,
- new Instantiable<OFVendorData>() {
- @Override
- public OFVendorData instantiate() {
- return new OFByteArrayVendorData();
- }
- }
- );
- }
-
- return vendorDataType;
- }
-
-}
+++ /dev/null
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson & Rob Sherwood, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.vendor;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Basic implementation of OFVendorData that just treats the data as a
- * byte array. This is used if there's an OFVendor message where there's
- * no registered OFVendorId or no specific OFVendorDataType that can be
- * determined from the data.
- *
- * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
- */
-public class OFByteArrayVendorData implements OFVendorData {
-
- protected byte[] bytes;
-
- /**
- * Construct vendor data with an empty byte array.
- */
- public OFByteArrayVendorData() {
- }
-
- /**
- * Construct vendor data with the specified byte array.
- * @param bytes
- */
- public OFByteArrayVendorData(byte[] bytes) {
- this.bytes = bytes;
- }
-
- /**
- * Get the associated byte array for this vendor data.
- * @return the byte array containing the raw vendor data.
- */
- public byte[] getBytes() {
- return bytes;
- }
-
- /**
- * Set the byte array for the vendor data.
- * @param bytes the raw byte array containing the vendor data.
- */
- public void setBytes(byte[] bytes) {
- this.bytes = bytes;
- }
-
- /**
- * Get the length of the vendor data. In this case it's just then length
- * of the underlying byte array.
- * @return the length of the vendor data
- */
- @Override
- public int getLength() {
- return (bytes != null) ? bytes.length : 0;
- }
-
- /**
- * Read the vendor data from the ChannelBuffer into the byte array.
- * @param data the channel buffer from which we're deserializing
- * @param length the length to the end of the enclosing message
- */
- @Override
- public void readFrom(ChannelBuffer data, int length) {
- bytes = new byte[length];
- data.readBytes(bytes);
- }
-
- /**
- * Write the vendor data bytes to the ChannelBuffer
- * @param data the channel buffer to which we're serializing
- */
- @Override
- public void writeTo(ChannelBuffer data) {
- if (bytes != null)
- data.writeBytes(bytes);
- }
-}
+++ /dev/null
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson & Rob Sherwood, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.vendor;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * The base class for all vendor data.
- *
- * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
- */
-public interface OFVendorData {
- /**
- * @return length of the data
- */
- public int getLength();
-
- /**
- * Read the vendor data from the specified ChannelBuffer
- * @param data
- */
- public void readFrom(ChannelBuffer data, int length);
-
- /**
- * Write the vendor data to the specified ChannelBuffer
- * @param data
- */
- public void writeTo(ChannelBuffer data);
-}
+++ /dev/null
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson & Rob Sherwood, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.vendor;
-
-import org.openflow.protocol.Instantiable;
-
-/**
- * Class that represents a specific vendor data type format in an
- * OFVendor message. Typically the vendor data will begin with an integer
- * code that determines the format of the rest of the data, but this
- * class does not assume that. It's basically just a holder for an
- * instantiator of the appropriate subclass of OFVendorData.
- *
- * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
- */
-public class OFVendorDataType {
-
- /**
- * Object that instantiates the subclass of OFVendorData
- * associated with this data type.
- */
- protected Instantiable<OFVendorData> instantiable;
-
- /**
- * Construct an empty vendor data type.
- */
- public OFVendorDataType() {
- super();
- }
-
- /**
- * Construct a vendor data type with the specified instantiable.
- * @param instantiable object that creates the subclass of OFVendorData
- * associated with this data type.
- */
- public OFVendorDataType(Instantiable<OFVendorData> instantiable) {
- this.instantiable = instantiable;
- }
-
- /**
- * Returns a new instance of a subclass of OFVendorData associated with
- * this OFVendorDataType.
- *
- * @return the new object
- */
- public OFVendorData newInstance() {
- return instantiable.instantiate();
- }
-
- /**
- * @return the instantiable
- */
- public Instantiable<OFVendorData> getInstantiable() {
- return instantiable;
- }
-
- /**
- * @param instantiable the instantiable to set
- */
- public void setInstantiable(Instantiable<OFVendorData> instantiable) {
- this.instantiable = instantiable;
- }
-
-}
+++ /dev/null
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson & Rob Sherwood, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol.vendor;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Base class for the vendor ID corresponding to vendor extensions from a
- * given vendor. It is responsible for knowing how to parse out some sort of
- * data type value from the vendor data in an OFVendor message so that we can
- * dispatch to the different subclasses of OFVendorData corresponding to the
- * different formats of data for the vendor extensions.
- *
- * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
- */
-public abstract class OFVendorId {
- static Map<Integer, OFVendorId> mapping = new HashMap<Integer, OFVendorId>();
-
- /**
- * The vendor id value, typically the OUI of the vendor prefixed with 0.
- */
- protected int id;
-
- /**
- * Register a new vendor id.
- * @param vendorId the vendor id to register
- */
- public static void registerVendorId(OFVendorId vendorId) {
- mapping.put(vendorId.getId(), vendorId);
- }
-
- /**
- * Lookup the OFVendorId instance corresponding to the given id value.
- * @param id the integer vendor id value
- * @return the corresponding OFVendorId that's been registered for the
- * given value, or null if there id has not been registered.
- */
- public static OFVendorId lookupVendorId(int id) {
- return mapping.get(id);
- }
-
- /**
- * Create an OFVendorId with the give vendor id value
- * @param id
- */
- public OFVendorId(int id) {
- this.id = id;
- }
-
- /**
- * @return the vendor id value
- */
- public int getId() {
- return id;
- }
-
- /**
- * This function parses enough of the data from the channel buffer to be
- * able to determine the appropriate OFVendorDataType for the data.
- *
- * @param data the channel buffer containing the vendor data.
- * @param length the length to the end of the enclosing message
- * @return the OFVendorDataType that can be used to instantiate the
- * appropriate subclass of OFVendorData.
- */
- public abstract OFVendorDataType parseVendorDataType(ChannelBuffer data, int length);
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-import java.math.BigInteger;
-
-public class HexString {
- /**
- * Convert a string of bytes to a ':' separated hex string
- * @param bytes
- * @return "0f:ca:fe:de:ad:be:ef"
- */
- public static String toHexString(byte[] bytes) {
- if (bytes == null) return "";
- int i;
- String ret = "";
- String tmp;
- for(i=0; i< bytes.length; i++) {
- if(i> 0)
- ret += ":";
- tmp = Integer.toHexString(U8.f(bytes[i]));
- if (tmp.length() == 1)
- ret += "0";
- ret += tmp;
- }
- return ret;
- }
-
- public static String toHexString(long val, int padTo) {
- char arr[] = Long.toHexString(val).toCharArray();
- String ret = "";
- // prepend the right number of leading zeros
- int i = 0;
- for (; i < (padTo * 2 - arr.length); i++) {
- ret += "0";
- if ((i % 2) != 0)
- ret += ":";
- }
- for (int j = 0; j < arr.length; j++) {
- ret += arr[j];
- if ((((i + j) % 2) != 0) && (j < (arr.length - 1)))
- ret += ":";
- }
- return ret;
- }
-
- public static String toHexString(long val) {
- return toHexString(val, 8);
- }
-
-
- /**
- * Convert a string of hex values into a string of bytes
- * @param values "0f:ca:fe:de:ad:be:ef"
- * @return [15, 5 ,2, 5, 17]
- * @throws NumberFormatException If the string can not be parsed
- */
- public static byte[] fromHexString(String values) throws NumberFormatException {
- String[] octets = values.split(":");
- byte[] ret = new byte[octets.length];
-
- for(int i = 0; i < octets.length; i++) {
- if (octets[i].length() > 2)
- throw new NumberFormatException("Invalid octet length");
- ret[i] = Integer.valueOf(octets[i], 16).byteValue();
- }
- return ret;
- }
-
- public static long toLong(String values) throws NumberFormatException {
- // Long.parseLong() can't handle HexStrings with MSB set. Sigh.
- BigInteger bi = new BigInteger(values.replaceAll(":", ""),16);
- if (bi.bitLength() > 64)
- throw new NumberFormatException("Input string too big to fit in long: " + values);
- return bi.longValue();
- }
-
-}
+++ /dev/null
-package org.openflow.util;
-
-public interface IProducer {
-
- public void registerConsumer(Class<?> iface, Object anObj);
-
- public void deregisterConsumer(Class<?> iface, Object anObj);
-
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-import java.util.LinkedHashMap;
-
-public class LRULinkedHashMap<K, V> extends LinkedHashMap<K, V> {
- private static final long serialVersionUID = -2964986094089626647L;
- protected int maximumCapacity;
-
- public LRULinkedHashMap(int initialCapacity, int maximumCapacity) {
- super(initialCapacity, 0.75f, true);
- this.maximumCapacity = maximumCapacity;
- }
-
- public LRULinkedHashMap(int maximumCapacity) {
- super(16, 0.75f, true);
- this.maximumCapacity = maximumCapacity;
- }
-
- @Override
- protected boolean removeEldestEntry(java.util.Map.Entry<K, V> eldest) {
- if (this.size() > maximumCapacity)
- return true;
- return false;
- }
-}
+++ /dev/null
-package org.openflow.util;
-
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * The following implement a producer/consumer design pattern in which both
- * producers and consumers explicitly employ a centralized registration
- * mechanism, and java Interfaces are used as contracts.<br>
- */
-public class ProducerConsumer {
-
- /*
- * Class variables
- */
- protected static ProducerConsumer singleton;
-
- /*
- * Default constructor
- */
- protected ProducerConsumer() {
- producerMap = new Hashtable<Class<?>, Set<IProducer>>();
- }
-
- /*
- * Instance variables
- */
-
- // Interface/IProducer map
- protected Map<Class<?>, Set<IProducer>> producerMap;
-
- /*
- * Protected methods
- */
-
- protected void _registerConsumer(Object consumer, Class<?>[] interfaces,
- Set<Class<?>> iSet,
- Set<Class<?>> iUniqueSet) {
- // *...Process all interfaces...*/
- for (Class<?> iface : interfaces) {
-
- // *...Protect against repeated interfaces...*/
- if (!iUniqueSet.contains(iface)) {
- iUniqueSet.add(iface);
-
- Set<IProducer> producers = producerMap.get(iface);
-
- if (producers != null) {
- for (IProducer producer : producers)
- producer.registerConsumer(iface, consumer);
- iSet.add(iface);
- }
-
- // *...Recurse...*/
- _registerConsumer(consumer, iface.getInterfaces(), iSet,
- iUniqueSet);
- }
- }
- }
-
- protected void _registerConsumer(Object consumer, Class<?> clazz,
- Set<Class<?>> iSet,
- Set<Class<?>> iUniqueSet) {
- if (clazz != null) {
- // *...Process all interfaces...*/
- _registerConsumer(consumer, clazz.getInterfaces(), iSet,
- iUniqueSet);
-
- // *...Recurse the class hierarchy...*/
- _registerConsumer(consumer, clazz.getSuperclass(), iSet,
- iUniqueSet);
- }
- }
-
- protected int _deregisterConsumer(Object consumer,
- Class<?>[] interfaces,
- Set<Class<?>> iUniqueSet) {
- int count = 0;
-
- // *...Process all interfaces...*/
- for (Class<?> iface : interfaces) {
-
- // *...Protect against repeated interfaces...*/
- if (!iUniqueSet.contains(iface)) {
- iUniqueSet.add(iface);
-
- Set<IProducer> producers = producerMap.get(iface);
-
- if (producers != null) {
- for (IProducer producer : producers)
- producer.deregisterConsumer(iface, consumer);
-
- count++;
- }
-
- // *...Recurse...*/
- count += _deregisterConsumer(consumer,
- iface.getInterfaces(),
- iUniqueSet);
- }
- }
-
- return count;
- }
-
- protected int _deregisterConsumer(Object consumer, Class<?> clazz,
- Set<Class<?>> iUniqueSet) {
- int count = 0;
-
- if (clazz != null) {
- // *...Process all interfaces...*/
- count += _deregisterConsumer(consumer, clazz.getInterfaces(),
- iUniqueSet);
-
- // *...Recurse the class hierarchy...*/
- count += _deregisterConsumer(consumer, clazz.getSuperclass(),
- iUniqueSet);
- }
-
- return count;
- }
-
- /*
- * Singleton API
- */
-
- /**
- * @return singleton ProducerConsumer
- */
- public static synchronized ProducerConsumer getSingleton() {
- if (singleton == null) singleton = new ProducerConsumer();
-
- return singleton;
- }
-
- /*
- * Producer APIs
- */
-
- /**
- * Producer registration
- *
- * @param producer
- * object that implements IProducer
- * @param iface
- * interface supported by the producer
- * @return whether there was a previously registered producer, or true if
- * one or more the arguments were invalid
- */
- public boolean registerProducer(IProducer producer, Class<?> iface) {
- if (producer != null && iface != null && iface.isInterface()) {
- Set<IProducer> producers = producerMap.get(iface);
-
- if (producers == null) {
- producers = new HashSet<IProducer>();
- producerMap.put(iface, producers);
- }
-
- return producers.add(producer);
- } else
- return true;
- }
-
- /**
- * Producer deregistration
- *
- * @param producer
- * object that implements IProducer
- * @param iface
- * interface supported by the producer
- * @return whether the interface/producer pair was removed, or false if one
- * or more the arguments were invalid
- */
- public boolean deregisterProducer(IProducer producer, Class<?> iface) {
- if (producer != null && iface != null && iface.isInterface()) {
- Set<IProducer> producers = producerMap.get(iface);
-
- if (producers != null) return producers.remove(producer);
- }
-
- return false;
- }
-
- /*
- * Consumer APIs
- */
-
- /**
- * Consumer registration
- *
- * @param consumer
- * object that implements producer-specific interfaces
- * @return set of supported interfaces
- */
- public Set<Class<?>> registerConsumer(Object consumer) {
- Set<Class<?>> iSet = new HashSet<Class<?>>();
-
- if (consumer != null)
- _registerConsumer(consumer,
- consumer.getClass(), iSet,
- new HashSet<Class<?>>());
-
- return iSet;
- }
-
- /**
- * Consumer deregistration
- *
- * @param consumer
- * object to deregister
- * @return number of unregistered interfaces
- */
- public int deregisterConsumer(Object consumer) {
- if (consumer != null)
- return _deregisterConsumer(consumer, consumer.getClass(),
- new HashSet<Class<?>>());
- else
- return 0;
- }
-
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-import java.util.Arrays;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-public class StringByteSerializer {
- public static String readFrom(ChannelBuffer data, int length) {
- byte[] stringBytes = new byte[length];
- data.readBytes(stringBytes);
- // find the first index of 0
- int index = 0;
- for (byte b : stringBytes) {
- if (0 == b)
- break;
- ++index;
- }
- return new String(Arrays.copyOf(stringBytes, index),
- Charset.forName("ascii"));
- }
-
- public static void writeTo(ChannelBuffer data, int length, String value) {
- try {
- byte[] name = value.getBytes("ASCII");
- if (name.length < length) {
- data.writeBytes(name);
- for (int i = name.length; i < length; ++i) {
- data.writeByte((byte) 0);
- }
- } else {
- data.writeBytes(name, 0, length-1);
- data.writeByte((byte) 0);
- }
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
-
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-public class U16 {
- public static int f(short i) {
- return (int)i & 0xffff;
- }
-
- public static short t(int l) {
- return (short) l;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-public class U32 {
- public static long f(int i) {
- return (long)i & 0xffffffffL;
- }
-
- public static int t(long l) {
- return (int) l;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-import java.math.BigInteger;
-
-public class U64 {
- public static BigInteger f(long i) {
- return new BigInteger(Long.toBinaryString(i), 2);
- }
-
- public static long t(BigInteger l) {
- return l.longValue();
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-public class U8 {
- public static short f(byte i) {
- return (short) ((short)i & 0xff);
- }
-
- public static byte t(short l) {
- return (byte) l;
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-
-/*****
- * A util library class for dealing with the lack of unsigned datatypes in Java
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- * @author David Erickson (daviderickson@cs.stanford.edu)
- */
-
-public class Unsigned {
- /**
- * Get an unsigned byte from the current position of the ByteBuffer
- *
- * @param bb ByteBuffer to get the byte from
- * @return an unsigned byte contained in a short
- */
- public static short getUnsignedByte(ByteBuffer bb) {
- return ((short) (bb.get() & (short) 0xff));
- }
-
- /**
- * Get an unsigned byte from the specified offset in the ByteBuffer
- *
- * @param bb ByteBuffer to get the byte from
- * @param offset the offset to get the byte from
- * @return an unsigned byte contained in a short
- */
- public static short getUnsignedByte(ByteBuffer bb, int offset) {
- return ((short) (bb.get(offset) & (short) 0xff));
- }
-
- /**
- * Put an unsigned byte into the specified ByteBuffer at the current
- * position
- *
- * @param bb ByteBuffer to put the byte into
- * @param v the short containing the unsigned byte
- */
- public static void putUnsignedByte(ByteBuffer bb, short v) {
- bb.put((byte) (v & 0xff));
- }
-
- /**
- * Put an unsigned byte into the specified ByteBuffer at the specified
- * offset
- *
- * @param bb ByteBuffer to put the byte into
- * @param v the short containing the unsigned byte
- * @param offset the offset to insert the unsigned byte at
- */
- public static void putUnsignedByte(ByteBuffer bb, short v, int offset) {
- bb.put(offset, (byte) (v & 0xff));
- }
-
- /**
- * Get an unsigned short from the current position of the ByteBuffer
- *
- * @param bb ByteBuffer to get the byte from
- * @return an unsigned short contained in a int
- */
- public static int getUnsignedShort(ByteBuffer bb) {
- return (bb.getShort() & 0xffff);
- }
-
- /**
- * Get an unsigned short from the specified offset in the ByteBuffer
- *
- * @param bb ByteBuffer to get the short from
- * @param offset the offset to get the short from
- * @return an unsigned short contained in a int
- */
- public static int getUnsignedShort(ByteBuffer bb, int offset) {
- return (bb.getShort(offset) & 0xffff);
- }
-
- /**
- * Put an unsigned short into the specified ByteBuffer at the current
- * position
- *
- * @param bb ByteBuffer to put the short into
- * @param v the int containing the unsigned short
- */
- public static void putUnsignedShort(ByteBuffer bb, int v) {
- bb.putShort((short) (v & 0xffff));
- }
-
- /**
- * Put an unsigned short into the specified ByteBuffer at the specified
- * offset
- *
- * @param bb ByteBuffer to put the short into
- * @param v the int containing the unsigned short
- * @param offset the offset to insert the unsigned short at
- */
- public static void putUnsignedShort(ByteBuffer bb, int v, int offset) {
- bb.putShort(offset, (short) (v & 0xffff));
- }
-
- /**
- * Get an unsigned int from the current position of the ByteBuffer
- *
- * @param bb ByteBuffer to get the int from
- * @return an unsigned int contained in a long
- */
- public static long getUnsignedInt(ByteBuffer bb) {
- return ((long) bb.getInt() & 0xffffffffL);
- }
-
- /**
- * Get an unsigned int from the specified offset in the ByteBuffer
- *
- * @param bb ByteBuffer to get the int from
- * @param offset the offset to get the int from
- * @return an unsigned int contained in a long
- */
- public static long getUnsignedInt(ByteBuffer bb, int offset) {
- return ((long) bb.getInt(offset) & 0xffffffffL);
- }
-
- /**
- * Put an unsigned int into the specified ByteBuffer at the current position
- *
- * @param bb ByteBuffer to put the int into
- * @param v the long containing the unsigned int
- */
- public static void putUnsignedInt(ByteBuffer bb, long v) {
- bb.putInt((int) (v & 0xffffffffL));
- }
-
- /**
- * Put an unsigned int into the specified ByteBuffer at the specified offset
- *
- * @param bb ByteBuffer to put the int into
- * @param v the long containing the unsigned int
- * @param offset the offset to insert the unsigned int at
- */
- public static void putUnsignedInt(ByteBuffer bb, long v, int offset) {
- bb.putInt(offset, (int) (v & 0xffffffffL));
- }
-
- /**
- * Get an unsigned long from the current position of the ByteBuffer
- *
- * @param bb ByteBuffer to get the long from
- * @return an unsigned long contained in a BigInteger
- */
- public static BigInteger getUnsignedLong(ByteBuffer bb) {
- byte[] v = new byte[8];
- for (int i = 0; i < 8; ++i) {
- v[i] = bb.get(i);
- }
- return new BigInteger(1, v);
- }
-
- /**
- * Get an unsigned long from the specified offset in the ByteBuffer
- *
- * @param bb ByteBuffer to get the long from
- * @param offset the offset to get the long from
- * @return an unsigned long contained in a BigInteger
- */
- public static BigInteger getUnsignedLong(ByteBuffer bb, int offset) {
- byte[] v = new byte[8];
- for (int i = 0; i < 8; ++i) {
- v[i] = bb.get(offset+i);
- }
- return new BigInteger(1, v);
- }
-
- /**
- * Put an unsigned long into the specified ByteBuffer at the current
- * position
- *
- * @param bb ByteBuffer to put the long into
- * @param v the BigInteger containing the unsigned long
- */
- public static void putUnsignedLong(ByteBuffer bb, BigInteger v) {
- bb.putLong(v.longValue());
- }
-
- /**
- * Put an unsigned long into the specified ByteBuffer at the specified
- * offset
- *
- * @param bb ByteBuffer to put the long into
- * @param v the BigInteger containing the unsigned long
- * @param offset the offset to insert the unsigned long at
- */
- public static void putUnsignedLong(ByteBuffer bb, BigInteger v, int offset) {
- bb.putLong(offset, v.longValue());
- }
-}
+++ /dev/null
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson & Rob Sherwood, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.vendor.nicira;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.vendor.OFVendorData;
-
-/**
- * Base class for vendor data corresponding to a Nicira vendor extension.
- * Nicira vendor data always starts with a 4-byte integer data type value.
- *
- * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
- */
-public class OFNiciraVendorData implements OFVendorData {
-
- public static final int NX_VENDOR_ID = 0x00002320;
- /**
- * The value of the integer data type at the beginning of the vendor data
- */
- protected int dataType;
-
- /**
- * Construct empty (i.e. unspecified data type) Nicira vendor data.
- */
- public OFNiciraVendorData() {
- }
-
- /**
- * Contruct Nicira vendor data with the specified data type
- * @param dataType the data type value at the beginning of the vendor data.
- */
- public OFNiciraVendorData(int dataType) {
- this.dataType = dataType;
- }
-
- /**
- * Get the data type value at the beginning of the vendor data
- * @return the integer data type value
- */
- public int getDataType() {
- return dataType;
- }
-
- /**
- * Set the data type value
- * @param dataType the integer data type value at the beginning of the
- * vendor data.
- */
- public void setDataType(int dataType) {
- this.dataType = dataType;
- }
-
- /**
- * Get the length of the vendor data. This implementation will normally
- * be the superclass for another class that will override this to return
- * the overall vendor data length. This implementation just returns the
- * length of the part that includes the 4-byte integer data type value
- * at the beginning of the vendor data.
- */
- @Override
- public int getLength() {
- return 4;
- }
-
- /**
- * Read the vendor data from the ChannelBuffer
- * @param data the channel buffer from which we're deserializing
- * @param length the length to the end of the enclosing message
- */
- @Override
- public void readFrom(ChannelBuffer data, int length) {
- dataType = data.readInt();
- }
-
- /**
- * Write the vendor data to the ChannelBuffer
- * @param data the channel buffer to which we're serializing
- */
- @Override
- public void writeTo(ChannelBuffer data) {
- data.writeInt(dataType);
- }
-}
+++ /dev/null
-package org.openflow.vendor.nicira;
-
-import org.openflow.protocol.vendor.OFBasicVendorDataType;
-import org.openflow.protocol.vendor.OFBasicVendorId;
-import org.openflow.protocol.vendor.OFVendorId;
-
-public class OFNiciraVendorExtensions {
- private static boolean initialized = false;
-
- public static synchronized void initialize() {
- if (initialized)
- return;
-
- // Configure openflowj to be able to parse the role request/reply
- // vendor messages.
- OFBasicVendorId niciraVendorId =
- new OFBasicVendorId(OFNiciraVendorData.NX_VENDOR_ID, 4);
- OFVendorId.registerVendorId(niciraVendorId);
- OFBasicVendorDataType roleRequestVendorData =
- new OFBasicVendorDataType(OFRoleRequestVendorData.NXT_ROLE_REQUEST,
- OFRoleRequestVendorData.getInstantiable());
- niciraVendorId.registerVendorDataType(roleRequestVendorData);
- OFBasicVendorDataType roleReplyVendorData =
- new OFBasicVendorDataType(OFRoleReplyVendorData.NXT_ROLE_REPLY,
- OFRoleReplyVendorData.getInstantiable());
- niciraVendorId.registerVendorDataType(roleReplyVendorData);
-
- initialized = true;
- }
-}
+++ /dev/null
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson & Rob Sherwood, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.vendor.nicira;
-
-import org.openflow.protocol.Instantiable;
-import org.openflow.protocol.vendor.OFVendorData;
-
-/**
- * Subclass of OFVendorData representing the vendor data associated with
- * a role reply vendor extension.
- *
- * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
- */
-public class OFRoleReplyVendorData extends OFRoleVendorData {
-
- protected static Instantiable<OFVendorData> instantiable =
- new Instantiable<OFVendorData>() {
- public OFVendorData instantiate() {
- return new OFRoleReplyVendorData();
- }
- };
-
- /**
- * @return a subclass of Instantiable<OFVendorData> that instantiates
- * an instance of OFRoleReplyVendorData.
- */
- public static Instantiable<OFVendorData> getInstantiable() {
- return instantiable;
- }
-
- /**
- * The data type value for a role reply
- */
- public static final int NXT_ROLE_REPLY = 11;
-
- /**
- * Construct a role reply vendor data with an unspecified role value.
- */
- public OFRoleReplyVendorData() {
- super(NXT_ROLE_REPLY);
- }
-
- /**
- * Construct a role reply vendor data with the specified role value.
- * @param role the role value for the role reply. Should be one of
- * NX_ROLE_OTHER, NX_ROLE_MASTER or NX_ROLE_SLAVE.
- */
- public OFRoleReplyVendorData(int role) {
- super(NXT_ROLE_REPLY, role);
- }
-}
+++ /dev/null
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson & Rob Sherwood, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.vendor.nicira;
-
-import org.openflow.protocol.Instantiable;
-import org.openflow.protocol.vendor.OFVendorData;
-
-/**
- * Subclass of OFVendorData representing the vendor data associated with
- * a role request vendor extension.
- *
- * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
- */
-public class OFRoleRequestVendorData extends OFRoleVendorData {
-
- protected static Instantiable<OFVendorData> instantiable =
- new Instantiable<OFVendorData>() {
- public OFVendorData instantiate() {
- return new OFRoleRequestVendorData();
- }
- };
-
- /**
- * @return a subclass of Instantiable<OFVendorData> that instantiates
- * an instance of OFRoleRequestVendorData.
- */
- public static Instantiable<OFVendorData> getInstantiable() {
- return instantiable;
- }
-
- /**
- * The data type value for a role request
- */
- public static final int NXT_ROLE_REQUEST = 10;
-
- /**
- * Construct a role request vendor data with an unspecified role value.
- */
- public OFRoleRequestVendorData() {
- super(NXT_ROLE_REQUEST);
- }
-
- /**
- * Construct a role request vendor data with the specified role value.
- * @param role the role value for the role request. Should be one of
- * NX_ROLE_OTHER, NX_ROLE_MASTER or NX_ROLE_SLAVE.
- */
- public OFRoleRequestVendorData(int role) {
- super(NXT_ROLE_REQUEST, role);
- }
-}
+++ /dev/null
-/**
-* Copyright 2011, Big Switch Networks, Inc.
-* Originally created by David Erickson & Rob Sherwood, Stanford University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.vendor.nicira;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- * Class that represents the vendor data in the role request
- * extension implemented by Open vSwitch to support high availability.
- *
- * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
- */
-public class OFRoleVendorData extends OFNiciraVendorData {
-
- /**
- * Role value indicating that the controller is in the OTHER role.
- */
- public static final int NX_ROLE_OTHER = 0;
-
- /**
- * Role value indicating that the controller is in the MASTER role.
- */
- public static final int NX_ROLE_MASTER = 1;
-
- /**
- * Role value indicating that the controller is in the SLAVE role.
- */
- public static final int NX_ROLE_SLAVE = 2;
-
- protected int role;
-
- /**
- * Construct an uninitialized OFRoleVendorData
- */
- public OFRoleVendorData() {
- super();
- }
-
- /**
- * Construct an OFRoleVendorData with the specified data type
- * (i.e. either request or reply) and an unspecified role.
- * @param dataType
- */
- public OFRoleVendorData(int dataType) {
- super(dataType);
- }
-
- /**
- * Construct an OFRoleVendorData with the specified data type
- * (i.e. either request or reply) and role (i.e. one of of
- * master, slave, or other).
- * @param dataType either role request or role reply data type
- */
- public OFRoleVendorData(int dataType, int role) {
- super(dataType);
- this.role = role;
- }
- /**
- * @return the role value of the role vendor data
- */
- public int getRole() {
- return role;
- }
-
- /**
- * @param role the role value of the role vendor data
- */
- public void setRole(int role) {
- this.role = role;
- }
-
- /**
- * @return the total length of the role vendor data
- */
- @Override
- public int getLength() {
- return super.getLength() + 4;
- }
-
- /**
- * Read the role vendor data from the ChannelBuffer
- * @param data the channel buffer from which we're deserializing
- * @param length the length to the end of the enclosing message
- */
- public void readFrom(ChannelBuffer data, int length) {
- super.readFrom(data, length);
- role = data.readInt();
- }
-
- /**
- * Write the role vendor data to the ChannelBuffer
- * @param data the channel buffer to which we're serializing
- */
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeInt(role);
- }
-}
+++ /dev/null
-/**
-* Copyright 2012, Andrew Ferguson, Brown University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.vendor.openflow;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.vendor.OFVendorData;
-
-/**
- * Base class for vendor data corresponding to extensions to OpenFlow 1.0.
- * Based on org.openflow.vendor.nicira
- *
- * @author Andrew Ferguson (adf@cs.brown.edu)
- */
-public class OFOpenFlowVendorData implements OFVendorData {
-
- public static final int OF_VENDOR_ID = 0x000026e1;
-
- /**
- * The value of the integer data type at the beginning of the vendor data
- */
- protected int dataType;
-
- /**
- * Construct empty (i.e. unspecified data type) OpenFlow vendor data.
- */
- public OFOpenFlowVendorData() {
- }
-
- /**
- * Construct OpenFlow vendor data with the specified data type
- * @param dataType the data type value at the beginning of the vendor data.
- */
- public OFOpenFlowVendorData(int dataType) {
- this.dataType = dataType;
- }
-
- /**
- * Get the data type value at the beginning of the vendor data
- * @return the integer data type value
- */
- public int getDataType() {
- return dataType;
- }
-
- /**
- * Set the data type value
- * @param dataType the integer data type value at the beginning of the
- * vendor data.
- */
- public void setDataType(int dataType) {
- this.dataType = dataType;
- }
-
- /**
- * Get the length of the vendor data. This implementation will normally
- * be the superclass for another class that will override this to return
- * the overall vendor data length. This implementation just returns the
- * length of the part that includes the 4-byte integer data type value
- * at the beginning of the vendor data.
- */
- @Override
- public int getLength() {
- return 4;
- }
-
- /**
- * Read the vendor data from the ChannelBuffer
- * @param data the channel buffer from which we're deserializing
- * @param length the length to the end of the enclosing message
- */
- @Override
- public void readFrom(ChannelBuffer data, int length) {
- dataType = data.readInt();
- }
-
- /**
- * Write the vendor data to the ChannelBuffer
- * @param data the channel buffer to which we're serializing
- */
- @Override
- public void writeTo(ChannelBuffer data) {
- data.writeInt(dataType);
- }
-}
+++ /dev/null
-/**
-* Copyright 2012, Andrew Ferguson, Brown University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.vendor.openflow;
-
-import org.openflow.protocol.vendor.OFBasicVendorDataType;
-import org.openflow.protocol.vendor.OFBasicVendorId;
-import org.openflow.protocol.vendor.OFVendorId;
-
-public class OFOpenFlowVendorExtensions {
- private static boolean initialized = false;
-
- public static synchronized void initialize() {
- if (initialized)
- return;
-
- // Configure openflowj to be able to parse the OpenFlow extensions.
- OFBasicVendorId openflowVendorId =
- new OFBasicVendorId(OFOpenFlowVendorData.OF_VENDOR_ID, 4);
- OFVendorId.registerVendorId(openflowVendorId);
-
- OFBasicVendorDataType queueModifyVendorData =
- new OFBasicVendorDataType(OFQueueModifyVendorData.OFP_EXT_QUEUE_MODIFY,
- OFQueueModifyVendorData.getInstantiable());
- openflowVendorId.registerVendorDataType(queueModifyVendorData);
-
- OFBasicVendorDataType queueDeleteVendorData =
- new OFBasicVendorDataType(OFQueueDeleteVendorData.OFP_EXT_QUEUE_DELETE,
- OFQueueModifyVendorData.getInstantiable());
- openflowVendorId.registerVendorDataType(queueDeleteVendorData);
-
- initialized = true;
- }
-}
+++ /dev/null
-/**
-* Copyright 2012, Andrew Ferguson, Brown University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.vendor.openflow;
-
-import org.openflow.protocol.Instantiable;
-import org.openflow.protocol.vendor.OFVendorData;
-
-/**
- * Class that represents the vendor data in the queue delete request
- *
- * @author Andrew Ferguson (adf@cs.brown.edu)
- */
-public class OFQueueDeleteVendorData extends OFQueueVendorData {
-
- protected static Instantiable<OFVendorData> instantiable =
- new Instantiable<OFVendorData>() {
- public OFVendorData instantiate() {
- return new OFQueueDeleteVendorData();
- }
- };
-
- /**
- * @return a subclass of Instantiable<OFVendorData> that instantiates
- * an instance of OFQueueDeleteVendorData.
- */
- public static Instantiable<OFVendorData> getInstantiable() {
- return instantiable;
- }
-
- /**
- * The data type value for a queue delete request
- */
- public static final int OFP_EXT_QUEUE_DELETE = 1;
-
- public OFQueueDeleteVendorData() {
- super(OFP_EXT_QUEUE_DELETE);
- }
-}
+++ /dev/null
-/**
-* Copyright 2012, Andrew Ferguson, Brown University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.vendor.openflow;
-
-import org.openflow.protocol.Instantiable;
-import org.openflow.protocol.vendor.OFVendorData;
-
-/**
- * Class that represents the vendor data in the queue modify request
- *
- * @author Andrew Ferguson (adf@cs.brown.edu)
- */
-public class OFQueueModifyVendorData extends OFQueueVendorData {
-
- protected static Instantiable<OFVendorData> instantiable =
- new Instantiable<OFVendorData>() {
- public OFVendorData instantiate() {
- return new OFQueueModifyVendorData();
- }
- };
-
- /**
- * @return a subclass of Instantiable<OFVendorData> that instantiates
- * an instance of OFQueueModifyVendorData.
- */
- public static Instantiable<OFVendorData> getInstantiable() {
- return instantiable;
- }
-
- /**
- * The data type value for a queue modify request
- */
- public static final int OFP_EXT_QUEUE_MODIFY = 0;
-
- public OFQueueModifyVendorData() {
- super(OFP_EXT_QUEUE_MODIFY);
- }
-}
+++ /dev/null
-/**
-* Copyright 2012, Andrew Ferguson, Brown University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.vendor.openflow;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.OFPacketQueue;
-
-/**
- * Class that represents the vendor data in a queue modify or delete request
- *
- * @author Andrew Ferguson (adf@cs.brown.edu)
- */
-public class OFQueueVendorData extends OFOpenFlowVendorData {
- public static int MINIMUM_LENGTH = 8;
-
- protected short portNumber;
- protected List<OFPacketQueue> queues = new ArrayList<OFPacketQueue>();
-
- public OFQueueVendorData(int dataType) {
- super(dataType);
- }
-
- /**
- * @return the portNumber
- */
- public short getPortNumber() {
- return portNumber;
- }
-
- /**
- * @param port the port on which the queue is
- */
- public void setPortNumber(short portNumber) {
- this.portNumber = portNumber;
- }
-
-
- /**
- * @return the queues
- */
- public List<OFPacketQueue> getQueues() {
- return queues;
- }
-
- /**
- * @param queues the queues to modify or delete
- */
- public void setQueues(List<OFPacketQueue> queues) {
- this.queues = queues;
- }
-
- /**
- * @return the total length of the queue modify or delete msg
- */
- @Override
- public int getLength() {
- int queuesLength = 0;
-
- for (OFPacketQueue queue : queues) {
- queuesLength += queue.getLength();
- }
-
- return super.getLength() + MINIMUM_LENGTH + queuesLength;
- }
-
- /**
- * Read the queue message data from the ChannelBuffer
- * @param data the channel buffer from which we're deserializing
- * @param length the length to the end of the enclosing message
- */
- public void readFrom(ChannelBuffer data, int length) {
- super.readFrom(data, length);
- portNumber = data.readShort();
- data.readInt(); // pad
- data.readShort(); // pad
-
- int availLength = (length - MINIMUM_LENGTH);
- this.queues.clear();
-
- while (availLength > 0) {
- OFPacketQueue queue = new OFPacketQueue();
- queue.readFrom(data);
- queues.add(queue);
- availLength -= queue.getLength();
- }
- }
-
- /**
- * Write the queue message data to the ChannelBuffer
- * @param data the channel buffer to which we're serializing
- */
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeShort(this.portNumber);
- data.writeInt(0); // pad
- data.writeShort(0); // pad
-
- for (OFPacketQueue queue : queues) {
- queue.writeTo(data);
- }
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import static org.junit.Assert.assertArrayEquals;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.protocol.action.MockVendorAction;
-import org.openflow.protocol.action.MockVendorActionFactory;
-import org.openflow.protocol.action.OFAction;
-import org.openflow.protocol.action.OFActionVendorGeneric;
-import org.openflow.protocol.factory.BasicFactory;
-import org.openflow.protocol.factory.MessageParseException;
-import org.openflow.protocol.factory.OFVendorActionRegistry;
-import org.openflow.util.U16;
-
-public class BasicFactoryTest extends TestCase {
-
- public void testCreateAndParse() throws MessageParseException {
- BasicFactory factory = new BasicFactory();
- OFMessage m = factory.getMessage(OFType.HELLO);
- m.setVersion((byte) 1);
- m.setType(OFType.ECHO_REQUEST);
- m.setLength(U16.t(8));
- m.setXid(0xdeadbeef);
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- ChannelBuffer bb2 = ChannelBuffers.dynamicBuffer();
- m.writeTo(bb);
- bb2.writeBytes(bb, bb.readableBytes()-1);
- TestCase.assertNull(factory.parseMessage(bb2));
- bb2.writeByte(bb.readByte());
- List<OFMessage> message = factory.parseMessage(bb2);
- TestCase.assertNotNull(message);
- TestCase.assertEquals(message.size(), 1);
- TestCase.assertTrue(message.get(0).getType() == OFType.ECHO_REQUEST);
- }
-
- public void testInvalidMsgParse() throws MessageParseException {
- BasicFactory factory = new BasicFactory();
- OFMessage m = factory.getMessage(OFType.HELLO);
- m.setVersion((byte) 1);
- m.setType(OFType.ECHO_REQUEST);
- m.setLength(U16.t(16));
- m.setXid(0xdeadbeef);
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- m.writeTo(bb);
- List<OFMessage> message = factory.parseMessage(bb);
- TestCase.assertNull(message);
- }
-
- public void testCurrouptedMsgParse() throws MessageParseException {
- BasicFactory factory = new BasicFactory();
- OFMessage m = factory.getMessage(OFType.HELLO);
- m.setVersion((byte) 1);
- m.setType(OFType.ERROR);
- m.setLength(U16.t(8));
- m.setXid(0xdeadbeef);
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- m.writeTo(bb);
- try {
- factory.parseMessage(bb);
- }
- catch(Exception e) {
- TestCase.assertEquals(MessageParseException.class, e.getClass());
- }
- }
-
- public void testCustomVendorAction() throws MessageParseException {
- BasicFactory factory = new BasicFactory();
- OFVendorActionRegistry.getInstance().register(
- MockVendorAction.VENDOR_ID, new MockVendorActionFactory());
-
-
- byte[] deadBeefMessage = {
- (byte) 0xff, (byte) 0xff, // action vendor
- 0x00, 0x10, // length
- (byte) 0xde, (byte) 0xad, (byte) 0xbe, (byte)0xef, // deadbeaf
- 0x01, 0x02, 0x03, 0x04,
- 0x05, 0x06, 0x07, 0x08 // pad
- };
-
- ChannelBuffer buf = ChannelBuffers.copiedBuffer(deadBeefMessage);
-
- List<OFAction> actions = factory.parseActions(buf,deadBeefMessage.length);
- assertEquals(1, actions.size());
- OFAction ofAction = actions.get(0);
- assertTrue("Action should be MockVendorAction, but is "+ofAction.getClass(), ofAction instanceof MockVendorAction);
- assertArrayEquals( new byte[] { 1,2,3,4,5,6,7,8}, ((MockVendorAction)ofAction).getMockData());
-
-
- }
-
- public void testGenericVendorAction() throws MessageParseException {
- byte[] nonDeadBeefMessage = {
- (byte) 0xff, (byte) 0xff, // action vendor
- 0x00, 0x10, // length
- (byte) 0x7e, (byte) 0xe7, (byte) 0xbe, (byte)0xef, // deadbeaf
- 0x01, 0x02, 0x03, 0x04,
- 0x05, 0x06, 0x07, 0x08 // pad
- };
-
- BasicFactory factory = new BasicFactory();
- OFVendorActionRegistry.getInstance().register(
- MockVendorAction.VENDOR_ID, new MockVendorActionFactory());
-
- ChannelBuffer buf = ChannelBuffers.copiedBuffer(nonDeadBeefMessage);
-
- List<OFAction> actions = factory.parseActions(buf,nonDeadBeefMessage.length);
- assertEquals(1, actions.size());
- OFAction ofAction = actions.get(0);
- assertTrue("Action should be OFActionVendorGeneric, but is "+ofAction.getClass(), ofAction instanceof OFActionVendorGeneric);
- }
-
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-
-import org.junit.Test;
-import org.openflow.protocol.action.OFActionType;
-
-import junit.framework.TestCase;
-
-
-public class OFActionTypeTest extends TestCase {
- @Test
- public void testMapping() throws Exception {
- TestCase.assertEquals(OFActionType.OUTPUT,
- OFActionType.valueOf((short) 0));
- TestCase.assertEquals(OFActionType.OPAQUE_ENQUEUE,
- OFActionType.valueOf((short) 11));
- TestCase.assertEquals(OFActionType.VENDOR,
- OFActionType.valueOf((short) 0xffff));
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import junit.framework.TestCase;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.util.OFTestCase;
-
-public class OFBarrierReplyTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFBarrierReply msg = (OFBarrierReply) messageFactory
- .getMessage(OFType.BARRIER_REPLY);
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- bb.clear();
- msg.writeTo(bb);
- msg.readFrom(bb);
- TestCase.assertEquals(OFType.BARRIER_REPLY, msg.getType());
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import junit.framework.TestCase;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.util.OFTestCase;
-
-public class OFBarrierRequestTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFBarrierRequest msg = (OFBarrierRequest) messageFactory
- .getMessage(OFType.BARRIER_REQUEST);
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- bb.clear();
- msg.writeTo(bb);
- msg.readFrom(bb);
- TestCase.assertEquals(OFType.BARRIER_REQUEST, msg.getType());
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.protocol.OFError.OFErrorType;
-import org.openflow.protocol.OFError.OFHelloFailedCode;
-import org.openflow.protocol.factory.BasicFactory;
-import org.openflow.protocol.factory.MessageParseException;
-import org.openflow.protocol.factory.OFMessageFactory;
-import org.openflow.util.OFTestCase;
-
-public class OFErrorTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFError msg = (OFError) messageFactory.getMessage(OFType.ERROR);
- msg.setMessageFactory(messageFactory);
- msg.setErrorType((short) OFErrorType.OFPET_HELLO_FAILED.getValue());
- msg.setErrorCode((short) OFHelloFailedCode.OFPHFC_INCOMPATIBLE
- .ordinal());
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- bb.clear();
- msg.writeTo(bb);
- msg.readFrom(bb);
- TestCase.assertEquals((short) OFErrorType.OFPET_HELLO_FAILED.getValue(),
- msg.getErrorType());
- TestCase.assertEquals((short) OFHelloFailedCode.OFPHFC_INCOMPATIBLE
- .ordinal(), msg.getErrorType());
- TestCase.assertNull(msg.getOffendingMsg());
-
- msg.setOffendingMsg(new OFHello());
- bb.clear();
- msg.writeTo(bb);
- msg.readFrom(bb);
- TestCase.assertEquals((short) OFErrorType.OFPET_HELLO_FAILED.getValue(),
- msg.getErrorType());
- TestCase.assertEquals((short) OFHelloFailedCode.OFPHFC_INCOMPATIBLE
- .ordinal(), msg.getErrorType());
- TestCase.assertNotNull(msg.getOffendingMsg());
- TestCase.assertEquals(OFHello.MINIMUM_LENGTH,
- msg.getOffendingMsg().length);
- }
-
- public void testGarbageAtEnd() throws MessageParseException {
- // This is a OFError msg (12 bytes), that encaps a OFVendor msg (24
- // bytes)
- // AND some zeros at the end (40 bytes) for a total of 76 bytes
- // THIS is what an NEC sends in reply to Nox's VENDOR request
- byte[] oferrorRaw = { 0x01, 0x01, 0x00, 0x4c, 0x00, 0x00, 0x10,
- (byte) 0xcc, 0x00, 0x01, 0x00, 0x01, 0x01, 0x04, 0x00, 0x18,
- 0x00, 0x00, 0x10, (byte) 0xcc, 0x00, 0x00, 0x23, 0x20, 0x00,
- 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00 };
- OFMessageFactory factory = new BasicFactory();
- ChannelBuffer oferrorBuf =
- ChannelBuffers.wrappedBuffer(oferrorRaw);
- List<OFMessage> msg = factory.parseMessage(oferrorBuf);
- TestCase.assertNotNull(msg);
- TestCase.assertEquals(msg.size(), 1);
- TestCase.assertEquals(76, msg.get(0).getLengthU());
- ChannelBuffer out = ChannelBuffers.dynamicBuffer();
- msg.get(0).writeTo(out);
- TestCase.assertEquals(76, out.readableBytes());
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.util.OFTestCase;
-
-
-public class OFFeaturesReplyTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFFeaturesReply ofr = (OFFeaturesReply) messageFactory
- .getMessage(OFType.FEATURES_REPLY);
- List<OFPhysicalPort> ports = new ArrayList<OFPhysicalPort>();
- OFPhysicalPort port = new OFPhysicalPort();
- port.setHardwareAddress(new byte[6]);
- port.setName("eth0");
- ports.add(port);
- ofr.setPorts(ports);
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- bb.clear();
- ofr.writeTo(bb);
- ofr.readFrom(bb);
- TestCase.assertEquals(1, ofr.getPorts().size());
- TestCase.assertEquals("eth0", ofr.getPorts().get(0).getName());
-
- // test a 15 character name
- ofr.getPorts().get(0).setName("012345678901234");
- bb.clear();
- ofr.writeTo(bb);
- ofr.readFrom(bb);
- TestCase.assertEquals("012345678901234", ofr.getPorts().get(0).getName());
-
- // test a 16 character name getting truncated
- ofr.getPorts().get(0).setName("0123456789012345");
- bb.clear();
- ofr.writeTo(bb);
- ofr.readFrom(bb);
- TestCase.assertEquals("012345678901234", ofr.getPorts().get(0).getName());
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import junit.framework.TestCase;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.protocol.OFFlowRemoved.OFFlowRemovedReason;
-import org.openflow.util.OFTestCase;
-
-public class OFFlowRemovedTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFFlowRemoved msg = (OFFlowRemoved) messageFactory
- .getMessage(OFType.FLOW_REMOVED);
- msg.setMatch(new OFMatch());
- byte[] hwAddr = new byte[6];
- msg.getMatch().setDataLayerDestination(hwAddr);
- msg.getMatch().setDataLayerSource(hwAddr);
- msg.setReason(OFFlowRemovedReason.OFPRR_DELETE);
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- bb.clear();
- msg.writeTo(bb);
- msg.readFrom(bb);
- TestCase.assertEquals(OFType.FLOW_REMOVED, msg.getType());
- TestCase.assertEquals(OFFlowRemovedReason.OFPRR_DELETE, msg.getReason());
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import junit.framework.TestCase;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.util.OFTestCase;
-
-public class OFGetConfigReplyTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFSetConfig msg = (OFSetConfig) messageFactory
- .getMessage(OFType.SET_CONFIG);
- msg.setFlags((short) 1);
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- bb.clear();
- msg.writeTo(bb);
- msg.readFrom(bb);
- TestCase.assertEquals(OFType.SET_CONFIG, msg.getType());
- TestCase.assertEquals((short)1, msg.getFlags());
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import junit.framework.TestCase;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.util.OFTestCase;
-
-public class OFGetConfigRequestTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFGetConfigRequest msg = (OFGetConfigRequest) messageFactory
- .getMessage(OFType.GET_CONFIG_REQUEST);
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- bb.clear();
- msg.writeTo(bb);
- msg.readFrom(bb);
- TestCase.assertEquals(OFType.GET_CONFIG_REQUEST, msg.getType());
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import junit.framework.TestCase;
-
-public class OFMatchTest extends TestCase {
- public void testFromString() {
- OFMatch correct = new OFMatch();
- OFMatch tester = new OFMatch();
-
- // Various combinations of "all"/"any"
- tester.fromString("OFMatch[]");
- // correct is already wildcarded
- TestCase.assertEquals(correct, tester);
- tester.fromString("all");
- TestCase.assertEquals(correct, tester);
- tester.fromString("ANY");
- TestCase.assertEquals(correct, tester);
- tester.fromString("");
- TestCase.assertEquals(correct, tester);
- tester.fromString("[]");
- TestCase.assertEquals(correct, tester);
-
- // ip_src
- correct.setWildcards(~OFMatch.OFPFW_NW_SRC_MASK);
- correct.setNetworkSource(0x01010203);
- tester.fromString("nw_src=1.1.2.3");
- TestCase.assertEquals(correct.getNetworkSourceMaskLen(), tester
- .getNetworkSourceMaskLen());
- TestCase.assertEquals(correct, tester);
- tester.fromString("IP_sRc=1.1.2.3");
- TestCase.assertEquals(correct.getNetworkSourceMaskLen(), tester
- .getNetworkSourceMaskLen());
- TestCase.assertEquals(correct, tester);
-
- // 0xVlan
- correct = new OFMatch();
- correct.setDataLayerVirtualLan((short)65535);
- correct.setWildcards(~OFMatch.OFPFW_DL_VLAN);
- tester = new OFMatch();
- tester.fromString("dl_vlan=0xffff");
- TestCase.assertEquals(correct, tester);
- }
-
- public void testToString() {
- OFMatch match = new OFMatch();
- match.fromString("nw_dst=3.4.5.6/8");
- TestCase.assertEquals(8, match.getNetworkDestinationMaskLen());
- String correct = "OFMatch[nw_dst=3.0.0.0/8]";
- String tester = match.toString();
-
- TestCase.assertEquals(correct, tester);
- tester = "OFMatch[dl_type=35020]";
- correct = "OFMatch[dl_type=0x88cc]";
- match = new OFMatch();
- match.fromString(tester);
- TestCase.assertEquals(correct, match.toString());
- OFMatch match2 = new OFMatch();
- match2.fromString(correct);
- TestCase.assertEquals(match, match2);
- }
-
- public void testClone() {
- OFMatch match1 = new OFMatch();
- OFMatch match2 = match1.clone();
- TestCase.assertEquals(match1, match2);
- match2.setNetworkProtocol((byte) 4);
- match2.setWildcards(match2.getWildcards() & ~OFMatch.OFPFW_NW_PROTO);
- TestCase.assertNotSame(match1, match2);
- }
-
- public void testIpToString() {
- String test = OFMatch.ipToString(-1);
- TestCase.assertEquals("255.255.255.255", test);
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import junit.framework.TestCase;
-
-public class OFMessageContextStoreTest extends TestCase {
- public void testStoreAndGet() {
- OFMessage msg = new OFMessage();
- OFMessageContextStore<String> store = new OFMessageContextStore<String>(msg, this.getName());
- String key = "mykey";
- String value = "myvalue";
- store.put(key, value);
- TestCase.assertEquals(value, store.get(key));
- }
-}
+++ /dev/null
-package org.openflow.protocol;
-
-import org.junit.Test;
-
-public class OFPacketOutTest {
-
- @Test(expected = IllegalArgumentException.class)
- public void testBothBufferIdAndPayloadSet() {
- OFPacketOut packetOut = new OFPacketOut();
- packetOut.setBufferId(12);
- packetOut.setPacketData(new byte[] { 1, 2, 3 });
- }
-
- @Test
- public void testOnlyBufferIdSet() {
- OFPacketOut packetOut = new OFPacketOut();
- packetOut.setBufferId(12);
- packetOut.setPacketData(null);
- packetOut.setPacketData(new byte[] {});
- packetOut.validate();
- }
-
- @Test(expected = IllegalStateException.class)
- public void testNeitherBufferIdNorPayloadSet() {
- OFPacketOut packetOut = new OFPacketOut();
- packetOut.setBufferId(OFPacketOut.BUFFER_ID_NONE);
- packetOut.setPacketData(null);
- packetOut.validate();
- }
-
- @Test(expected = IllegalStateException.class)
- public void testNeitherBufferIdNorPayloadSet2() {
- OFPacketOut packetOut = new OFPacketOut();
- packetOut.setBufferId(OFPacketOut.BUFFER_ID_NONE);
- packetOut.setPacketData(new byte[] {});
- packetOut.validate();
- }
-
- @Test(expected = IllegalStateException.class)
- public void testNeitherBufferIdNorPayloadSet3() {
- OFPacketOut packetOut = new OFPacketOut();
- packetOut.validate();
- }
-
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import junit.framework.TestCase;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.util.OFTestCase;
-
-public class OFPortConfigTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFPortMod msg = (OFPortMod) messageFactory
- .getMessage(OFType.PORT_MOD);
- msg.setHardwareAddress(new byte[6]);
- msg.portNumber = 1;
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- bb.clear();
- msg.writeTo(bb);
- msg.readFrom(bb);
- TestCase.assertEquals(OFType.PORT_MOD, msg.getType());
- TestCase.assertEquals(1, msg.getPortNumber());
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import junit.framework.TestCase;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.protocol.OFPortStatus.OFPortReason;
-import org.openflow.util.OFTestCase;
-
-public class OFPortStatusTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFPortStatus msg = (OFPortStatus) messageFactory
- .getMessage(OFType.PORT_STATUS);
- msg.setDesc(new OFPhysicalPort());
- msg.getDesc().setHardwareAddress(new byte[6]);
- msg.getDesc().setName("eth0");
- msg.setReason((byte) OFPortReason.OFPPR_ADD.ordinal());
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- bb.clear();
- msg.writeTo(bb);
- msg.readFrom(bb);
- TestCase.assertEquals(OFType.PORT_STATUS, msg.getType());
- TestCase.assertEquals((byte) OFPortReason.OFPPR_ADD.ordinal(), msg
- .getReason());
- TestCase.assertNotNull(msg.getDesc());
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import junit.framework.TestCase;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.util.OFTestCase;
-
-public class OFSetConfigTest extends OFTestCase {
- public void testWriteRead() throws Exception {
- OFGetConfigReply msg = (OFGetConfigReply) messageFactory
- .getMessage(OFType.GET_CONFIG_REPLY);
- msg.setFlags((short) 1);
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- bb.clear();
- msg.writeTo(bb);
- msg.readFrom(bb);
- TestCase.assertEquals(OFType.GET_CONFIG_REPLY, msg.getType());
- TestCase.assertEquals((short)1, msg.getFlags());
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.protocol.factory.BasicFactory;
-import org.openflow.protocol.factory.OFMessageFactory;
-import org.openflow.protocol.statistics.OFStatisticsType;
-import org.openflow.util.OFTestCase;
-
-public class OFStatisticsReplyTest extends OFTestCase {
- public void testOFFlowStatisticsReply() throws Exception {
- byte[] packet = new byte[] { 0x01, 0x11, 0x01, 0x2c, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, (byte) 0xff,
- (byte) 0xff, 0x00, 0x00, 0x08, 0x00, 0x00, 0x01, 0x00, 0x00,
- 0x0a, 0x00, 0x00, 0x03, 0x0a, 0x00, 0x00, 0x02, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, (byte) 0xa6,
- (byte) 0xa6, 0x00, (byte) 0xff, (byte) 0xff, 0x00, 0x05, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- (byte) 0xc4, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00,
- 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x02, (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x08, 0x06,
- 0x00, 0x02, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x03, 0x0a, 0x00,
- 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x3b, 0x2f, (byte) 0xfa, 0x40, (byte) 0xff, (byte) 0xff, 0x00,
- 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00,
- 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x03, (byte) 0xff, (byte) 0xff, 0x00, 0x62, 0x08,
- 0x00, 0x00, 0x01, 0x62, 0x37, 0x0a, 0x00, 0x00, 0x02, 0x0a,
- 0x00, 0x00, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x3a, (byte) 0xc5, 0x2a, (byte) 0x80, (byte) 0xff,
- (byte) 0xff, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0xc4, 0x00, 0x00, 0x00,
- 0x08, 0x00, 0x02, 0x00, 0x00 };
-
- OFMessageFactory factory = new BasicFactory();
- ChannelBuffer packetBuf = ChannelBuffers.wrappedBuffer(packet);
- List<OFMessage> msg = factory.parseMessage(packetBuf);
- TestCase.assertNotNull(msg);
- TestCase.assertEquals(msg.size(), 1);
- TestCase.assertTrue(msg.get(0) instanceof OFStatisticsReply);
- OFStatisticsReply sr = (OFStatisticsReply) msg.get(0);
- TestCase.assertEquals(OFStatisticsType.FLOW, sr.getStatisticType());
- TestCase.assertEquals(3, sr.getStatistics().size());
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.protocol.factory.BasicFactory;
-import org.openflow.protocol.factory.OFMessageFactory;
-import org.openflow.protocol.statistics.OFFlowStatisticsRequest;
-import org.openflow.protocol.statistics.OFStatisticsType;
-import org.openflow.protocol.statistics.OFVendorStatistics;
-import org.openflow.util.OFTestCase;
-
-public class OFStatisticsRequestTest extends OFTestCase {
- public void testOFFlowStatisticsRequest() throws Exception {
- byte[] packet = new byte[] { 0x01, 0x10, 0x00, 0x38, 0x00, 0x00, 0x00,
- 0x16, 0x00, 0x01, 0x00, 0x00, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- (byte) 0xff, 0x00, (byte) 0xff, (byte) 0xff };
-
- OFMessageFactory factory = new BasicFactory();
- ChannelBuffer packetBuf = ChannelBuffers.wrappedBuffer(packet);
- List<OFMessage> msg = factory.parseMessage(packetBuf);
- TestCase.assertNotNull(msg);
- TestCase.assertEquals(msg.size(), 1);
- TestCase.assertTrue(msg.get(0) instanceof OFStatisticsRequest);
- OFStatisticsRequest sr = (OFStatisticsRequest) msg.get(0);
- TestCase.assertEquals(OFStatisticsType.FLOW, sr.getStatisticType());
- TestCase.assertEquals(1, sr.getStatistics().size());
- TestCase.assertTrue(sr.getStatistics().get(0) instanceof OFFlowStatisticsRequest);
- }
-
- public void testOFStatisticsRequestVendor() throws Exception {
- byte[] packet = new byte[] { 0x01, 0x10, 0x00, 0x50, 0x00, 0x00, 0x00,
- 0x63, (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x4c, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x20,
- (byte) 0xe0, 0x00, 0x11, 0x00, 0x0c, 0x29, (byte) 0xc5,
- (byte) 0x95, 0x57, 0x02, 0x25, 0x5c, (byte) 0xca, 0x00, 0x02,
- (byte) 0xff, (byte) 0xff, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x50, 0x04,
- 0x00, 0x00, 0x00, 0x00, (byte) 0xff, 0x00, 0x00, 0x00,
- (byte) 0xff, (byte) 0xff, 0x4e, 0x20 };
-
- OFMessageFactory factory = new BasicFactory();
- ChannelBuffer packetBuf = ChannelBuffers.wrappedBuffer(packet);
- List<OFMessage> msg = factory.parseMessage(packetBuf);
- TestCase.assertNotNull(msg);
- TestCase.assertEquals(msg.size(), 1);
- TestCase.assertTrue(msg.get(0) instanceof OFStatisticsRequest);
- OFStatisticsRequest sr = (OFStatisticsRequest) msg.get(0);
- TestCase.assertEquals(OFStatisticsType.VENDOR, sr.getStatisticType());
- TestCase.assertEquals(1, sr.getStatistics().size());
- TestCase.assertTrue(sr.getStatistics().get(0) instanceof OFVendorStatistics);
- TestCase.assertEquals(68, ((OFVendorStatistics)sr.getStatistics().get(0)).getLength());
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-
-import junit.framework.TestCase;
-
-import org.junit.Test;
-import org.openflow.protocol.statistics.OFStatisticsType;
-
-
-public class OFStatisticsTypeTest extends TestCase {
- @Test
- public void testMapping() throws Exception {
- TestCase.assertEquals(OFStatisticsType.DESC,
- OFStatisticsType.valueOf((short) 0, OFType.STATS_REQUEST));
- TestCase.assertEquals(OFStatisticsType.QUEUE,
- OFStatisticsType.valueOf((short) 5, OFType.STATS_REQUEST));
- TestCase.assertEquals(OFStatisticsType.VENDOR,
- OFStatisticsType.valueOf((short) 0xffff, OFType.STATS_REQUEST));
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-
-import junit.framework.TestCase;
-
-import org.junit.Test;
-
-
-public class OFTypeTest extends TestCase {
-
- public void testOFTypeCreate() throws Exception {
- OFType foo = OFType.HELLO;
- Class<? extends OFMessage> c = foo.toClass();
- TestCase.assertEquals(c, OFHello.class);
- }
-
- @Test
- public void testMapping() throws Exception {
- TestCase.assertEquals(OFType.HELLO, OFType.valueOf((byte) 0));
- TestCase.assertEquals(OFType.BARRIER_REPLY, OFType.valueOf((byte) 19));
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.protocol;
-
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.openflow.protocol.factory.BasicFactory;
-import org.openflow.protocol.vendor.OFByteArrayVendorData;
-import org.openflow.protocol.vendor.OFBasicVendorDataType;
-import org.openflow.protocol.vendor.OFBasicVendorId;
-import org.openflow.protocol.vendor.OFVendorData;
-import org.openflow.protocol.vendor.OFVendorId;
-import org.openflow.util.OFTestCase;
-
-public class OFVendorTest extends OFTestCase {
-
- public static int ACME_VENDOR_ID = 0x00112233;
-
- static class AcmeVendorData implements OFVendorData {
- protected int dataType;
-
- public int getLength() {
- return 4;
- }
-
- public void readFrom(ChannelBuffer data, int length) {
- dataType = data.readInt();
- }
-
- public void writeTo(ChannelBuffer data) {
- data.writeInt(dataType);
- }
- }
-
- static class AcmeVendorData1 extends AcmeVendorData {
- public short flags;
- public short value;
-
- public static int DATA_TYPE = 1;
-
- public AcmeVendorData1() {
- }
-
- public AcmeVendorData1(short flags, short value) {
- this.dataType = DATA_TYPE;
- this.flags = flags;
- this.value = value;
- }
-
- public short getFlags() {
- return flags;
- }
-
- public short getValue() {
- return value;
- }
-
- public int getLength() {
- return 8;
- }
-
- public void readFrom(ChannelBuffer data, int length) {
- super.readFrom(data, length);
- flags = data.readShort();
- value = data.readShort();
-
- }
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeShort(flags);
- data.writeShort(value);
- }
-
- public static Instantiable<OFVendorData> getInstantiable() {
- return new Instantiable<OFVendorData>() {
- public OFVendorData instantiate() {
- return new AcmeVendorData1();
- }
- };
- }
- }
-
- static class AcmeVendorData2 extends AcmeVendorData {
- public int type;
- public int subtype;
-
- public static int DATA_TYPE = 2;
-
- public AcmeVendorData2() {
- }
-
- public AcmeVendorData2(int type, int subtype) {
- this.dataType = DATA_TYPE;
- this.type = type;
- this.subtype = subtype;
- }
-
- public int getType() {
- return type;
- }
-
- public int getSubtype() {
- return subtype;
- }
-
- public int getLength() {
- return 12;
- }
-
- public void readFrom(ChannelBuffer data, int length) {
- super.readFrom(data, length);
- type = data.readShort();
- subtype = data.readShort();
-
- }
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeShort(type);
- data.writeShort(subtype);
- }
-
- public static Instantiable<OFVendorData> getInstantiable() {
- return new Instantiable<OFVendorData>() {
- public OFVendorData instantiate() {
- return new AcmeVendorData2();
- }
- };
- }
- }
-
- {
- OFBasicVendorId acmeVendorId = new OFBasicVendorId(ACME_VENDOR_ID, 4);
- OFVendorId.registerVendorId(acmeVendorId);
- OFBasicVendorDataType acmeVendorData1 = new OFBasicVendorDataType(
- AcmeVendorData1.DATA_TYPE, AcmeVendorData1.getInstantiable());
- acmeVendorId.registerVendorDataType(acmeVendorData1);
- OFBasicVendorDataType acmeVendorData2 = new OFBasicVendorDataType(
- AcmeVendorData2.DATA_TYPE, AcmeVendorData2.getInstantiable());
- acmeVendorId.registerVendorDataType(acmeVendorData2);
- }
-
- private OFVendor makeVendorMessage(int vendor) {
- OFVendor msg = (OFVendor) messageFactory.getMessage(OFType.VENDOR);
- msg.setVendorDataFactory(new BasicFactory());
- msg.setVendor(vendor);
- return msg;
- }
-
- public void testWriteRead() throws Exception {
- OFVendor msg = makeVendorMessage(1);
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- bb.clear();
- msg.writeTo(bb);
- msg.readFrom(bb);
- TestCase.assertEquals(1, msg.getVendor());
- }
-
- public void testVendorData() throws Exception {
- OFVendor msg = makeVendorMessage(ACME_VENDOR_ID);
- OFVendorData vendorData = new AcmeVendorData1((short)11, (short)22);
- msg.setVendorData(vendorData);
- msg.setLengthU(OFVendor.MINIMUM_LENGTH + vendorData.getLength());
- ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
- bb.clear();
- msg.writeTo(bb);
- msg.readFrom(bb);
- assertEquals(ACME_VENDOR_ID, msg.getVendor());
- AcmeVendorData1 vendorData1 = (AcmeVendorData1) msg.getVendorData();
- assertEquals(11, vendorData1.getFlags());
- assertEquals(22, vendorData1.getValue());
-
- vendorData = new AcmeVendorData2(33, 44);
- msg.setVendorData(vendorData);
- msg.setLengthU(OFVendor.MINIMUM_LENGTH + vendorData.getLength());
- bb.clear();
- msg.writeTo(bb);
- msg.readFrom(bb);
- assertEquals(ACME_VENDOR_ID, msg.getVendor());
- AcmeVendorData2 vendorData2 = (AcmeVendorData2) msg.getVendorData();
- assertEquals(33, vendorData2.getType());
- assertEquals(44, vendorData2.getSubtype());
-
- final int DUMMY_VENDOR_ID = 55;
- msg.setVendor(DUMMY_VENDOR_ID);
- byte[] genericVendorDataBytes = new byte[] {0x55, 0x66};
- vendorData = new OFByteArrayVendorData(genericVendorDataBytes);
- msg.setVendorData(vendorData);
- msg.setLengthU(OFVendor.MINIMUM_LENGTH + vendorData.getLength());
- bb.clear();
- msg.writeTo(bb);
- msg.readFrom(bb);
- assertEquals(DUMMY_VENDOR_ID, msg.getVendor());
- OFByteArrayVendorData genericVendorData = (OFByteArrayVendorData) msg.getVendorData();
- assertTrue(Arrays.equals(genericVendorDataBytes, genericVendorData.getBytes()));
- }
-}
+++ /dev/null
-package org.openflow.protocol;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.EnumSet;
-
-import org.junit.Test;
-import org.openflow.protocol.Wildcards.Flag;
-
-public class WildcardsTest {
-
- @Test
- public void testBasic() {
- int[] intMasks = { 0, 0x3820e0, OFMatch.OFPFW_ALL_SANITIZED };
- for (int i : intMasks) {
- Wildcards w = Wildcards.of(i);
- assertEquals(i, w.getInt());
- }
- }
-
- @Test
- public void testAllSanitize() {
- Wildcards w = Wildcards.of(OFMatch.OFPFW_ALL);
- assertEquals(OFMatch.OFPFW_ALL_SANITIZED, w.getInt());
- assertTrue(w.isFull());
- assertFalse(w.isExact());
- }
-
- @Test
- public void testAll() {
- Wildcards all = Wildcards.FULL;
- assertTrue(all.isFull());
- assertFalse(all.isExact());
- assertEquals(0, all.getNwDstMask());
- assertEquals(0, all.getNwSrcMask());
-
- // unsetting flags from NONE is a no-op
- Wildcards stillAll = all.wildcard(Flag.IN_PORT);
- assertTrue(stillAll.isFull());
- assertEquals(all, stillAll);
-
- // so is setting a >= 32 netmask
-
- stillAll = all.withNwSrcMask(0);
- assertTrue(stillAll.isFull());
- assertEquals(all, stillAll);
-
- stillAll = all.withNwDstMask(0);
- assertTrue(stillAll.isFull());
- assertEquals(all, stillAll);
- }
-
- @Test
- public void testNone() {
- Wildcards none = Wildcards.EXACT;
- assertTrue(none.isExact());
- assertEquals(32, none.getNwDstMask());
- assertEquals(32, none.getNwSrcMask());
-
- // unsetting flags from NONE is a no-op
- Wildcards stillNone = none.matchOn(Flag.IN_PORT);
- assertTrue(stillNone.isExact());
- assertEquals(none, stillNone);
-
- // so is setting a >= 32 netmask
- stillNone = none.withNwSrcMask(32);
- assertTrue(stillNone.isExact());
- assertEquals(none, stillNone);
-
- stillNone = none.withNwDstMask(32);
- assertTrue(stillNone.isExact());
- assertEquals(none, stillNone);
- }
-
- @Test
- public void testSetOneFlag() {
- Wildcards none = Wildcards.EXACT;
- assertTrue(none.isExact());
- assertFalse(none.isWildcarded(Flag.DL_SRC));
- Wildcards one = none.wildcard(Flag.DL_SRC);
- assertFalse(one.isExact());
- assertTrue(one.isWildcarded(Flag.DL_SRC));
- assertEquals(OFMatch.OFPFW_DL_SRC, one.getInt());
- assertEquals(EnumSet.of(Flag.DL_SRC), one.getWildcardedFlags());
- }
-
- @Test
- public void testSetTwoFlags() {
- Wildcards none = Wildcards.EXACT;
-
- // set two flags
- Wildcards two = none.wildcard(Flag.DL_SRC, Flag.DL_DST);
- assertFalse(two.isExact());
- assertTrue(two.isWildcarded(Flag.DL_SRC));
- assertTrue(two.isWildcarded(Flag.DL_DST));
- assertEquals(OFMatch.OFPFW_DL_SRC | OFMatch.OFPFW_DL_DST, two.getInt());
- assertEquals(EnumSet.of(Flag.DL_SRC, Flag.DL_DST), two.getWildcardedFlags());
-
- // unset dl_dst
- Wildcards gone = two.matchOn(Flag.DL_DST);
- assertFalse(gone.isExact());
- assertTrue(gone.isWildcarded(Flag.DL_SRC));
- assertFalse(gone.isWildcarded(Flag.DL_DST));
- assertEquals(OFMatch.OFPFW_DL_SRC, gone.getInt());
- assertEquals(EnumSet.of(Flag.DL_SRC), gone.getWildcardedFlags());
- }
-
- @Test
- public void testSetNwSrc() {
- Wildcards none = Wildcards.EXACT;
- assertEquals(32, none.getNwSrcMask());
-
- // unsetting flags from NONE is a no-op
- Wildcards nwSet = none.withNwSrcMask(8);
- assertFalse(nwSet.isExact());
- assertEquals(EnumSet.noneOf(Flag.class), nwSet.getWildcardedFlags());
- assertEquals(8, nwSet.getNwSrcMask());
- assertEquals((32 - 8) << OFMatch.OFPFW_NW_SRC_SHIFT, nwSet.getInt());
- }
-
- @Test
- public void testSetNwDst() {
- Wildcards none = Wildcards.EXACT;
- assertEquals(32, none.getNwDstMask());
-
- // unsetting flags from NONE is a no-op
- Wildcards nwSet = none.withNwDstMask(8);
- assertFalse(nwSet.isExact());
- assertEquals(EnumSet.noneOf(Flag.class), nwSet.getWildcardedFlags());
- assertEquals(8, nwSet.getNwDstMask());
- assertEquals((32 - 8) << OFMatch.OFPFW_NW_DST_SHIFT, nwSet.getInt());
- }
-
- @Test
- public void testToString() {
- String s = Wildcards.FULL.toString();
- assertNotNull(s);
- assertTrue(s.length() > 0);
- }
-
- @Test
- public void testInvert() {
- assertEquals(Wildcards.FULL, Wildcards.EXACT.inverted());
-
- Wildcards some = Wildcards.of(Flag.DL_VLAN, Flag.DL_VLAN_PCP);
- Wildcards inv = some.inverted();
-
- for(Flag f : Flag.values()) {
- boolean shouldBeSet = (f == Flag.DL_VLAN || f == Flag.DL_VLAN_PCP);
-
- assertEquals("Flag " + f + " "
- + (shouldBeSet ? "should be set " : "should not be set"),
- shouldBeSet, some.isWildcarded(f));
- assertEquals(!(f == Flag.DL_VLAN || f == Flag.DL_VLAN_PCP), inv.isWildcarded(f));
- }
- assertEquals(0, inv.getNwDstMask());
- assertEquals(0, inv.getNwSrcMask());
- }
-}
+++ /dev/null
-package org.openflow.protocol.action;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-
-public class MockVendorAction extends OFActionVendor {
- public static final int VENDOR_ID = 0xdeadbeef;
-
- private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
- private byte[] mockData;
-
- public byte[] getMockData() {
- return mockData;
- }
-
- public void setMockData(byte[] mockData) {
- this.mockData = mockData;
- }
-
- @Override
- public void readFrom(ChannelBuffer data) {
- super.readFrom(data);
-
- int dataLength = getLength() - MINIMUM_LENGTH;
- if(dataLength > 0) {
- mockData = new byte[dataLength];
- data.readBytes(mockData);
- } else {
- mockData = EMPTY_BYTE_ARRAY;
- }
-
- }
-
- @Override
- public void writeTo(ChannelBuffer data) {
- super.writeTo(data);
- data.writeBytes(mockData);
- }
-
-
-}
+++ /dev/null
-package org.openflow.protocol.action;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.openflow.protocol.factory.OFVendorActionFactory;
-
-public class MockVendorActionFactory implements OFVendorActionFactory {
-
- @Override
- public OFActionVendor readFrom(ChannelBuffer data) {
- MockVendorAction action = new MockVendorAction();
- action.readFrom(data);
- return action;
- }
-
-}
+++ /dev/null
-package org.openflow.protocol.action;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-import org.openflow.protocol.factory.OFVendorActionRegistry;
-
-public class OFVendorActionRegistryTest {
-
- @Test
- public void test() {
- MockVendorActionFactory factory = new MockVendorActionFactory();
- OFVendorActionRegistry.getInstance().register(MockVendorAction.VENDOR_ID, factory);
- assertEquals(factory, OFVendorActionRegistry.getInstance().get(MockVendorAction.VENDOR_ID));
- }
-
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-import org.junit.Test;
-
-import junit.framework.TestCase;
-
-/**
- * Does hexstring conversion work?
- *
- * @author Rob Sherwood (rob.sherwood@stanford.edu)
- *
- */
-
-public class HexStringTest extends TestCase {
-
- @Test
- public void testMarshalling() throws Exception {
- String dpidStr = "00:00:00:23:20:2d:16:71";
- long dpid = HexString.toLong(dpidStr);
- String testStr = HexString.toHexString(dpid);
- TestCase.assertEquals(dpidStr, testStr);
- }
-
- @Test
- public void testToLong() {
- String dpidStr = "3e:1f:01:fc:72:8c:63:31";
- long valid = 0x3e1f01fc728c6331L;
- long testLong = HexString.toLong(dpidStr);
- TestCase.assertEquals(valid, testLong);
- }
-
- @Test
- public void testToLongMSB() {
- String dpidStr = "ca:7c:5e:d1:64:7a:95:9b";
- long valid = -3856102927509056101L;
- long testLong = HexString.toLong(dpidStr);
- TestCase.assertEquals(valid, testLong);
- }
-
- @Test
- public void testToLongError() {
- String dpidStr = "09:08:07:06:05:04:03:02:01";
- try {
- HexString.toLong(dpidStr);
- fail("HexString.toLong() should have thrown a NumberFormatException");
- }
- catch (NumberFormatException expected) {
- // do nothing
- }
- }
-
- @Test
- public void testToStringBytes() {
- byte[] dpid = { 0, 0, 0, 0, 0, 0, 0, -1 };
- String valid = "00:00:00:00:00:00:00:ff";
- String testString = HexString.toHexString(dpid);
- TestCase.assertEquals(valid, testString);
- }
-
- @Test
- public void testFromHexStringError() {
- String invalidStr = "00:00:00:00:00:00:ffff";
- try {
- HexString.fromHexString(invalidStr);
- fail("HexString.fromHexString() should have thrown a NumberFormatException");
- }
- catch (NumberFormatException expected) {
- // do nothing
- }
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-import org.openflow.protocol.factory.BasicFactory;
-import org.openflow.protocol.factory.OFMessageFactory;
-
-import junit.framework.TestCase;
-
-public class OFTestCase extends TestCase {
- public OFMessageFactory messageFactory;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- messageFactory = new BasicFactory();
- }
-
- public void test() throws Exception {
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-import junit.framework.TestCase;
-
-public class U16Test extends TestCase {
- /**
- * Tests that we correctly translate unsigned values in and out of a short
- * @throws Exception
- */
- public void test() throws Exception {
- int val = 0xffff;
- TestCase.assertEquals((short)-1, U16.t(val));
- TestCase.assertEquals((short)32767, U16.t(0x7fff));
- TestCase.assertEquals(val, U16.f((short)-1));
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-import junit.framework.TestCase;
-
-public class U32Test extends TestCase {
- /**
- * Tests that we correctly translate unsigned values in and out of an int
- * @throws Exception
- */
- public void test() throws Exception {
- long val = 0xffffffffL;
- TestCase.assertEquals(-1, U32.t(val));
- TestCase.assertEquals(val, U32.f(-1));
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-import java.math.BigInteger;
-
-import junit.framework.TestCase;
-
-public class U64Test extends TestCase {
- /**
- * Tests that we correctly translate unsigned values in and out of a long
- * @throws Exception
- */
- public void test() throws Exception {
- BigInteger val = new BigInteger("ffffffffffffffff", 16);
- TestCase.assertEquals(-1, U64.t(val));
- TestCase.assertEquals(val, U64.f(-1));
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-import junit.framework.TestCase;
-
-public class U8Test extends TestCase {
- /**
- * Tests that we correctly translate unsigned values in and out of a byte
- * @throws Exception
- */
- public void test() throws Exception {
- short val = 0xff;
- TestCase.assertEquals(-1, U8.t(val));
- TestCase.assertEquals(val, U8.f((byte)-1));
- }
-}
+++ /dev/null
-/**
-* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
-* University
-*
-* Licensed under the Apache License, Version 2.0 (the "License"); you may
-* not use this file except in compliance with the License. You may obtain
-* a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-* License for the specific language governing permissions and limitations
-* under the License.
-**/
-
-package org.openflow.util;
-
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-
-import junit.framework.TestCase;
-
-public class UnsignedTest extends TestCase {
- public static String ULONG_MAX = "18446744073709551615";
-
- /**
- * Tests that we correctly extract an unsigned long into a BigInteger
- * @throws Exception
- */
- public void testGetUnsignedLong() throws Exception {
- ByteBuffer bb = ByteBuffer.allocate(8);
- bb.put((byte)0xff).put((byte)0xff).put((byte)0xff).put((byte)0xff);
- bb.put((byte)0xff).put((byte)0xff).put((byte)0xff).put((byte)0xff);
- bb.position(0);
- bb.limit(8);
- BigInteger bi = Unsigned.getUnsignedLong(bb);
- BigInteger uLongMax = new BigInteger(ULONG_MAX);
- for (int i = 0; i < uLongMax.bitCount(); ++i) {
- TestCase.assertTrue("Bit: " + i + " should be: " + uLongMax.testBit(i),
- uLongMax.testBit(i) == bi.testBit(i));
- }
- TestCase.assertEquals(ULONG_MAX, bi.toString());
-
- bb = ByteBuffer.allocate(10);
- bb.put((byte)0x00);
- bb.put((byte)0xff).put((byte)0xff).put((byte)0xff).put((byte)0xff);
- bb.put((byte)0xff).put((byte)0xff).put((byte)0xff).put((byte)0xff);
- bb.put((byte)0x00);
- bb.position(0);
- bb.limit(10);
- bi = Unsigned.getUnsignedLong(bb, 1);
- uLongMax = new BigInteger(ULONG_MAX);
- for (int i = 0; i < uLongMax.bitCount(); ++i) {
- TestCase.assertTrue("Bit: " + i + " should be: " + uLongMax.testBit(i),
- uLongMax.testBit(i) == bi.testBit(i));
- }
- TestCase.assertEquals(ULONG_MAX, bi.toString());
- }
-
- /**
- * Tests that we correctly put an unsigned long into a ByteBuffer
- * @throws Exception
- */
- public void testPutUnsignedLong() throws Exception {
- ByteBuffer bb = ByteBuffer.allocate(8);
- BigInteger uLongMax = new BigInteger(ULONG_MAX);
- Unsigned.putUnsignedLong(bb, uLongMax);
- for (int i = 0; i < 8; ++i) {
- TestCase.assertTrue("Byte: " + i + " should be 0xff, was: " + bb.get(i),
- (bb.get(i) & (short)0xff) == 0xff);
- }
-
- bb = ByteBuffer.allocate(10);
- Unsigned.putUnsignedLong(bb, uLongMax, 1);
- int offset = 1;
- for (int i = 0; i < 8; ++i) {
- TestCase.assertTrue("Byte: " + i + " should be 0xff, was: " +
- bb.get(offset+i), (bb.get(offset+i) & (short)0xff) == 0xff);
- }
- }
-}