From 49b07d9d643504f2f8d596e207ef4cf4b9ab8946 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Tue, 14 Mar 2017 10:27:48 +0100 Subject: [PATCH] Add arbitrary mask for nxm-reg According to specification, nxm-reg should be fully maskable using arbitrary mask. Resolves: bug 7897 Change-Id: I912017e6bd33813ac65ed5799c8bfa7ebf217889 Signed-off-by: Tomas Slusny (cherry picked from commit 113fc0c316f814452a535a66f0da085076d282b5) --- .../nx/codec/match/AbstractRegCodec.java | 27 +++++++++---- .../src/main/yang/nicira-match.yang | 38 +++++++++++++++++-- .../nicira/convertor/match/RegConvertor.java | 19 ++++++++-- ...openflowplugin-extension-nicira-match.yang | 3 ++ 4 files changed, 71 insertions(+), 16 deletions(-) diff --git a/extension/openflowjava-extension-nicira/src/main/java/org/opendaylight/openflowjava/nx/codec/match/AbstractRegCodec.java b/extension/openflowjava-extension-nicira/src/main/java/org/opendaylight/openflowjava/nx/codec/match/AbstractRegCodec.java index 7ff2cc806a..c186af39b7 100644 --- a/extension/openflowjava-extension-nicira/src/main/java/org/opendaylight/openflowjava/nx/codec/match/AbstractRegCodec.java +++ b/extension/openflowjava-extension-nicira/src/main/java/org/opendaylight/openflowjava/nx/codec/match/AbstractRegCodec.java @@ -25,19 +25,30 @@ public abstract class AbstractRegCodec extends AbstractMatchCodec { @Override public MatchEntry deserialize(ByteBuf message) { - MatchEntryBuilder matchEntriesBuilder = deserializeHeader(message); - RegCaseValueBuilder caseBuilder = new RegCaseValueBuilder(); - caseBuilder.setRegValues(new RegValuesBuilder().setValue(message.readUnsignedInt()).build()); - matchEntriesBuilder.setMatchEntryValue(caseBuilder.build()); - return matchEntriesBuilder.build(); + final MatchEntryBuilder matchEntriesBuilder = deserializeHeader(message); + final RegValuesBuilder regValuesBuilder = new RegValuesBuilder(); + regValuesBuilder.setValue(message.readUnsignedInt()); + + if (matchEntriesBuilder.isHasMask()) { + regValuesBuilder.setMask(message.readUnsignedInt()); + } + + return matchEntriesBuilder + .setMatchEntryValue(new RegCaseValueBuilder() + .setRegValues(regValuesBuilder.build()) + .build()) + .build(); } @Override public void serialize(MatchEntry input, ByteBuf outBuffer) { serializeHeader(input, outBuffer); - RegCaseValue regCase = ((RegCaseValue) input.getMatchEntryValue()); - Long value = regCase.getRegValues().getValue(); - outBuffer.writeInt(value.intValue()); + final RegCaseValue regCase = ((RegCaseValue) input.getMatchEntryValue()); + outBuffer.writeInt(regCase.getRegValues().getValue().intValue()); + + if (input.isHasMask()) { + outBuffer.writeInt(regCase.getRegValues().getMask().intValue()); + } } @Override diff --git a/extension/openflowjava-extension-nicira/src/main/yang/nicira-match.yang b/extension/openflowjava-extension-nicira/src/main/yang/nicira-match.yang index ab902d6e29..e7faa80678 100644 --- a/extension/openflowjava-extension-nicira/src/main/yang/nicira-match.yang +++ b/extension/openflowjava-extension-nicira/src/main/yang/nicira-match.yang @@ -148,14 +148,17 @@ module nicira-match { base ofoxm:match-field; } - grouping ofj-nxm-nx-match-reg-grouping { container reg-values { leaf value { type uint32; } + leaf mask { + type uint32; + } } } + grouping ofj-oxm-of-mpls-label-grouping { container mpls-label-values { leaf mpls-label { @@ -171,6 +174,7 @@ module nicira-match { } } } + grouping ofj-nxm-nx-match-arp-sha-grouping { container arp-sha-values { leaf mac-address { @@ -178,6 +182,7 @@ module nicira-match { } } } + grouping ofj-nxm-nx-match-arp-tha-grouping { container arp-tha-values { leaf mac-address { @@ -185,6 +190,7 @@ module nicira-match { } } } + grouping ofj-nxm-of-match-arp-op-grouping { container arp-op-values { leaf value { @@ -192,6 +198,7 @@ module nicira-match { } } } + grouping ofj-nxm-of-match-arp-spa-grouping { container arp-spa-values { leaf value { @@ -199,6 +206,7 @@ module nicira-match { } } } + grouping ofj-nxm-of-match-arp-tpa-grouping { container arp-tpa-values { leaf value { @@ -206,6 +214,7 @@ module nicira-match { } } } + grouping ofj-nxm-of-in-port-type-grouping { container nxm-of-in-port-values { leaf value { @@ -213,6 +222,7 @@ module nicira-match { } } } + grouping ofj-nxm-nx-match-tun-ipv4-dst-grouping { container tun-ipv4-dst-values { leaf value { @@ -220,6 +230,7 @@ module nicira-match { } } } + grouping ofj-nxm-nx-match-tun-ipv4-src-grouping { container tun-ipv4-src-values { leaf value { @@ -227,6 +238,7 @@ module nicira-match { } } } + grouping ofj-nxm-of-match-eth-src-grouping { container eth-src-values { leaf mac-address { @@ -234,6 +246,7 @@ module nicira-match { } } } + grouping ofj-nxm-of-match-eth-dst-grouping { container eth-dst-values { leaf mac-address { @@ -241,6 +254,7 @@ module nicira-match { } } } + grouping ofj-nxm-of-match-eth-type-grouping { container eth-type-values { leaf value { @@ -276,21 +290,25 @@ module nicira-match { uses ofj-nxm-nx-match-nshc-grouping; } } + grouping ofj-nxm-nx-match-nshc-2-grouping { container nshc-2-values { uses ofj-nxm-nx-match-nshc-grouping; } } + grouping ofj-nxm-nx-match-nshc-3-grouping { container nshc-3-values { uses ofj-nxm-nx-match-nshc-grouping; } } + grouping ofj-nxm-nx-match-nshc-4-grouping { container nshc-4-values { uses ofj-nxm-nx-match-nshc-grouping; } } + grouping ofj-nxm-of-match-tcp-src-grouping { container tcp-src-values { leaf port { @@ -301,6 +319,7 @@ module nicira-match { } } } + grouping ofj-nxm-of-match-tcp-dst-grouping { container tcp-dst-values { leaf port { @@ -311,7 +330,8 @@ module nicira-match { } } } - grouping ofj-nxm-of-match-udp-src-grouping { + + grouping ofj-nxm-of-match-udp-src-grouping { container udp-src-values { leaf port { type inet:port-number; @@ -321,6 +341,7 @@ module nicira-match { } } } + grouping ofj-nxm-of-match-udp-dst-grouping { container udp-dst-values { leaf port { @@ -331,6 +352,7 @@ module nicira-match { } } } + grouping ofj-nxm-nx-match-ct-state-grouping{ container ct-state-values { leaf ct-state { @@ -341,6 +363,7 @@ module nicira-match { } } } + grouping ofj-nxm-nx-match-ct-zone-grouping{ container ct-zone-values { leaf ct-zone { @@ -348,6 +371,7 @@ module nicira-match { } } } + grouping ofj-nxm-of-match-ip-dst-grouping { container ip-dst-values { leaf value { @@ -355,6 +379,7 @@ module nicira-match { } } } + grouping ofj-nxm-of-match-ip-src-grouping { container ip-src-values { leaf value { @@ -362,6 +387,7 @@ module nicira-match { } } } + grouping ofj-nxm-of-match-icmp-type-grouping { container icmp-type-values { leaf value { @@ -369,6 +395,7 @@ module nicira-match { } } } + grouping ofj-nxm-nx-match-encap-eth-type-grouping { container encap-eth-type-values { leaf encap-eth-type { @@ -376,6 +403,7 @@ module nicira-match { } } } + grouping ofj-nxm-nx-match-encap-eth-src-grouping { container encap-eth-src-values { leaf mac-address { @@ -383,6 +411,7 @@ module nicira-match { } } } + grouping ofj-nxm-nx-match-encap-eth-dst-grouping { container encap-eth-dst-values { leaf mac-address { @@ -390,6 +419,7 @@ module nicira-match { } } } + grouping ofj-nxm-nx-match-nsh-mdtype-grouping { container nsh-mdtype-values { leaf value { @@ -397,6 +427,7 @@ module nicira-match { } } } + grouping ofj-nxm-nx-match-nsh-np-grouping { container nsh-np-values { leaf value { @@ -404,6 +435,7 @@ module nicira-match { } } } + grouping ofj-nxm-nx-match-tun-gpe-np-grouping { container tun-gpe-np-values { leaf value { @@ -471,7 +503,6 @@ module nicira-match { case tun-gpe-np-case-value { uses ofj-nxm-nx-match-tun-gpe-np-grouping; } - case eth-type-case-value { uses ofj-nxm-of-match-eth-type-grouping; } @@ -520,7 +551,6 @@ module nicira-match { case icmp-type-case-value { uses ofj-nxm-of-match-icmp-type-grouping; } - } } diff --git a/extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/RegConvertor.java b/extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/RegConvertor.java index 1ba11162db..579def71dd 100644 --- a/extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/RegConvertor.java +++ b/extension/openflowplugin-extension-nicira/src/main/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/match/RegConvertor.java @@ -8,6 +8,7 @@ package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match; import com.google.common.base.Optional; +import java.util.Objects; import org.opendaylight.openflowjava.nx.NiciraMatchCodecs; import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava; import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava; @@ -54,7 +55,7 @@ public class RegConvertor implements ConvertorToOFJava, ConvertorFro /* * (non-Javadoc) - * + * * @see * org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava#convert * (org.opendaylight.yangtools.yang.binding.DataContainer, @@ -77,6 +78,11 @@ public class RegConvertor implements ConvertorToOFJava, ConvertorFro .getOxmMatchField()); RegCaseValue regCaseValue = ((RegCaseValue) input.getMatchEntryValue()); nxRegBuilder.setValue(regCaseValue.getRegValues().getValue()); + + if (input.isHasMask()) { + nxRegBuilder.setMask(regCaseValue.getRegValues().getMask()); + } + return resolveAugmentation(nxRegBuilder.build(), path, resolveRegKey(input.getOxmMatchField())); } @@ -130,7 +136,7 @@ public class RegConvertor implements ConvertorToOFJava, ConvertorFro /* * (non-Javadoc) - * + * * @see * org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava#convert * (org @@ -144,12 +150,17 @@ public class RegConvertor implements ConvertorToOFJava, ConvertorFro throw new CodecPreconditionException(extension); } NxmNxReg nxmNxReg = matchGrouping.get().getNxmNxReg(); - RegValuesBuilder regValuesBuilder = new RegValuesBuilder().setValue(nxmNxReg.getValue()); + RegValuesBuilder regValuesBuilder = new RegValuesBuilder() + .setValue(nxmNxReg.getValue()) + .setMask(nxmNxReg.getMask()); + RegCaseValueBuilder regCaseValueBuilder = new RegCaseValueBuilder(); regCaseValueBuilder.setRegValues(regValuesBuilder.build()); return MatchUtil.createDefaultMatchEntryBuilder(nxmNxReg.getReg(), Nxm1Class.class, - regCaseValueBuilder.build()).build(); + regCaseValueBuilder.build()) + .setHasMask(Objects.nonNull(nxmNxReg.getMask())) + .build(); } } diff --git a/extension/openflowplugin-extension-nicira/src/main/yang/openflowplugin-extension-nicira-match.yang b/extension/openflowplugin-extension-nicira/src/main/yang/openflowplugin-extension-nicira-match.yang index cd4c5890ea..199b94d1ba 100644 --- a/extension/openflowplugin-extension-nicira/src/main/yang/openflowplugin-extension-nicira-match.yang +++ b/extension/openflowplugin-extension-nicira/src/main/yang/openflowplugin-extension-nicira-match.yang @@ -167,6 +167,9 @@ module openflowplugin-extension-nicira-match { leaf value { type uint32; } + leaf mask { + type uint32; + } } } grouping nxm-nx-tun-id-grouping { -- 2.36.6