- removed ending whitespace characters from .buildBuffer method as those hexStrings should be ended with a hex character
Change-Id: If1e53d7bbcc81293aa7a231b24b1b7a7746cb5c7
Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
\r
+import com.google.common.base.Splitter;\r
+\r
/**\r
* @author michal.polkorab\r
*\r
@Override\r
public void serialize(Action action, ByteBuf outBuffer) {\r
super.serialize(action, outBuffer);\r
- String[] addressGroups = action.getAugmentation(IpAddressAction.class)\r
- .getIpAddress().getValue().split("\\.");\r
- for (int i = 0; i < addressGroups.length; i++) {\r
- outBuffer.writeByte(Integer.parseInt(addressGroups[i]));\r
+ Iterable<String> addressGroups = Splitter.on(".")\r
+ .split(action.getAugmentation(IpAddressAction.class).getIpAddress().getValue());\r
+ for (String group : addressGroups) {\r
+ outBuffer.writeByte(Short.parseShort(group));\r
}\r
}\r
}\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
\r
+import com.google.common.base.Splitter;\r
+\r
/**\r
* Parent for Ipv4 address based match entry serializers\r
* @author michal.polkorab\r
}\r
\r
private static void writeIpv4Address(MatchEntries entry, ByteBuf out) {\r
- String[] addressGroups = entry.getAugmentation(Ipv4AddressMatchEntry.class)\r
- .getIpv4Address().getValue().split("\\.");\r
- for (int i = 0; i < addressGroups.length; i++) {\r
- out.writeByte(Integer.parseInt(addressGroups[i]));\r
+ Iterable<String> addressGroups = Splitter.on(".")\r
+ .split(entry.getAugmentation(Ipv4AddressMatchEntry.class).getIpv4Address().getValue());\r
+ for (String group : addressGroups) {\r
+ out.writeByte(Short.parseShort(group));\r
}\r
}\r
\r
\r
import io.netty.buffer.ByteBuf;\r
\r
+import java.util.ArrayList;\r
import java.util.Arrays;\r
+import java.util.List;\r
\r
import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
\r
+import com.google.common.base.Splitter;\r
+import com.google.common.collect.Lists;\r
+\r
/**\r
* Parent for Ipv6 address based match entry serializers\r
* @author michal.polkorab\r
public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
super.serialize(entry, outBuffer);\r
String textAddress = entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address().getValue();\r
- String[] address;\r
+ List<String> address;\r
if (textAddress.equals("::")) {\r
- address = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];\r
- Arrays.fill(address, "0");\r
+ String[] tmp = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];\r
+ Arrays.fill(tmp, "0");\r
+ address = Arrays.asList(tmp);\r
} else {\r
- address = parseIpv6Address(textAddress.split(":"));\r
+ address = parseIpv6Address(Lists.newArrayList(Splitter.on(":").split(textAddress)));\r
}\r
- for (int i = 0; i < address.length; i++) {\r
- outBuffer.writeShort(Integer.parseInt(address[i], 16));\r
+ for (String group : address) {\r
+ outBuffer.writeShort(Integer.parseInt(group, 16));\r
}\r
writeMask(entry, outBuffer, getValueLength());\r
}\r
\r
- private static String[] parseIpv6Address(String[] addressGroups) {\r
+ private static List<String> parseIpv6Address(ArrayList<String> addressGroups) {\r
int countEmpty = 0;\r
- for (int i = 0; i < addressGroups.length; i++) {\r
- if (addressGroups[i].equals("")){\r
+ for (String group : addressGroups) {\r
+ if (group.equals("")) {\r
countEmpty++;\r
}\r
}\r
- String[] ready = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];\r
+ List<String> ready = new ArrayList<>(EncodeConstants.GROUPS_IN_IPV6_ADDRESS);\r
switch (countEmpty) {\r
case 0:\r
ready = addressGroups;\r
break;\r
case 1:\r
- int zerosToBePushed = EncodeConstants.GROUPS_IN_IPV6_ADDRESS - addressGroups.length + 1;\r
- int index = 0;\r
- for (int i = 0; i < addressGroups.length; i++) {\r
- if (addressGroups[i].equals("")) {\r
+ int zerosToBePushed = EncodeConstants.GROUPS_IN_IPV6_ADDRESS - addressGroups.size() + 1;\r
+ for (String group : addressGroups) {\r
+ if (group.equals("")) {\r
for (int j = 0; j < zerosToBePushed; j++) {\r
- ready[index] = "0";\r
- index++;\r
+ ready.add("0");\r
}\r
} else {\r
- ready[index] = addressGroups[i];\r
- index++;\r
+ ready.add(group);\r
}\r
}\r
break;\r
case 2:\r
- Arrays.fill(ready, "0");\r
- ready[ready.length - 1] = addressGroups[addressGroups.length - 1];\r
+ String[] tmp = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];\r
+ Arrays.fill(tmp, "0");\r
+ tmp[EncodeConstants.GROUPS_IN_IPV6_ADDRESS - 1] =\r
+ addressGroups.get(addressGroups.size() - 1);\r
+ ready = Arrays.asList(tmp);\r
break;\r
default:\r
throw new IllegalStateException("Incorrect ipv6 address");\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
/** Class for common operations on ByteBuf
* @author michal.polkorab
public static byte[] hexStringToBytes(String hexSrc) {
return hexStringToBytes(hexSrc, true);
}
-
+
/**
* Converts String into byte[]
* @param hexSrc input String
if (!withSpaces) {
splitPattern = "(?<=\\G.{2})";
}
-
- String[] byteChips = hexSrc.split(splitPattern);
- byte[] result = new byte[byteChips.length];
- for (int i = 0; i < byteChips.length; i++) {
- result[i] = (byte) Short.parseShort(byteChips[i], 16);
+ Iterable<String> tmp = Splitter.onPattern(splitPattern)
+ .omitEmptyStrings().split(hexSrc);
+ ArrayList<String> byteChips = Lists.newArrayList(tmp);
+ byte[] result = new byte[byteChips.size()];
+ int i = 0;
+ for (String chip : byteChips) {
+ result[i] = (byte) Short.parseShort(chip, 16);
+ i++;
}
return result;
}
-
+
/**
* Creates ByteBuf filled with specified data
* @param hexSrc input String of bytes in hex format
* @return byte representation of mac address
* @see {@link MacAddress}
*/
- @SuppressWarnings("javadoc")
public static byte[] macAddressToBytes(String macAddress) {
- String[] sequences = macAddress.split(":");
+ Iterable<String> addressGroups = Splitter.on(":").split(macAddress);
byte[] result = new byte[EncodeConstants.MAC_ADDRESS_LENGTH];
- for (int i = 0; i < sequences.length; i++) {
- result[i] = (byte) Short.parseShort(sequences[i], 16);
+ int i = 0;
+ for (String group : addressGroups) {
+ result[i] = (byte) Short.parseShort(group, 16);
+ i++;
}
return result;
}
* @return String representation of mac address
* @see {@link MacAddress}
*/
- @SuppressWarnings("javadoc")
public static String macAddressToString(byte[] address) {
List<String> groups = new ArrayList<>();
for(int i=0; i < EncodeConstants.MAC_ADDRESS_LENGTH; i++){
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
+import com.google.common.base.Splitter;
+
/**
* Serializes ofp_match (OpenFlow v1.0) structure
* @author michal.polkorab
outBuffer.writeByte(match.getNwTos());
outBuffer.writeByte(match.getNwProto());
ByteBufUtils.padBuffer(PADDING_IN_MATCH_2, outBuffer);
- String[] srcGroups = match.getNwSrc().getValue().split("\\.");
- for (int i = 0; i < srcGroups.length; i++) {
- outBuffer.writeByte(Integer.parseInt(srcGroups[i]));
+ Iterable<String> srcGroups = Splitter.on(".").split(match.getNwSrc().getValue());
+ for (String group : srcGroups) {
+ outBuffer.writeByte(Short.parseShort(group));
}
- String[] dstGroups = match.getNwDst().getValue().split("\\.");
- for (int i = 0; i < dstGroups.length; i++) {
- outBuffer.writeByte(Integer.parseInt(dstGroups[i]));
+ Iterable<String> dstGroups = Splitter.on(".").split(match.getNwDst().getValue());
+ for (String group : dstGroups) {
+ outBuffer.writeByte(Short.parseShort(group));
}
outBuffer.writeShort(match.getTpSrc());
outBuffer.writeShort(match.getTpDst());
"00 01 02 03 "+ //portNo
"00 00 00 00 "+ //padding01
"08 00 27 00 B0 EB " + //mac address
- "00 00 "); //padding02
+ "00 00"); //padding02
//port name
String portName = "SampleText";
byte[] portNameBytes = new byte[MAX_PORT_NAME_LEN];
+ "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 "
+ "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 "
+ "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 "
- + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88 ");
+ + "00 00 00 31 00 00 04 42 00 00 03 0C 00 00 08 88");
GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
BufferHelper.checkHeaderV10(builtByFactory);
+ "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 "\r
+ "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 "\r
+ "FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 FF 02 03 02 03 02 03 02 "\r
- + "FF 02 03 02 03 02 03 02 ");\r
+ + "FF 02 03 02 03 02 03 02");\r
\r
MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);\r
\r
+ "00 FF 00 00 00 00 00 10 "\r
+ "FF 02 03 02 03 02 03 02 "\r
+ "FF 02 02 02 02 02 02 02 "\r
- + "FF 02 03 02 03 02 03 02 ");\r
+ + "FF 02 03 02 03 02 03 02");\r
\r
MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);\r
\r
"00 10 " + // length
"00 00 00 00 " + // pad
"00 05 " + // rate
- "00 00 00 00 00 00 " // pad
+ "00 00 00 00 00 00" // pad
);
GetQueueConfigOutput builtByFactory = BufferHelper.deserialize(
Assert.assertArrayEquals(expected, data);
}
-
+
/**
* Test of {@link ByteBufUtils#hexStringToBytes(String, boolean)}
*/
Assert.assertArrayEquals(expected, data);
}
-
+
/**
* Test of {@link ByteBufUtils#hexStringToByteBuf(String)}
*/