X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fserialization%2Fmatch%2FAbstractOxmIpv6AddressSerializer.java;h=496505b89cb3e999f04bf25e100997c33a40933e;hb=519a86d1ddcfb8f0fe264174e62e5424e1efba1f;hp=61cea69da2c62aec954b7624b69db0889863ca75;hpb=c4492ffff102a6bf4b4ecc8f10f4babd95303fcb;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmIpv6AddressSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmIpv6AddressSerializer.java index 61cea69d..496505b8 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmIpv6AddressSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/AbstractOxmIpv6AddressSerializer.java @@ -1,83 +1,83 @@ -/* - * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.openflowjava.protocol.impl.serialization.match; - -import io.netty.buffer.ByteBuf; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; - -import com.google.common.collect.Lists; - -/** - * Parent for Ipv6 address based match entry serializers - * @author michal.polkorab - */ -public abstract class AbstractOxmIpv6AddressSerializer extends AbstractOxmMatchEntrySerializer { - - @Override - public void serialize(final MatchEntries entry, final ByteBuf outBuffer) { - super.serialize(entry, outBuffer); - String textAddress = entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address().getValue(); - List address; - if (textAddress.equals("::")) { - String[] tmp = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS]; - Arrays.fill(tmp, "0"); - address = Arrays.asList(tmp); - } else { - address = parseIpv6Address(Lists.newArrayList(ByteBufUtils.COLON_SPLITTER.split(textAddress))); - } - for (String group : address) { - outBuffer.writeShort(Integer.parseInt(group, 16)); - } - writeMask(entry, outBuffer, getValueLength()); - } - - private static List parseIpv6Address(final ArrayList addressGroups) { - int countEmpty = 0; - for (String group : addressGroups) { - if (group.equals("")) { - countEmpty++; - } - } - List ready = new ArrayList<>(EncodeConstants.GROUPS_IN_IPV6_ADDRESS); - switch (countEmpty) { - case 0: - ready = addressGroups; - break; - case 1: - int zerosToBePushed = EncodeConstants.GROUPS_IN_IPV6_ADDRESS - addressGroups.size() + 1; - for (String group : addressGroups) { - if (group.equals("")) { - for (int j = 0; j < zerosToBePushed; j++) { - ready.add("0"); - } - } else { - ready.add(group); - } - } - break; - case 2: - String[] tmp = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS]; - Arrays.fill(tmp, "0"); - tmp[EncodeConstants.GROUPS_IN_IPV6_ADDRESS - 1] = - addressGroups.get(addressGroups.size() - 1); - ready = Arrays.asList(tmp); - break; - default: - throw new IllegalStateException("Incorrect ipv6 address"); - } - return ready; - } -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.openflowjava.protocol.impl.serialization.match; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.opendaylight.openflowjava.util.ByteBufUtils; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; + +import com.google.common.collect.Lists; + +/** + * Parent for Ipv6 address based match entry serializers + * @author michal.polkorab + */ +public abstract class AbstractOxmIpv6AddressSerializer extends AbstractOxmMatchEntrySerializer { + + @Override + public void serialize(final MatchEntries entry, final ByteBuf outBuffer) { + super.serialize(entry, outBuffer); + String textAddress = entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address().getValue(); + List address; + if (textAddress.equals("::")) { + String[] tmp = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS]; + Arrays.fill(tmp, "0"); + address = Arrays.asList(tmp); + } else { + address = parseIpv6Address(Lists.newArrayList(ByteBufUtils.COLON_SPLITTER.split(textAddress))); + } + for (String group : address) { + outBuffer.writeShort(Integer.parseInt(group, 16)); + } + writeMask(entry, outBuffer, getValueLength()); + } + + private static List parseIpv6Address(final List addressGroups) { + int countEmpty = 0; + for (String group : addressGroups) { + if (group.equals("")) { + countEmpty++; + } + } + List ready = new ArrayList<>(EncodeConstants.GROUPS_IN_IPV6_ADDRESS); + switch (countEmpty) { + case 0: + ready = addressGroups; + break; + case 1: + int zerosToBePushed = EncodeConstants.GROUPS_IN_IPV6_ADDRESS - addressGroups.size() + 1; + for (String group : addressGroups) { + if (group.equals("")) { + for (int j = 0; j < zerosToBePushed; j++) { + ready.add("0"); + } + } else { + ready.add(group); + } + } + break; + case 2: + String[] tmp = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS]; + Arrays.fill(tmp, "0"); + tmp[EncodeConstants.GROUPS_IN_IPV6_ADDRESS - 1] = + addressGroups.get(addressGroups.size() - 1); + ready = Arrays.asList(tmp); + break; + default: + throw new IllegalStateException("Incorrect ipv6 address"); + } + return ready; + } +}