2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.openflowjava.protocol.impl.serialization.match;
\r
10 import io.netty.buffer.ByteBuf;
\r
12 import java.util.Arrays;
\r
14 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;
\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
\r
19 * Parent for Ipv6 address based match entry serializers
\r
20 * @author michal.polkorab
\r
22 public abstract class AbstractOxmIpv6AddressSerializer extends AbstractOxmMatchEntrySerializer {
\r
25 public void serialize(MatchEntries entry, ByteBuf outBuffer) {
\r
26 super.serialize(entry, outBuffer);
\r
27 String textAddress = entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address().getValue();
\r
29 if (textAddress.equals("::")) {
\r
30 address = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];
\r
31 Arrays.fill(address, "0");
\r
33 address = parseIpv6Address(textAddress.split(":"));
\r
35 for (int i = 0; i < address.length; i++) {
\r
36 outBuffer.writeShort(Integer.parseInt(address[i], 16));
\r
38 writeMask(entry, outBuffer, getValueLength());
\r
41 private static String[] parseIpv6Address(String[] addressGroups) {
\r
43 for (int i = 0; i < addressGroups.length; i++) {
\r
44 if (addressGroups[i].equals("")){
\r
48 String[] ready = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];
\r
49 switch (countEmpty) {
\r
51 ready = addressGroups;
\r
54 int zerosToBePushed = EncodeConstants.GROUPS_IN_IPV6_ADDRESS - addressGroups.length + 1;
\r
56 for (int i = 0; i < addressGroups.length; i++) {
\r
57 if (addressGroups[i].equals("")) {
\r
58 for (int j = 0; j < zerosToBePushed; j++) {
\r
63 ready[index] = addressGroups[i];
\r
69 Arrays.fill(ready, "0");
\r
70 ready[ready.length - 1] = addressGroups[addressGroups.length - 1];
\r
73 throw new IllegalStateException("Incorrect ipv6 address");
\r