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.util.ByteBufUtils;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
21 import com.google.common.collect.Lists;
24 * Parent for Ipv6 address based match entry serializers
25 * @author michal.polkorab
27 public abstract class AbstractOxmIpv6AddressSerializer extends AbstractOxmMatchEntrySerializer {
30 public void serialize(final MatchEntries entry, final ByteBuf outBuffer) {
31 super.serialize(entry, outBuffer);
32 String textAddress = entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address().getValue();
34 if (textAddress.equals("::")) {
35 String[] tmp = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];
36 Arrays.fill(tmp, "0");
37 address = Arrays.asList(tmp);
39 address = parseIpv6Address(Lists.newArrayList(ByteBufUtils.COLON_SPLITTER.split(textAddress)));
41 for (String group : address) {
42 outBuffer.writeShort(Integer.parseInt(group, 16));
44 writeMask(entry, outBuffer, getValueLength());
47 private static List<String> parseIpv6Address(final List<String> addressGroups) {
49 for (String group : addressGroups) {
50 if (group.equals("")) {
54 List<String> ready = new ArrayList<>(EncodeConstants.GROUPS_IN_IPV6_ADDRESS);
57 ready = addressGroups;
60 int zerosToBePushed = EncodeConstants.GROUPS_IN_IPV6_ADDRESS - addressGroups.size() + 1;
61 for (String group : addressGroups) {
62 if (group.equals("")) {
63 for (int j = 0; j < zerosToBePushed; j++) {
72 String[] tmp = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];
73 Arrays.fill(tmp, "0");
74 tmp[EncodeConstants.GROUPS_IN_IPV6_ADDRESS - 1] =
75 addressGroups.get(addressGroups.size() - 1);
76 ready = Arrays.asList(tmp);
79 throw new IllegalStateException("Incorrect ipv6 address");