grouping match-v10-grouping {
container match-v10 {
leaf wildcards {
- type uint32;
+ type oft:flow-wildcards-v10;
+ }
+ leaf nw-src-mask {
+ type uint8;
+ }
+ leaf nw-dst-mask {
+ type uint8;
}
leaf in-port {
type uint16;
// reference "ofp_port.peer"; \r
type oft:port-features; \r
}\r
- leaf curr_speed { \r
+ leaf curr-speed { \r
description "Current port bitrate in kbps.";\r
// reference "ofp_port.curr_speed"; \r
type uint32; \r
units "kbps";\r
}\r
- leaf max_speed { \r
+ leaf max-speed { \r
description "Max port bitrate in kbps";\r
// reference "ofp_port.max_speed"; \r
type uint32;\r
leaf actions-v10 {\r
type oft:action-type-v10;\r
}\r
- uses port;\r
+ list phy-port {\r
+ uses port;\r
+ }\r
}\r
grouping get-config-request {\r
// reference "OFPT_GET_CONFIG_REQUEST message in Openflow Switch 1.3 Spec"\r
}
}
+ typedef flow-wildcards-v10 {
+ /* ofp_flow_wildcards */
+ type bits {
+ bit IN_PORT {
+ position 0;
+ /* Switch input port. */
+ }
+ bit DL_VLAN {
+ position 1;
+ /* Switch input port. */
+ }
+ bit DL_SRC {
+ position 2;
+ /* Switch input port. */
+ }
+ bit DL_DST {
+ position 3;
+ /* Switch input port. */
+ }
+ bit DL_TYPE {
+ position 4;
+ /* Switch input port. */
+ }
+ bit NW_PROTO {
+ position 5;
+ /* Switch input port. */
+ }
+ bit TP_SRC {
+ position 6;
+ /* Switch input port. */
+ }
+ bit TP_DST {
+ position 7;
+ /* Switch input port. */
+ }
+ bit DL_VLAN_PCP {
+ position 20;
+ /* Switch input port. */
+ }
+ bit NW_TOS {
+ position 21;
+ /* Switch input port. */
+ }
+ bit ALL {
+ position 22;
+ /* Switch input port. */
+ }
+ }
+ }
+
}
\r
private static final String UNKNOWN_CODE = "UNKNOWN_CODE";\r
private static final String UNKNOWN_TYPE = "UNKNOWN_TYPE";\r
- private static final int NO_CORRECT_ENUM_FOUND_VALUE = -1;\r
\r
private static ErrorMessageFactory instance;\r
\r
ErrorMessageBuilder builder = new ErrorMessageBuilder();\r
builder.setVersion(version);\r
builder.setXid(rawMessage.readUnsignedInt());\r
- ErrorType type = ErrorType.forValue(rawMessage.readUnsignedShort());\r
- decodeType(builder, type);\r
- decodeCode(rawMessage, builder, type);\r
+ int type = rawMessage.readUnsignedShort();\r
+ ErrorType errorType = ErrorType.forValue(type);\r
+ decodeType(builder, errorType, type);\r
+ decodeCode(rawMessage, builder, errorType);\r
if (rawMessage.readableBytes() > 0) {\r
builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array());\r
}\r
return builder.build();\r
}\r
+ \r
+ private static void decodeType(ErrorMessageBuilder builder, ErrorType type, int readValue) {\r
+ if (type != null) {\r
+ builder.setType(type.getIntValue());\r
+ builder.setTypeString(type.name());\r
+ } else {\r
+ builder.setType(readValue);\r
+ builder.setTypeString(UNKNOWN_TYPE);\r
+ }\r
+ }\r
\r
private static void decodeCode(ByteBuf rawMessage, ErrorMessageBuilder builder,\r
ErrorType type) {\r
- \r
- switch (type) {\r
- case HELLOFAILED:\r
- {\r
- HelloFailedCode code = HelloFailedCode.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
+ int code = rawMessage.readUnsignedShort();\r
+ if (type != null) {\r
+ switch (type) {\r
+ case HELLOFAILED:\r
+ {\r
+ HelloFailedCode errorCode = HelloFailedCode.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
}\r
- break;\r
- }\r
- case BADREQUEST:\r
- {\r
- BadRequestCode code = BadRequestCode.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
+ case BADREQUEST:\r
+ {\r
+ BadRequestCode errorCode = BadRequestCode.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
}\r
- break;\r
- }\r
- case BADACTION:\r
- {\r
- BadActionCode code = BadActionCode.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
+ case BADACTION:\r
+ {\r
+ BadActionCode errorCode = BadActionCode.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
}\r
- break;\r
- }\r
- case BADINSTRUCTION:\r
- {\r
- BadInstructionCode code = BadInstructionCode.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
+ case BADINSTRUCTION:\r
+ {\r
+ BadInstructionCode errorCode = BadInstructionCode.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
}\r
- break;\r
- }\r
- case BADMATCH:\r
- {\r
- BadMatchCode code = BadMatchCode.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
+ case BADMATCH:\r
+ {\r
+ BadMatchCode errorCode = BadMatchCode.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
}\r
- break;\r
- }\r
- case FLOWMODFAILED:\r
- {\r
- FlowModFailedCode code = FlowModFailedCode.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
+ case FLOWMODFAILED:\r
+ {\r
+ FlowModFailedCode errorCode = FlowModFailedCode.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
}\r
- break;\r
- }\r
- case GROUPMODFAILED:\r
- {\r
- GroupModFailedCode code = GroupModFailedCode.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
+ case GROUPMODFAILED:\r
+ {\r
+ GroupModFailedCode errorCode = GroupModFailedCode.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
}\r
- break;\r
- }\r
- case PORTMODFAILED:\r
- {\r
- PortModFailedCode code = PortModFailedCode.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
+ case PORTMODFAILED:\r
+ {\r
+ PortModFailedCode errorCode = PortModFailedCode.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
}\r
- break;\r
- }\r
- case TABLEMODFAILED:\r
- {\r
- TableModFailedCode code = TableModFailedCode.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
+ case TABLEMODFAILED:\r
+ {\r
+ TableModFailedCode errorCode = TableModFailedCode.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
}\r
- break;\r
- }\r
- case QUEUEOPFAILED:\r
- {\r
- QueueOpFailedCode code = QueueOpFailedCode.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
+ case QUEUEOPFAILED:\r
+ {\r
+ QueueOpFailedCode errorCode = QueueOpFailedCode.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
}\r
- break;\r
- }\r
- case SWITCHCONFIGFAILED:\r
- {\r
- SwitchConfigFailedCode code = SwitchConfigFailedCode.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
+ case SWITCHCONFIGFAILED:\r
+ {\r
+ SwitchConfigFailedCode errorCode = SwitchConfigFailedCode.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
}\r
- break;\r
- }\r
- case ROLEREQUESTFAILED:\r
- {\r
- RoleRequestFailedCode code = RoleRequestFailedCode.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
+ case ROLEREQUESTFAILED:\r
+ {\r
+ RoleRequestFailedCode errorCode = RoleRequestFailedCode.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
}\r
- break;\r
- }\r
- case METERMODFAILED:\r
- {\r
- MeterModFailedCode code = MeterModFailedCode.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
+ case METERMODFAILED:\r
+ {\r
+ MeterModFailedCode errorCode = MeterModFailedCode.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
}\r
- break;\r
- }\r
- case TABLEFEATURESFAILED:\r
- {\r
- TableFeaturesFailedCode code = TableFeaturesFailedCode.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
+ case TABLEFEATURESFAILED:\r
+ {\r
+ TableFeaturesFailedCode errorCode = TableFeaturesFailedCode.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
+ }\r
+ case EXPERIMENTER:\r
+ ExperimenterErrorBuilder expBuilder = new ExperimenterErrorBuilder();\r
+ expBuilder.setExpType(code);\r
+ expBuilder.setExperimenter(rawMessage.readUnsignedInt());\r
+ builder.addAugmentation(ExperimenterError.class, expBuilder.build());\r
+ break;\r
+ default:\r
+ setUnknownCode(builder, code);\r
+ break;\r
}\r
- break;\r
- }\r
- case EXPERIMENTER:\r
- ExperimenterErrorBuilder expBuilder = new ExperimenterErrorBuilder();\r
- expBuilder.setExpType(rawMessage.readUnsignedShort());\r
- expBuilder.setExperimenter(rawMessage.readUnsignedInt());\r
- builder.addAugmentation(ExperimenterError.class, expBuilder.build());\r
- break;\r
- default:\r
- builder.setCode(NO_CORRECT_ENUM_FOUND_VALUE);\r
- builder.setCodeString(UNKNOWN_CODE);\r
- break;\r
- }\r
- }\r
-\r
- private static void decodeType(ErrorMessageBuilder builder, ErrorType type) {\r
- if (type != null) {\r
- builder.setType(type.getIntValue());\r
- builder.setTypeString(type.name());\r
} else {\r
- builder.setType(NO_CORRECT_ENUM_FOUND_VALUE);\r
- builder.setTypeString(UNKNOWN_TYPE);\r
+ setUnknownCode(builder, code);\r
}\r
}\r
+ \r
+ private static void setUnknownCode(ErrorMessageBuilder builder, int readValue) {\r
+ builder.setCode(readValue);\r
+ builder.setCodeString(UNKNOWN_CODE);\r
+ }\r
+ \r
+ private static void setCode(ErrorMessageBuilder builder, int code, String codeString) {\r
+ builder.setCode(code);\r
+ builder.setCodeString(codeString);\r
+ }\r
\r
}\r
*/\r
public class OF10ErrorMessageFactory implements OFDeserializer<ErrorMessage> {\r
\r
- private static final String UNKNOWN_TYPE = "UNKNOWN_TYPE";\r
+ private static final String UNKNOWN_TYPE = "UNKNOWN_TYPE";\r
private static final String UNKNOWN_CODE = "UNKNOWN_CODE";\r
- private static final int NO_CORRECT_ENUM_FOUND_VALUE = -1;\r
\r
private static OF10ErrorMessageFactory instance;\r
\r
ErrorMessageBuilder builder = new ErrorMessageBuilder();\r
builder.setVersion(version);\r
builder.setXid(rawMessage.readUnsignedInt());\r
- ErrorTypeV10 type = ErrorTypeV10.forValue(rawMessage.readUnsignedShort());\r
- decodeType(builder, type);\r
- decodeCode(rawMessage, builder, type);\r
+ int type = rawMessage.readUnsignedShort();\r
+ ErrorTypeV10 errorType = ErrorTypeV10.forValue(type);\r
+ decodeType(builder, errorType, type);\r
+ decodeCode(rawMessage, builder, errorType);\r
if (rawMessage.readableBytes() > 0) {\r
builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array());\r
}\r
return builder.build();\r
}\r
-\r
- private static void decodeCode(ByteBuf rawMessage, ErrorMessageBuilder builder,\r
- ErrorTypeV10 type) {\r
- switch (type) {\r
- case HELLOFAILED:\r
- {\r
- HelloFailedCodeV10 code = HelloFailedCodeV10.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
- }\r
- break;\r
- }\r
- case BADREQUEST:\r
- {\r
- BadRequestCodeV10 code = BadRequestCodeV10.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
- }\r
- break;\r
- }\r
- case BADACTION:\r
- {\r
- BadActionCodeV10 code = BadActionCodeV10.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
- }\r
- break;\r
- }\r
- case FLOWMODFAILED:\r
- {\r
- FlowModFailedCodeV10 code = FlowModFailedCodeV10.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
- }\r
- break;\r
- }\r
- case PORTMODFAILED:\r
- {\r
- PortModFailedCodeV10 code = PortModFailedCodeV10.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
- }\r
- break;\r
- }\r
- case QUEUEOPFAILED:\r
- {\r
- QueueOpFailedCodeV10 code = QueueOpFailedCodeV10.forValue(rawMessage.readUnsignedShort());\r
- if (code != null) {\r
- builder.setCode(code.getIntValue());\r
- builder.setCodeString(code.name());\r
- }\r
- break;\r
- }\r
- default:\r
- builder.setCode(NO_CORRECT_ENUM_FOUND_VALUE);\r
- builder.setCodeString(UNKNOWN_CODE);\r
- break;\r
- }\r
- }\r
-\r
- private static void decodeType(ErrorMessageBuilder builder, ErrorTypeV10 type) {\r
+ \r
+ private static void decodeType(ErrorMessageBuilder builder, ErrorTypeV10 type, int readValue) {\r
if (type != null) {\r
builder.setType(type.getIntValue());\r
builder.setTypeString(type.name());\r
} else {\r
- builder.setType(NO_CORRECT_ENUM_FOUND_VALUE);\r
+ builder.setType(readValue);\r
builder.setTypeString(UNKNOWN_TYPE);\r
}\r
}\r
\r
+ private static void decodeCode(ByteBuf rawMessage, ErrorMessageBuilder builder,\r
+ ErrorTypeV10 type) {\r
+ int code = rawMessage.readUnsignedShort();\r
+ if (type != null) {\r
+ switch (type) {\r
+ case HELLOFAILED:\r
+ {\r
+ HelloFailedCodeV10 errorCode = HelloFailedCodeV10.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
+ }\r
+ case BADREQUEST:\r
+ {\r
+ BadRequestCodeV10 errorCode = BadRequestCodeV10.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
+ }\r
+ case BADACTION:\r
+ {\r
+ BadActionCodeV10 errorCode = BadActionCodeV10.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
+ }\r
+ case FLOWMODFAILED:\r
+ {\r
+ FlowModFailedCodeV10 errorCode = FlowModFailedCodeV10.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
+ }\r
+ case PORTMODFAILED:\r
+ {\r
+ PortModFailedCodeV10 errorCode = PortModFailedCodeV10.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
+ }\r
+ case QUEUEOPFAILED:\r
+ {\r
+ QueueOpFailedCodeV10 errorCode = QueueOpFailedCodeV10.forValue(code);\r
+ if (errorCode != null) {\r
+ setCode(builder, errorCode.getIntValue(), errorCode.name());\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ break;\r
+ }\r
+ default:\r
+ setUnknownCode(builder, code);\r
+ break;\r
+ }\r
+ } else {\r
+ setUnknownCode(builder, code);\r
+ }\r
+ }\r
+ \r
+ private static void setUnknownCode(ErrorMessageBuilder builder, int readValue) {\r
+ builder.setCode(readValue);\r
+ builder.setCodeString(UNKNOWN_CODE);\r
+ }\r
+ \r
+ private static void setCode(ErrorMessageBuilder builder, int code, String codeString) {\r
+ builder.setCode(code);\r
+ builder.setCodeString(codeString);\r
+ }\r
+\r
}\r
import io.netty.buffer.ByteBuf;\r
\r
import java.math.BigInteger;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
\r
import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder;\r
\r
/**\r
* Translates FeaturesReply messages (OpenFlow v1.0)\r
*/\r
public class OF10FeaturesReplyMessageFactory implements OFDeserializer<GetFeaturesOutput> {\r
\r
- private static final byte MAX_PORT_NAME_LENGTH = 16;\r
- \r
private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 3;\r
\r
private static OF10FeaturesReplyMessageFactory instance;\r
rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER);\r
builder.setCapabilitiesV10(createCapabilitiesV10(rawMessage.readUnsignedInt()));\r
builder.setActionsV10(createActionsV10(rawMessage.readUnsignedInt()));\r
- deserializePort(rawMessage, builder);\r
+ List<PhyPort> ports = new ArrayList<>();\r
+ while (rawMessage.readableBytes() > 0) {\r
+ ports.add(deserializePort(rawMessage));\r
+ }\r
+ builder.setPhyPort(ports);\r
return builder.build();\r
}\r
\r
SET_VLAN_PCP, SET_VLAN_VID, STRIP_VLAN, VENDOR);\r
}\r
\r
- private static void deserializePort(ByteBuf rawMessage, GetFeaturesOutputBuilder builder) {\r
+ private static PhyPort deserializePort(ByteBuf rawMessage) {\r
+ PhyPortBuilder builder = new PhyPortBuilder();\r
builder.setPortNo((long) rawMessage.readUnsignedShort());\r
byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];\r
rawMessage.readBytes(address);\r
builder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(address)));\r
- byte[] name = new byte[MAX_PORT_NAME_LENGTH];\r
- rawMessage.readBytes(name);\r
- builder.setName(name.toString());\r
+ builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH));\r
builder.setConfigV10(createPortConfig(rawMessage.readUnsignedInt()));\r
builder.setStateV10(createPortState(rawMessage.readUnsignedInt()));\r
builder.setCurrentFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));\r
builder.setAdvertisedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));\r
builder.setSupportedFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));\r
builder.setPeerFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));\r
+ return builder.build();\r
}\r
+\r
+ \r
\r
private static PortStateV10 createPortState(long input){\r
final Boolean _linkDown = ((input) & (1<<0)) != 0;\r
public class OF10PortStatusMessageFactory implements OFDeserializer<PortStatusMessage> {\r
\r
private static final byte PADDING_IN_PORT_STATUS_HEADER = 7;\r
- private static final int MAX_PORT_NAME_LENGTH = 16;\r
\r
private static OF10PortStatusMessageFactory instance;\r
\r
byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];\r
rawMessage.readBytes(address);\r
builder.setHwAddr(new MacAddress(ByteBufUtils.macAddressToString(address)));\r
- byte[] name = new byte[MAX_PORT_NAME_LENGTH];\r
- rawMessage.readBytes(name);\r
- builder.setName(name.toString());\r
+ builder.setName(ByteBufUtils.decodeNullTerminatedString(rawMessage, EncodeConstants.MAX_PORT_NAME_LENGTH));\r
builder.setConfigV10(createPortConfig(rawMessage.readUnsignedInt()));\r
builder.setStateV10(createPortState(rawMessage.readUnsignedInt()));\r
builder.setCurrentFeaturesV10(createPortFeatures(rawMessage.readUnsignedInt()));\r
private static final byte PADDING_IN_PACKET_QUEUE_HEADER = 2;\r
private static final byte PADDING_IN_QUEUE_PROPERTY_HEADER = 4;\r
private static final byte PADDING_IN_RATE_QUEUE_PROPERTY = 6;\r
- private static final byte PACKET_QUEUE_LENGTH = 16;\r
+ private static final byte PACKET_QUEUE_HEADER_LENGTH = 8;\r
\r
private static OF10QueueGetConfigReplyMessageFactory instance;\r
\r
queueBuilder.setQueueId(new QueueId(input.readUnsignedInt()));\r
int length = input.readUnsignedShort();\r
input.skipBytes(PADDING_IN_PACKET_QUEUE_HEADER);\r
- queueBuilder.setQueueProperty(createPropertiesList(input, length - PACKET_QUEUE_LENGTH));\r
+ queueBuilder.setQueueProperty(createPropertiesList(input, length - PACKET_QUEUE_HEADER_LENGTH));\r
queuesList.add(queueBuilder.build());\r
} \r
return queuesList;\r
public void messageToBuffer(short version, ByteBuf out, PortModInput message) {\r
ByteBufUtils.writeOFHeader(instance, message, out);\r
out.writeShort(message.getPortNo().getValue().intValue());\r
- out.writeBytes(ByteBufUtils.hexStringToBytes(message.getHwAddress().getValue(), false));\r
+ out.writeBytes(ByteBufUtils.macAddressToBytes(message.getHwAddress().getValue()));\r
out.writeInt(createPortConfigBitmask(message.getConfigV10()));\r
out.writeInt(createPortConfigBitmask(message.getMaskV10()));\r
out.writeInt(createPortFeaturesBitmask(message.getAdvertiseV10()));\r
import io.netty.buffer.UnpooledByteBufAllocator;\r
\r
import java.util.ArrayList;\r
+import java.util.Arrays;\r
import java.util.List;\r
import java.util.Map;\r
import java.util.Map.Entry;\r
Joiner joiner = Joiner.on(":");\r
return joiner.join(groups); \r
}\r
+ \r
+ /**\r
+ * Reads and parses port name from ByteBuf\r
+ * @param rawMessage\r
+ * @param length maximal length of String\r
+ * @return String with name of port\r
+ */\r
+ public static String decodeNullTerminatedString(ByteBuf rawMessage, int length) {\r
+ byte[] name = new byte[EncodeConstants.MAX_PORT_NAME_LENGTH];\r
+ rawMessage.readBytes(name);\r
+ int index = 0;\r
+ for (int i = 0; i < name.length; i++) {\r
+ if (name[i] != 0) {\r
+ index++;\r
+ } else {\r
+ break;\r
+ }\r
+ }\r
+ byte[] correctName = Arrays.copyOf(name, index);\r
+ return new String(correctName);\r
+ }\r
}\r
/** Length of byte in bytes */\r
public static final byte SIZE_OF_BYTE_IN_BYTES = Byte.SIZE / Byte.SIZE;\r
\r
+ \r
+ /** OF v1.0 maximal port name length */\r
+ public static final byte MAX_PORT_NAME_LENGTH = 16;\r
}\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder;\r
private static ActionsList createSetNwSrcAction(ByteBuf input, ActionsListBuilder builder) {\r
ActionBuilder actionBuilder = new ActionBuilder();\r
actionBuilder.setType(SetNwSrc.class);\r
- actionBuilder.addAugmentation(DlAddressAction.class, createNwAddressAugmentationAndPad(input));\r
+ actionBuilder.addAugmentation(IpAddressAction.class, createNwAddressAugmentationAndPad(input));\r
builder.setAction(actionBuilder.build());\r
return builder.build();\r
}\r
private static ActionsList createSetNwDstAction(ByteBuf input, ActionsListBuilder builder) {\r
ActionBuilder actionBuilder = new ActionBuilder();\r
actionBuilder.setType(SetNwDst.class);\r
- actionBuilder.addAugmentation(DlAddressAction.class, createNwAddressAugmentationAndPad(input));\r
+ actionBuilder.addAugmentation(IpAddressAction.class, createNwAddressAugmentationAndPad(input));\r
builder.setAction(actionBuilder.build());\r
return builder.build();\r
}\r
\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;\r
\r
\r
private static final byte PADDING_IN_MATCH = 1;\r
private static final byte PADDING_IN_MATCH_2 = 2;\r
+ private static final byte NW_SRC_BITS = 6;\r
+ private static final byte NW_SRC_SHIFT = 8;\r
+ private static final int NW_SRC_MASK = ((1 << NW_SRC_BITS) - 1) << NW_SRC_SHIFT;\r
+ private static final byte NW_DST_BITS = 6;\r
+ private static final byte NW_DST_SHIFT = 14;\r
+ private static final int NW_DST_MASK = ((1 << NW_DST_BITS) - 1) << NW_DST_SHIFT;\r
\r
/**\r
* Creates ofp_match (OpenFlow v1.0) structure\r
*/\r
public static MatchV10 createMatchV10(ByteBuf rawMessage) {\r
MatchV10Builder builder = new MatchV10Builder();\r
- builder.setWildcards(rawMessage.readUnsignedInt());\r
+ long wildcards = rawMessage.readUnsignedInt();\r
+ builder.setWildcards(createWildcards(wildcards));\r
+ builder.setNwSrcMask(decodeNwSrcMask(wildcards));\r
+ builder.setNwDstMask(decodeNwDstMask(wildcards));\r
builder.setInPort(rawMessage.readUnsignedShort());\r
byte[] dlSrc = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];\r
rawMessage.readBytes(dlSrc);\r
for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) {\r
dstGroups.add(Short.toString(rawMessage.readUnsignedByte()));\r
}\r
- builder.setNwSrc(new Ipv4Address(joiner.join(dstGroups)));\r
+ builder.setNwDst(new Ipv4Address(joiner.join(dstGroups)));\r
builder.setTpSrc(rawMessage.readUnsignedShort());\r
builder.setTpDst(rawMessage.readUnsignedShort());\r
return builder.build();\r
}\r
\r
+ private static FlowWildcardsV10 createWildcards(long input) {\r
+ boolean _iNPORT = (input & (1 << 0)) != 0;\r
+ boolean _dLVLAN = (input & (1 << 1)) != 0;\r
+ boolean _dLSRC = (input & (1 << 2)) != 0;\r
+ boolean _dLDST = (input & (1 << 3)) != 0;\r
+ boolean _dLTYPE = (input & (1 << 4)) != 0;\r
+ boolean _nWPROTO = (input & (1 << 5)) != 0;\r
+ boolean _tPSRC = (input & (1 << 6)) != 0;\r
+ boolean _tPDST = (input & (1 << 7)) != 0;\r
+ boolean _dLVLANPCP = (input & (1 << 20)) != 0;\r
+ boolean _nWTOS = (input & (1 << 21)) != 0;\r
+ int allBits = (1 << 22) - 1;\r
+ boolean _aLL = (input & allBits) == allBits;\r
+ return new FlowWildcardsV10(_aLL, _dLDST, _dLSRC, _dLTYPE, _dLVLAN,\r
+ _dLVLANPCP, _iNPORT, _nWPROTO, _nWTOS, _tPDST, _tPSRC);\r
+ }\r
+ \r
+ private static short decodeNwSrcMask(long input) {\r
+ return (short) Math.max(32 - ((input & NW_SRC_MASK) >> NW_SRC_SHIFT), 0);\r
+ }\r
+ \r
+ private static short decodeNwDstMask(long input) {\r
+ return (short) Math.max(32 - ((input & NW_DST_MASK) >> NW_DST_SHIFT), 0);\r
+ }\r
+ \r
}\r
/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
package org.opendaylight.openflowjava.protocol.impl.util;\r
\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
import io.netty.buffer.ByteBuf;\r
\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;\r
\r
/**\r
\r
private static final byte PADDING_IN_MATCH = 1;\r
private static final byte PADDING_IN_MATCH_2 = 2;\r
+ private static final byte NW_SRC_SHIFT = 8;\r
+ private static final byte NW_DST_SHIFT = 14;\r
+ private static final int ALL = ((1 << 22) - 1);\r
\r
/**\r
* Encodes ofp_match (OpenFlow v1.0)\r
* @param match match to be encoded\r
*/\r
public static void encodeMatchV10(ByteBuf out, MatchV10 match) {\r
- out.writeInt(match.getWildcards().intValue());\r
+ out.writeInt(encodeWildcards(match.getWildcards(), match.getNwSrcMask(), match.getNwDstMask()));\r
out.writeShort(match.getInPort());\r
out.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlSrc().getValue()));\r
out.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlDst().getValue()));\r
for (int i = 0; i < srcGroups.length; i++) {\r
out.writeByte(Integer.parseInt(srcGroups[i]));\r
}\r
- String[] dstGroups = match.getNwSrc().getValue().split("\\.");\r
+ String[] dstGroups = match.getNwDst().getValue().split("\\.");\r
for (int i = 0; i < dstGroups.length; i++) {\r
out.writeByte(Integer.parseInt(dstGroups[i]));\r
}\r
out.writeShort(match.getTpDst());\r
}\r
\r
+ private static int encodeWildcards(FlowWildcardsV10 wildcards, short srcMask, short dstMask) {\r
+ int bitmask = 0;\r
+ if (wildcards.isALL()) {\r
+ bitmask |= ALL;\r
+ } else {\r
+ Map<Integer, Boolean> wildcardsMap = new HashMap<>();\r
+ wildcardsMap.put(0, wildcards.isINPORT());\r
+ wildcardsMap.put(1, wildcards.isDLVLAN());\r
+ wildcardsMap.put(2, wildcards.isDLSRC());\r
+ wildcardsMap.put(3, wildcards.isDLDST());\r
+ wildcardsMap.put(4, wildcards.isDLTYPE());\r
+ wildcardsMap.put(5, wildcards.isNWPROTO());\r
+ wildcardsMap.put(6, wildcards.isTPSRC());\r
+ wildcardsMap.put(7, wildcards.isTPDST());\r
+ wildcardsMap.put(20, wildcards.isDLVLANPCP());\r
+ wildcardsMap.put(21, wildcards.isNWTOS());\r
+ bitmask = ByteBufUtils.fillBitMaskFromMap(wildcardsMap);\r
+ bitmask |= ((32 - srcMask) << NW_SRC_SHIFT);\r
+ bitmask |= ((32 - dstMask) << NW_DST_SHIFT);\r
+ }\r
+ return bitmask;\r
+ }\r
+ \r
}\r
* Test of {@link ErrorMessageFactory} for correct translation into POJO
*/
@Test
- public void test() {
- ByteBuf bb = BufferHelper.buildBuffer("00 04 00 03 01 02 03 04");
- ErrorMessage builtByFactory = BufferHelper.decodeV13(ErrorMessageFactory.getInstance(), bb);
+ public void testWithoutData() {
+ ByteBuf bb = BufferHelper.buildBuffer("00 01 00 02");
+ ErrorMessage builtByFactory = BufferHelper.decodeV13(
+ ErrorMessageFactory.getInstance(), bb);
+
+ BufferHelper.checkHeaderV13(builtByFactory);
+ Assert.assertEquals("Wrong type", 1, builtByFactory.getType().intValue());
+ Assert.assertEquals("Wrong code", 2, builtByFactory.getCode().intValue());
+ Assert.assertEquals("Wrong type string", "BADREQUEST", builtByFactory.getTypeString());
+ Assert.assertEquals("Wrong code string", "BADMULTIPART", builtByFactory.getCodeString());
+ Assert.assertNull("Data is not null", builtByFactory.getData());
+ }
+
+ /**
+ * Test of {@link ErrorMessageFactory} for correct translation into POJO
+ */
+ @Test
+ public void testWithData() {
+ ByteBuf bb = BufferHelper.buildBuffer("00 00 00 01 00 01 02 03");
+ ErrorMessage builtByFactory = BufferHelper.decodeV13(
+ ErrorMessageFactory.getInstance(), bb);
+
+ BufferHelper.checkHeaderV13(builtByFactory);
+ Assert.assertEquals("Wrong type", 0, builtByFactory.getType().intValue());
+ Assert.assertEquals("Wrong code", 1, builtByFactory.getCode().intValue());
+ Assert.assertEquals("Wrong type string", "HELLOFAILED", builtByFactory.getTypeString());
+ Assert.assertEquals("Wrong code string", "EPERM", builtByFactory.getCodeString());
+ Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());
+ }
+
+ /**
+ * Test of {@link ErrorMessageFactory} for correct translation into POJO
+ */
+ @Test
+ public void testWithIncorrectTypeEnum() {
+ ByteBuf bb = BufferHelper.buildBuffer("00 20 00 05 00 01 02 03");
+ ErrorMessage builtByFactory = BufferHelper.decodeV13(
+ ErrorMessageFactory.getInstance(), bb);
+
+ BufferHelper.checkHeaderV13(builtByFactory);
+ Assert.assertEquals("Wrong type", 32, builtByFactory.getType().intValue());
+ Assert.assertEquals("Wrong code", 5, builtByFactory.getCode().intValue());
+ Assert.assertEquals("Wrong type string", "UNKNOWN_TYPE", builtByFactory.getTypeString());
+ Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
+ Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());
+ }
+
+ /**
+ * Test of {@link ErrorMessageFactory} for correct translation into POJO
+ */
+ @Test
+ public void testWithIncorrectCodeEnum() {
+ ByteBuf bb = BufferHelper.buildBuffer("00 03 00 10 00 01 02 03");
+ ErrorMessage builtByFactory = BufferHelper.decodeV13(
+ ErrorMessageFactory.getInstance(), bb);
+
BufferHelper.checkHeaderV13(builtByFactory);
-
- Assert.assertEquals("Wrong type", 4, builtByFactory.getType().intValue());
- Assert.assertEquals("Wrong code", 3, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong type", "BADMATCH", builtByFactory.getTypeString());
- Assert.assertEquals("Wrong code", "BADDLADDRMASK", builtByFactory.getCodeString());
- Assert.assertArrayEquals("Wrong body", new byte[]{0x01, 0x02, 0x03, 0x04}, builtByFactory.getData());
+ Assert.assertEquals("Wrong type", 3, builtByFactory.getType().intValue());
+ Assert.assertEquals("Wrong code", 16, builtByFactory.getCode().intValue());
+ Assert.assertEquals("Wrong type string", "BADINSTRUCTION", builtByFactory.getTypeString());
+ Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
+ Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());
}
}
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ */\r
+public class OF10ErrorMessageFactoryTest {\r
+\r
+ /**\r
+ * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void testWithoutData() {\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 01 00 02");\r
+ ErrorMessage builtByFactory = BufferHelper.decodeV10(\r
+ OF10ErrorMessageFactory.getInstance(), bb);\r
+\r
+ BufferHelper.checkHeaderV10(builtByFactory);\r
+ Assert.assertEquals("Wrong type", 1, builtByFactory.getType().intValue());\r
+ Assert.assertEquals("Wrong code", 2, builtByFactory.getCode().intValue());\r
+ Assert.assertEquals("Wrong type string", "BADREQUEST", builtByFactory.getTypeString());\r
+ Assert.assertEquals("Wrong code string", "BADSTAT", builtByFactory.getCodeString());\r
+ Assert.assertNull("Data is not null", builtByFactory.getData());\r
+ }\r
+ \r
+ /**\r
+ * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void testWithData() {\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 00 00 01 00 01 02 03");\r
+ ErrorMessage builtByFactory = BufferHelper.decodeV10(\r
+ OF10ErrorMessageFactory.getInstance(), bb);\r
+\r
+ BufferHelper.checkHeaderV10(builtByFactory);\r
+ Assert.assertEquals("Wrong type", 0, builtByFactory.getType().intValue());\r
+ Assert.assertEquals("Wrong code", 1, builtByFactory.getCode().intValue());\r
+ Assert.assertEquals("Wrong type string", "HELLOFAILED", builtByFactory.getTypeString());\r
+ Assert.assertEquals("Wrong code string", "EPERM", builtByFactory.getCodeString());\r
+ Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());\r
+ }\r
+ \r
+ /**\r
+ * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void testWithIncorrectTypeEnum() {\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 05 00 01 02 03");\r
+ ErrorMessage builtByFactory = BufferHelper.decodeV10(\r
+ OF10ErrorMessageFactory.getInstance(), bb);\r
+\r
+ BufferHelper.checkHeaderV10(builtByFactory);\r
+ Assert.assertEquals("Wrong type", 10, builtByFactory.getType().intValue());\r
+ Assert.assertEquals("Wrong code", 5, builtByFactory.getCode().intValue());\r
+ Assert.assertEquals("Wrong type string", "UNKNOWN_TYPE", builtByFactory.getTypeString());\r
+ Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());\r
+ Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());\r
+ }\r
+ \r
+ /**\r
+ * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void testWithIncorrectCodeEnum() {\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 03 00 06 00 01 02 03");\r
+ ErrorMessage builtByFactory = BufferHelper.decodeV10(\r
+ OF10ErrorMessageFactory.getInstance(), bb);\r
+\r
+ BufferHelper.checkHeaderV10(builtByFactory);\r
+ Assert.assertEquals("Wrong type", 3, builtByFactory.getType().intValue());\r
+ Assert.assertEquals("Wrong code", 6, builtByFactory.getCode().intValue());\r
+ Assert.assertEquals("Wrong type string", "FLOWMODFAILED", builtByFactory.getTypeString());\r
+ Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());\r
+ Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());\r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionTypeV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.CapabilitiesV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OF10FeaturesReplyMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void test() {\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "\r
+ + "00 00 00 8B 00 00 03 B5 "\r
+ + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 "\r
+ + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88");\r
+ GetFeaturesOutput builtByFactory = BufferHelper.decodeV10(\r
+ OF10FeaturesReplyMessageFactory.getInstance(), bb);\r
+\r
+ BufferHelper.checkHeaderV10(builtByFactory);\r
+ Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue());\r
+ Assert.assertEquals("Wrong n-buffers", 0x00010203L, builtByFactory.getBuffers().longValue());\r
+ Assert.assertEquals("Wrong n-tables", 0x01, builtByFactory.getTables().shortValue());\r
+ Assert.assertEquals("Wrong capabilities", new CapabilitiesV10(true, true, false, false, false, false, true, true),\r
+ builtByFactory.getCapabilitiesV10());\r
+ Assert.assertEquals("Wrong actions", new ActionTypeV10(false, true, true, true, true, false, true,\r
+ false, true, true, false, false, false), builtByFactory.getActionsV10());\r
+ PhyPort port = builtByFactory.getPhyPort().get(0);\r
+ Assert.assertEquals("Wrong port - port-no", 16, port.getPortNo().intValue());\r
+ Assert.assertEquals("Wrong port - hw-addr", new MacAddress("01:01:05:01:04:02"), port.getHwAddr());\r
+ Assert.assertEquals("Wrong port - name", new String("ALOHA"), port.getName());\r
+ Assert.assertEquals("Wrong port - config", new PortConfigV10(true, false, false, true, false, false, true),\r
+ port.getConfigV10());\r
+ Assert.assertEquals("Wrong port - state", new PortStateV10(false, true, false, false, false, true, false, false),\r
+ port.getStateV10());\r
+ Assert.assertEquals("Wrong port - curr", new PortFeaturesV10(false, false, false, false, true, true, true,\r
+ false, false, false, false, false), port.getCurrentFeaturesV10());\r
+ Assert.assertEquals("Wrong port - advertised", new PortFeaturesV10(false, false, true, true, false, false,\r
+ false, false, false, false, true, false), port.getAdvertisedFeaturesV10());\r
+ Assert.assertEquals("Wrong port - supported", new PortFeaturesV10(true, true, false, false, false, false,\r
+ false, true, false, true, false, false), port.getSupportedFeaturesV10());\r
+ Assert.assertEquals("Wrong port - peer", new PortFeaturesV10(true, false, false, false, false, false, false,\r
+ false, true, false, false, true), port.getPeerFeaturesV10());\r
+ }\r
+ \r
+ /**\r
+ * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void testWithNoPortsSet() {\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "\r
+ + "00 00 00 8B 00 00 03 B5 "\r
+ + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 "\r
+ + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 "\r
+ + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 01 01 "\r
+ + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 ");\r
+ GetFeaturesOutput builtByFactory = BufferHelper.decodeV10(\r
+ OF10FeaturesReplyMessageFactory.getInstance(), bb);\r
+\r
+ BufferHelper.checkHeaderV10(builtByFactory);\r
+ Assert.assertEquals("Wrong ports size", 2, builtByFactory.getPhyPort().size());\r
+ }\r
+ \r
+ /**\r
+ * Testing {@link OF10FeaturesReplyMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void testWithTwoPortsSet() {\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 00 00 00 "\r
+ + "00 00 00 8B 00 00 03 B5");\r
+ GetFeaturesOutput builtByFactory = BufferHelper.decodeV10(\r
+ OF10FeaturesReplyMessageFactory.getInstance(), bb);\r
+\r
+ BufferHelper.checkHeaderV10(builtByFactory);\r
+ Assert.assertEquals("Wrong ports size", 0, builtByFactory.getPhyPort().size());\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ */\r
+public class OF10FlowRemovedMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing {@link OF10FlowRemovedMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void test(){\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 24 08 D1 00 20 AA BB CC DD EE FF "\r
+ + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "//36\r
+ + "50 50 20 20 "// match\r
+ + "00 01 02 03 04 05 06 07 00 03 01 00 00 00 00 02 "\r
+ + "00 00 00 05 00 08 00 00 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07");//41\r
+ FlowRemovedMessage builtByFactory = BufferHelper.decodeV10(OF10FlowRemovedMessageFactory.getInstance(), bb);\r
+\r
+ BufferHelper.checkHeaderV10(builtByFactory);\r
+ Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue());\r
+ Assert.assertEquals("Wrong priority", 0x03, builtByFactory.getPriority().intValue());\r
+ Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().getIntValue());\r
+ Assert.assertEquals("Wrong durationSec", 0x00000002L, builtByFactory.getDurationSec().longValue());\r
+ Assert.assertEquals("Wrong durationNsec", 0x00000005L, builtByFactory.getDurationNsec().longValue());\r
+ Assert.assertEquals("Wrong idleTimeout", 0x08, builtByFactory.getIdleTimeout().intValue());\r
+ Assert.assertEquals("Wrong packetCount", 0x0001020304050607L, builtByFactory.getPacketCount().longValue());\r
+ Assert.assertEquals("Wrong byteCount", 0x0001020304050607L, builtByFactory.getByteCount().longValue());\r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ */\r
+public class OF10HelloMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing {@link OF10HelloMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void testWithoutElements() {\r
+ ByteBuf bb = BufferHelper.buildBuffer();\r
+ HelloMessage builtByFactory = BufferHelper.decodeV10(\r
+ OF10HelloMessageFactory.getInstance(), bb);\r
+\r
+ BufferHelper.checkHeaderV10(builtByFactory);\r
+ Assert.assertNull("Wrong elements", builtByFactory.getElements());\r
+ }\r
+ \r
+ /**\r
+ * Testing {@link OF10HelloMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void testWithElements() {\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 01 " // type\r
+ + "00 0c " // length\r
+ + "00 00 00 11 " // bitmap 1\r
+ + "00 00 00 00 " // bitmap 2\r
+ + "00 00 00 00" // padding\r
+ );\r
+ HelloMessage builtByFactory = BufferHelper.decodeV10(\r
+ OF10HelloMessageFactory.getInstance(), bb);\r
+\r
+ BufferHelper.checkHeaderV10(builtByFactory);\r
+ Assert.assertNull("Wrong elements", builtByFactory.getElements());\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;\r
+\r
+public class OF10PacketInMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing {@link OF10PacketInMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void test(){\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00 01 02 03 04");\r
+ PacketInMessage builtByFactory = BufferHelper.decodeV10(OF10PacketInMessageFactory.getInstance(), bb); \r
+ \r
+ BufferHelper.checkHeaderV10(builtByFactory);\r
+ Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue());\r
+ Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue());\r
+ Assert.assertEquals("Wrong inPort", 0x0102, builtByFactory.getInPort().intValue());\r
+ Assert.assertEquals("Wrong reason", PacketInReason.OFPRNOMATCH, builtByFactory.getReason());\r
+ Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData());\r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OF10PortStatusMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing {@link OF10PortStatusMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void test(){\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 00 00 00 00 00 00 00 "\r
+ + "00 10 01 01 05 01 04 02 41 4C 4F 48 41 00 00 00 00 00 00 00 00 00 00 "\r
+ + "00 00 00 00 15 00 00 01 01 00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88");\r
+ PortStatusMessage builtByFactory = BufferHelper.decodeV10(OF10PortStatusMessageFactory.getInstance(), bb);\r
+ \r
+ BufferHelper.checkHeaderV10(builtByFactory);\r
+ Assert.assertEquals("Wrong reason", PortReason.OFPPRADD, builtByFactory.getReason());\r
+ Assert.assertEquals("Wrong port - port-no", 16, builtByFactory.getPortNo().intValue());\r
+ Assert.assertEquals("Wrong builtByFactory - hw-addr", new MacAddress("01:01:05:01:04:02"), builtByFactory.getHwAddr());\r
+ Assert.assertEquals("Wrong builtByFactory - name", new String("ALOHA"), builtByFactory.getName());\r
+ Assert.assertEquals("Wrong builtByFactory - config", new PortConfigV10(true, false, false, true, false, false, true),\r
+ builtByFactory.getConfigV10());\r
+ Assert.assertEquals("Wrong builtByFactory - state", new PortStateV10(false, true, false, false, false, true, false, false),\r
+ builtByFactory.getStateV10());\r
+ Assert.assertEquals("Wrong builtByFactory - curr", new PortFeaturesV10(false, false, false, false, true, true, true,\r
+ false, false, false, false, false), builtByFactory.getCurrentFeaturesV10());\r
+ Assert.assertEquals("Wrong builtByFactory - advertised", new PortFeaturesV10(false, false, true, true, false, false,\r
+ false, false, false, false, true, false), builtByFactory.getAdvertisedFeaturesV10());\r
+ Assert.assertEquals("Wrong builtByFactory - supbuiltByFactoryed", new PortFeaturesV10(true, true, false, false, false, false,\r
+ false, true, false, true, false, false), builtByFactory.getSupportedFeaturesV10());\r
+ Assert.assertEquals("Wrong builtByFactory - peer", new PortFeaturesV10(true, false, false, false, false, false, false,\r
+ false, true, false, false, true), builtByFactory.getPeerFeaturesV10());\r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OF10QueueGetConfigReplyMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing of {@link OF10QueueGetConfigReplyMessageFactory} for correct\r
+ * translation into POJO\r
+ */\r
+ @Test\r
+ public void test() {\r
+ ByteBuf bb = BufferHelper.buildBuffer("00 01 00 00 00 00 00 00 "\r
+ + "00 00 00 08 00 10 00 00 00 00 00 08 00 00 00 00 "\r
+ + "00 00 00 02 00 28 00 00 00 01 00 10 00 00 00 00 00 20 00 00 00 00 00 00 "\r
+ + "00 01 00 10 00 00 00 00 00 30 00 00 00 00 00 00");\r
+ GetQueueConfigOutput builtByFactory = BufferHelper.decodeV10(\r
+ OF10QueueGetConfigReplyMessageFactory.getInstance(), bb);\r
+\r
+ BufferHelper.checkHeaderV10(builtByFactory);\r
+ Assert.assertEquals("Wrong port", 1, builtByFactory.getPort().getValue().intValue());\r
+ Assert.assertEquals("Wrong queues size", 2, builtByFactory.getQueues().size());\r
+ Queues queue1 = builtByFactory.getQueues().get(0);\r
+ Queues queue2 = builtByFactory.getQueues().get(1);\r
+ Assert.assertEquals("Wrong queueId", 8, queue1.getQueueId().getValue().intValue());\r
+ Assert.assertEquals("Wrong queue - # properties", 1, queue1.getQueueProperty().size());\r
+ Assert.assertEquals("Wrong queue - wrong property", QueueProperties.OFPQTNONE,\r
+ queue1.getQueueProperty().get(0).getProperty());\r
+ Assert.assertEquals("Wrong queueId", 2, queue2.getQueueId().getValue().intValue());\r
+ Assert.assertEquals("Wrong queue - # properties", 2, queue2.getQueueProperty().size());\r
+ Assert.assertEquals("Wrong queue - wrong property", QueueProperties.OFPQTMINRATE,\r
+ queue2.getQueueProperty().get(0).getProperty());\r
+ Assert.assertEquals("Wrong queue - wrong property", QueueProperties.OFPQTMINRATE,\r
+ queue2.getQueueProperty().get(1).getProperty());\r
+ RateQueueProperty rate1 = queue2.getQueueProperty().get(0).getAugmentation(RateQueueProperty.class);\r
+ RateQueueProperty rate2 = queue2.getQueueProperty().get(1).getAugmentation(RateQueueProperty.class);\r
+ Assert.assertEquals("Wrong queue - wrong property rate", 32, rate1.getRate().intValue());\r
+ Assert.assertEquals("Wrong queue - wrong property rate", 48, rate2.getRate().intValue());\r
+ }\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ */\r
+public class OF10VendorMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing {@link OF10VendorMessageFactory} for correct translation into POJO\r
+ */\r
+ @Test\r
+ public void test() {\r
+ ByteBuf bb = BufferHelper.buildBuffer("01 02 03 04");\r
+ ExperimenterMessage builtByFactory = BufferHelper.decodeV10(\r
+ OF10VendorMessageFactory.getInstance(), bb);\r
+\r
+ BufferHelper.checkHeaderV10(builtByFactory);\r
+ Assert.assertEquals("Wrong experimenter", 0x01020304L, builtByFactory.getExperimenter().longValue());\r
+ }\r
+}\r
*/\r
public class FlowModInputMessageFactoryTest {\r
private static final byte PADDING_IN_FLOW_MOD_MESSAGE = 2;\r
+ \r
/**\r
* @throws Exception \r
* Testing of {@link FlowModInputMessageFactory} for correct translation from POJO\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OF10BarrierInputMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing of {@link OF10BarrierInputMessageFactory} for correct translation from POJO\r
+ * @throws Exception \r
+ */\r
+ @Test\r
+ public void test() throws Exception {\r
+ BarrierInputBuilder bib = new BarrierInputBuilder();\r
+ BufferHelper.setupHeader(bib, EncodeConstants.OF10_VERSION_ID);\r
+ BarrierInput bi = bib.build();\r
+ \r
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ OF10BarrierInputMessageFactory bimf = OF10BarrierInputMessageFactory.getInstance();\r
+ bimf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, bi);\r
+ \r
+ BufferHelper.checkHeaderV10(out, (byte) 18, 8);\r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+\r
+import java.math.BigInteger;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlagsV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OF10FlowModInputMessageFactoryTest {\r
+\r
+ /**\r
+ * @throws Exception \r
+ * Testing of {@link OF10FlowModInputMessageFactory} for correct translation from POJO\r
+ */\r
+ @Test\r
+ public void testFlowModInputMessageFactory() throws Exception {\r
+ FlowModInputBuilder builder = new FlowModInputBuilder();\r
+ BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);\r
+ MatchV10Builder matchBuilder = new MatchV10Builder();\r
+ matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true, true));\r
+ matchBuilder.setNwSrcMask((short) 0);\r
+ matchBuilder.setNwDstMask((short) 0);\r
+ matchBuilder.setInPort(58);\r
+ matchBuilder.setDlSrc(new MacAddress("01:01:01:01:01:01"));\r
+ matchBuilder.setDlDst(new MacAddress("ff:ff:ff:ff:ff:ff"));\r
+ matchBuilder.setDlVlan(18);\r
+ matchBuilder.setDlVlanPcp((short) 5);\r
+ matchBuilder.setDlType(42);\r
+ matchBuilder.setNwTos((short) 4);\r
+ matchBuilder.setNwProto((short) 7);\r
+ matchBuilder.setNwSrc(new Ipv4Address("8.8.8.8"));\r
+ matchBuilder.setNwDst(new Ipv4Address("16.16.16.16"));\r
+ matchBuilder.setTpSrc(6653);\r
+ matchBuilder.setTpDst(6633);\r
+ builder.setMatchV10(matchBuilder.build());\r
+ byte[] cookie = new byte[]{0x00, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01};\r
+ builder.setCookie(new BigInteger(cookie));\r
+ builder.setCommand(FlowModCommand.forValue(0));\r
+ builder.setIdleTimeout(12);\r
+ builder.setHardTimeout(16);\r
+ builder.setPriority(1);\r
+ builder.setBufferId(2L);\r
+ builder.setOutPort(new PortNumber(4422L));\r
+ builder.setFlagsV10(new FlowModFlagsV10(true, false, true));\r
+ List<ActionsList> actions = new ArrayList<>();\r
+ ActionsListBuilder actionsListBuilder = new ActionsListBuilder();\r
+ ActionBuilder actionBuilder = new ActionBuilder();\r
+ actionBuilder.setType(SetNwDst.class);\r
+ IpAddressActionBuilder ipBuilder = new IpAddressActionBuilder();\r
+ ipBuilder.setIpAddress(new Ipv4Address("2.2.2.2"));\r
+ actionBuilder.addAugmentation(IpAddressAction.class, ipBuilder.build());\r
+ actionsListBuilder.setAction(actionBuilder.build());\r
+ actions.add(actionsListBuilder.build());\r
+ actionBuilder = new ActionBuilder();\r
+ actionBuilder.setType(SetTpSrc.class);\r
+ PortActionBuilder portBuilder = new PortActionBuilder();\r
+ portBuilder.setPort(new PortNumber(42L));\r
+ actionBuilder.addAugmentation(PortAction.class, portBuilder.build());\r
+ actionsListBuilder.setAction(actionBuilder.build());\r
+ actions.add(actionsListBuilder.build());\r
+ builder.setActionsList(actions);\r
+ FlowModInput message = builder.build();\r
+ \r
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ OF10FlowModInputMessageFactory factory = OF10FlowModInputMessageFactory.getInstance();\r
+ factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+ \r
+ BufferHelper.checkHeaderV10(out, factory.getMessageType(), factory.computeLength(message));\r
+ Assert.assertEquals("Wrong wildcards", 4194303, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong inPort", 58, out.readUnsignedShort());\r
+ byte[] dlSrc = new byte[6];\r
+ out.readBytes(dlSrc);\r
+ Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));\r
+ byte[] dlDst = new byte[6];\r
+ out.readBytes(dlDst);\r
+ Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst));\r
+ Assert.assertEquals("Wrong dlVlan", 18, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong dlVlanPcp", 5, out.readUnsignedByte());\r
+ out.skipBytes(1);\r
+ Assert.assertEquals("Wrong dlType", 42, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong nwTos", 4, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong nwProto", 7, out.readUnsignedByte());\r
+ out.skipBytes(2);\r
+ Assert.assertEquals("Wrong nwSrc", 134744072, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong nwDst", 269488144, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong tpSrc", 6653, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong tpDst", 6633, out.readUnsignedShort());\r
+ byte[] cookieRead = new byte[8];\r
+ out.readBytes(cookieRead);\r
+ Assert.assertArrayEquals("Wrong cookie", cookie, cookieRead);\r
+ Assert.assertEquals("Wrong command", 0, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong idleTimeOut", 12, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong hardTimeOut", 16, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong priority", 1, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong bufferId", 2, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong outPort", 4422, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong action - type", 7, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong flags", 33686018, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong action - type", 9, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong action - length", 8, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong flags", 42, out.readUnsignedShort());\r
+ out.skipBytes(2);\r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OF10HelloInputMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing of {@link OF10HelloInputMessageFactory} for correct translation from POJO\r
+ * @throws Exception \r
+ */\r
+ @Test\r
+ public void testWithoutElementsSet() throws Exception {\r
+ HelloInputBuilder hib = new HelloInputBuilder();\r
+ BufferHelper.setupHeader(hib, EncodeConstants.OF10_VERSION_ID);\r
+ HelloInput hi = hib.build();\r
+ \r
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ OF10HelloInputMessageFactory himf = OF10HelloInputMessageFactory.getInstance();\r
+ himf.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, hi);\r
+ \r
+ BufferHelper.checkHeaderV10(out, (byte) 0, 8);\r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsListBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.ActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OF10PacketOutInputMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing of {@link OF10PacketOutInputMessageFactory} for correct translation from POJO\r
+ * @throws Exception \r
+ */\r
+ @Test\r
+ public void testPacketOutInputMessage() throws Exception {\r
+ PacketOutInputBuilder builder = new PacketOutInputBuilder();\r
+ BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);\r
+ builder.setBufferId(256L);\r
+ builder.setInPort(new PortNumber(257L));\r
+ List<ActionsList> actions = new ArrayList<>();\r
+ ActionsListBuilder actionsListBuilder = new ActionsListBuilder();\r
+ ActionBuilder actionBuilder = new ActionBuilder();\r
+ actionBuilder.setType(Output.class);\r
+ PortActionBuilder portBuilder = new PortActionBuilder();\r
+ portBuilder.setPort(new PortNumber((long) 42));\r
+ actionBuilder.addAugmentation(PortAction.class, portBuilder.build());\r
+ MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder();\r
+ maxLen.setMaxLength(50);\r
+ actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build());\r
+ actionsListBuilder.setAction(actionBuilder.build());\r
+ actions.add(actionsListBuilder.build());\r
+ actionsListBuilder = new ActionsListBuilder();\r
+ actionBuilder = new ActionBuilder();\r
+ actionBuilder.setType(StripVlan.class);\r
+ actionsListBuilder.setAction(actionBuilder.build());\r
+ builder.setActionsList(actions);\r
+ actions.add(actionsListBuilder.build());\r
+ builder.setActionsList(actions);\r
+ builder.setData(ByteBufUtils.hexStringToBytes("00 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14"));\r
+ PacketOutInput message = builder.build();\r
+ \r
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ OF10PacketOutInputMessageFactory factory = OF10PacketOutInputMessageFactory.getInstance();\r
+ factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);\r
+ \r
+ BufferHelper.checkHeaderV10(out, (byte) 13, 48);\r
+ Assert.assertEquals("Wrong BufferId", 256, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong PortNumber", 257, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong actions length", 16, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong port", 42, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong maxlength", 50, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong action type", 3, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());\r
+ out.skipBytes(4);\r
+ Assert.assertArrayEquals("Wrong data", message.getData(), out.readBytes(out.readableBytes()).array());\r
+ Assert.assertTrue("Unread data", out.readableBytes() == 0);\r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+import junit.framework.Assert;\r
+\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeaturesV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OF10PortModInputMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing of {@link OF10PortModInputMessageFactory} for correct translation from POJO\r
+ * @throws Exception \r
+ */\r
+ @Test\r
+ public void testPortModInput() throws Exception {\r
+ PortModInputBuilder builder = new PortModInputBuilder();\r
+ BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);\r
+ builder.setPortNo(new PortNumber(6633L));\r
+ builder.setHwAddress(new MacAddress("08:00:27:00:B0:EB"));\r
+ builder.setConfigV10(new PortConfigV10(true, false, false, true, false, false, true));\r
+ builder.setMaskV10(new PortConfigV10(false, true, true, false, false, true, false));\r
+ builder.setAdvertiseV10(new PortFeaturesV10(true, true, false, false, false, false,\r
+ false, true, true, false, false, false));\r
+ PortModInput message = builder.build();\r
+ \r
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ OF10PortModInputMessageFactory factory = OF10PortModInputMessageFactory.getInstance();\r
+ factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+ \r
+ BufferHelper.checkHeaderV10(out, (byte) 15, 32);\r
+ Assert.assertEquals("Wrong PortNo", message.getPortNo().getValue().longValue(), out.readUnsignedShort());\r
+ byte[] address = new byte[6];\r
+ out.readBytes(address);\r
+ Assert.assertEquals("Wrong MacAddress", message.getHwAddress(),\r
+ new MacAddress(ByteBufUtils.macAddressToString(address)));\r
+ Assert.assertEquals("Wrong config", 21, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong mask", 98, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong advertise", 652, out.readUnsignedInt());\r
+ out.skipBytes(4);\r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+import junit.framework.Assert;\r
+\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInputBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OF10QueueGetConfigInputMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing of {@link OF10QueueGetConfigInputMessageFactory} for correct translation from POJO\r
+ * @throws Exception \r
+ */\r
+ @Test\r
+ public void test() throws Exception {\r
+ GetQueueConfigInputBuilder builder = new GetQueueConfigInputBuilder();\r
+ BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);\r
+ builder.setPort(new PortNumber(6653L));\r
+ GetQueueConfigInput message = builder.build();\r
+ \r
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ OF10QueueGetConfigInputMessageFactory factory = OF10QueueGetConfigInputMessageFactory.getInstance();\r
+ factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+ \r
+ BufferHelper.checkHeaderV10(out, (byte) 20, 12);\r
+ Assert.assertEquals("Wrong port", 6653L, out.readUnsignedShort());\r
+ out.skipBytes(2);\r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OF10VendorInputMessageFactoryTest {\r
+\r
+ /**\r
+ * Testing of {@link OF10VendorInputMessageFactory} for correct translation from POJO\r
+ * @throws Exception \r
+ */\r
+ @Test\r
+ public void test() throws Exception {\r
+ ExperimenterInputBuilder builder = new ExperimenterInputBuilder();\r
+ BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);\r
+ builder.setExperimenter(0x0001020304L);\r
+ builder.setData(new byte[] {0x01, 0x02, 0x03, 0x04});\r
+ ExperimenterInput message = builder.build();\r
+ \r
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ OF10VendorInputMessageFactory factory = OF10VendorInputMessageFactory.getInstance();\r
+ factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);\r
+ \r
+ BufferHelper.checkHeaderV10(out, (byte) 4, factory.computeLength(message));\r
+ Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt());\r
+ byte[] data = new byte[4];\r
+ out.readBytes(data);\r
+ Assert.assertArrayEquals("Wrong data", message.getData(), data);\r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OF10MatchDeserializerTest {\r
+\r
+ /**\r
+ * Testing correct deserialization of ofp_match\r
+ */\r
+ @Test\r
+ public void test() {\r
+ ByteBuf message = BufferHelper.buildBuffer("00 24 08 91 00 20 AA BB CC DD EE FF "\r
+ + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "\r
+ + "50 50 20 20");\r
+ message.skipBytes(4); // skip XID\r
+ MatchV10 match = OF10MatchDeserializer.createMatchV10(message);\r
+ Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, false, true, false,\r
+ false, true, false, true, true, false), match.getWildcards());\r
+ Assert.assertEquals("Wrong srcMask", 24, match.getNwSrcMask().shortValue());\r
+ Assert.assertEquals("Wrong dstMask", 16, match.getNwDstMask().shortValue());\r
+ Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue());\r
+ Assert.assertEquals("Wrong dl-src", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlSrc());\r
+ Assert.assertEquals("Wrong dl-dst", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlDst());\r
+ Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue());\r
+ Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue());\r
+ Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue());\r
+ Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue());\r
+ Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue());\r
+ Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc());\r
+ Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst());\r
+ Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue());\r
+ Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue());\r
+ }\r
+ \r
+ /**\r
+ * Testing correct deserialization of ofp_match\r
+ */\r
+ @Test\r
+ public void test2() {\r
+ ByteBuf message = BufferHelper.buildBuffer("00 3F FF FF 00 20 AA BB CC DD EE FF "\r
+ + "AA BB CC DD EE FF 00 05 10 00 00 08 07 06 00 00 10 11 12 13 01 02 03 04 "\r
+ + "50 50 20 20");\r
+ message.skipBytes(4); // skip XID\r
+ MatchV10 match = OF10MatchDeserializer.createMatchV10(message);\r
+ Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(true, true, true, true, true,\r
+ true, true, true, true, true, true), match.getWildcards());\r
+ Assert.assertEquals("Wrong srcMask", 0, match.getNwSrcMask().shortValue());\r
+ Assert.assertEquals("Wrong dstMask", 0, match.getNwDstMask().shortValue());\r
+ Assert.assertEquals("Wrong in-port", 32, match.getInPort().intValue());\r
+ Assert.assertEquals("Wrong dl-src", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlSrc());\r
+ Assert.assertEquals("Wrong dl-dst", new MacAddress("AA:BB:CC:DD:EE:FF"), match.getDlDst());\r
+ Assert.assertEquals("Wrong dl-vlan", 5, match.getDlVlan().intValue());\r
+ Assert.assertEquals("Wrong dl-vlan-pcp", 16, match.getDlVlanPcp().shortValue());\r
+ Assert.assertEquals("Wrong dl-type", 8, match.getDlType().intValue());\r
+ Assert.assertEquals("Wrong nw-tos", 7, match.getNwTos().shortValue());\r
+ Assert.assertEquals("Wrong nw-proto", 6, match.getNwProto().shortValue());\r
+ Assert.assertEquals("Wrong nw-src", new Ipv4Address("16.17.18.19"), match.getNwSrc());\r
+ Assert.assertEquals("Wrong nw-dst", new Ipv4Address("1.2.3.4"), match.getNwDst());\r
+ Assert.assertEquals("Wrong tp-src", 20560, match.getTpSrc().shortValue());\r
+ Assert.assertEquals("Wrong tp-dst", 8224, match.getTpDst().shortValue());\r
+ }\r
+\r
+}\r
--- /dev/null
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import junit.framework.Assert;\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+\r
+import org.junit.Test;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class OF10MatchSerializerTest {\r
+\r
+ /**\r
+ * Testing correct serialization of ofp_match\r
+ */\r
+ @Test\r
+ public void test() {\r
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ MatchV10Builder builder = new MatchV10Builder();\r
+ builder.setWildcards(new FlowWildcardsV10(false, false, false, true, false,\r
+ false, true, false, true, true, true));\r
+ builder.setNwSrcMask((short) 24);\r
+ builder.setNwDstMask((short) 16);\r
+ builder.setInPort(6653);\r
+ builder.setDlSrc(new MacAddress("01:01:01:01:01:01"));\r
+ builder.setDlDst(new MacAddress("02:02:02:02:02:02"));\r
+ builder.setDlVlan(128);\r
+ builder.setDlVlanPcp((short) 2);\r
+ builder.setDlType(15);\r
+ builder.setNwTos((short) 14);\r
+ builder.setNwProto((short) 85);\r
+ builder.setNwSrc(new Ipv4Address("1.1.1.2"));\r
+ builder.setNwDst(new Ipv4Address("32.16.8.1"));\r
+ builder.setTpSrc(2048);\r
+ builder.setTpDst(4096);\r
+ MatchV10 match = builder.build();\r
+ OF10MatchSerializer.encodeMatchV10(out, match);\r
+ \r
+ Assert.assertEquals("Wrong wildcards", 2361553, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort());\r
+ byte[] dlSrc = new byte[6];\r
+ out.readBytes(dlSrc);\r
+ Assert.assertEquals("Wrong dl-src", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));\r
+ byte[] dlDst = new byte[6];\r
+ out.readBytes(dlDst);\r
+ Assert.assertEquals("Wrong dl-dst", "02:02:02:02:02:02", ByteBufUtils.macAddressToString(dlDst));\r
+ Assert.assertEquals("Wrong dl-vlan", 128, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong dl-vlan-pcp", 2, out.readUnsignedByte());\r
+ out.skipBytes(1);\r
+ Assert.assertEquals("Wrong dl-type", 15, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong nw-tos", 14, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong nw-proto", 85, out.readUnsignedByte());\r
+ out.skipBytes(2);\r
+ Assert.assertEquals("Wrong nw-src", 16843010, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong nw-dst", 537921537, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong tp-src", 2048, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong tp-dst", 4096, out.readUnsignedShort());\r
+ }\r
+ \r
+ /**\r
+ * Testing correct serialization of ofp_match\r
+ */\r
+ @Test\r
+ public void test2() {\r
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+ MatchV10Builder builder = new MatchV10Builder();\r
+ builder.setWildcards(new FlowWildcardsV10(true, true, true, true, true,\r
+ true, true, true, true, true, true));\r
+ builder.setNwSrcMask((short) 0);\r
+ builder.setNwDstMask((short) 0);\r
+ builder.setInPort(6653);\r
+ builder.setDlSrc(new MacAddress("01:01:01:01:01:01"));\r
+ builder.setDlDst(new MacAddress("02:02:02:02:02:02"));\r
+ builder.setDlVlan(128);\r
+ builder.setDlVlanPcp((short) 2);\r
+ builder.setDlType(15);\r
+ builder.setNwTos((short) 14);\r
+ builder.setNwProto((short) 85);\r
+ builder.setNwSrc(new Ipv4Address("1.1.1.2"));\r
+ builder.setNwDst(new Ipv4Address("32.16.8.1"));\r
+ builder.setTpSrc(2048);\r
+ builder.setTpDst(4096);\r
+ MatchV10 match = builder.build();\r
+ OF10MatchSerializer.encodeMatchV10(out, match);\r
+ \r
+ Assert.assertEquals("Wrong wildcards", 4194303, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort());\r
+ byte[] dlSrc = new byte[6];\r
+ out.readBytes(dlSrc);\r
+ Assert.assertEquals("Wrong dl-src", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));\r
+ byte[] dlDst = new byte[6];\r
+ out.readBytes(dlDst);\r
+ Assert.assertEquals("Wrong dl-dst", "02:02:02:02:02:02", ByteBufUtils.macAddressToString(dlDst));\r
+ Assert.assertEquals("Wrong dl-vlan", 128, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong dl-vlan-pcp", 2, out.readUnsignedByte());\r
+ out.skipBytes(1);\r
+ Assert.assertEquals("Wrong dl-type", 15, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong nw-tos", 14, out.readUnsignedByte());\r
+ Assert.assertEquals("Wrong nw-proto", 85, out.readUnsignedByte());\r
+ out.skipBytes(2);\r
+ Assert.assertEquals("Wrong nw-src", 16843010, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong nw-dst", 537921537, out.readUnsignedInt());\r
+ Assert.assertEquals("Wrong tp-src", 2048, out.readUnsignedShort());\r
+ Assert.assertEquals("Wrong tp-dst", 4096, out.readUnsignedShort());\r
+ }\r
+}\r