2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowjava.protocol.impl.serialization.match;
10 import io.netty.buffer.ByteBuf;
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.List;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17 import org.opendaylight.openflowjava.util.ByteBufUtils;
19 import com.google.common.collect.Lists;
22 * Parent for Ipv6 address based match entry serializers
23 * @author michal.polkorab
25 public abstract class AbstractOxmIpv6AddressSerializer extends AbstractOxmMatchEntrySerializer {
27 protected void writeIpv6Address(String textAddress, final ByteBuf outBuffer) {
29 if (textAddress.equals("::")) {
30 String[] tmp = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];
31 Arrays.fill(tmp, "0");
32 address = Arrays.asList(tmp);
34 address = parseIpv6Address(Lists.newArrayList(ByteBufUtils.COLON_SPLITTER.split(textAddress)));
36 for (String group : address) {
37 outBuffer.writeShort(Integer.parseInt(group, 16));
41 private static List<String> parseIpv6Address(final List<String> addressGroups) {
43 for (String group : addressGroups) {
44 if (group.equals("")) {
48 List<String> ready = new ArrayList<>(EncodeConstants.GROUPS_IN_IPV6_ADDRESS);
51 ready = addressGroups;
54 int zerosToBePushed = EncodeConstants.GROUPS_IN_IPV6_ADDRESS - addressGroups.size() + 1;
55 for (String group : addressGroups) {
56 if (group.equals("")) {
57 for (int j = 0; j < zerosToBePushed; j++) {
66 String[] tmp = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];
67 Arrays.fill(tmp, "0");
68 tmp[EncodeConstants.GROUPS_IN_IPV6_ADDRESS - 1] =
69 addressGroups.get(addressGroups.size() - 1);
70 ready = Arrays.asList(tmp);
73 throw new IllegalStateException("Incorrect ipv6 address");