From b99ff614098c2b3257e38ed693cd3c778bd796a5 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 8 Jan 2021 07:28:23 +0100 Subject: [PATCH] Adapt to OFP's lldp changing LLDP has cleaned up reflection use, adjust to that. Change-Id: Ibceb241c224058106438b127e9e132401dbf14a1 Signed-off-by: Robert Varga --- .../genius/mdsalutil/packet/Ethernet.java | 25 +++++++++---------- .../genius/mdsalutil/packet/IPv4.java | 21 +++++++--------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/packet/Ethernet.java b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/packet/Ethernet.java index 0dac3a1e3..e27f26737 100644 --- a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/packet/Ethernet.java +++ b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/packet/Ethernet.java @@ -5,13 +5,13 @@ * 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.genius.mdsalutil.packet; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Supplier; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.opendaylight.openflowplugin.libraries.liblldp.BitBufferHelper; @@ -31,27 +31,27 @@ public class Ethernet extends Packet { // TODO: This has to be outside and it should be possible for osgi // to add new coming packet classes @SuppressWarnings("checkstyle:ConstantName") // public constant is used in other projects; too late to rename easily - public static final Map> etherTypeClassMap = new ConcurrentHashMap<>(); + public static final Map> etherTypeClassMap = new ConcurrentHashMap<>(); static { - etherTypeClassMap.put(EtherTypes.ARP.shortValue(), ARP.class); - etherTypeClassMap.put(EtherTypes.LLDP.shortValue(), LLDP.class); - etherTypeClassMap.put(EtherTypes.IPv4.shortValue(), IPv4.class); + etherTypeClassMap.put(EtherTypes.ARP.shortValue(), ARP::new); + etherTypeClassMap.put(EtherTypes.LLDP.shortValue(), LLDP::new); + etherTypeClassMap.put(EtherTypes.IPv4.shortValue(), IPv4::new); // TODO: Add support for more classes here - etherTypeClassMap.put(EtherTypes.VLANTAGGED.shortValue(), IEEE8021Q.class); - // etherTypeClassMap.put(EtherTypes.OLDQINQ.shortValue(), IEEE8021Q.class); - // etherTypeClassMap.put(EtherTypes.QINQ.shortValue(), IEEE8021Q.class); - // etherTypeClassMap.put(EtherTypes.CISCOQINQ.shortValue(), IEEE8021Q.class); + etherTypeClassMap.put(EtherTypes.VLANTAGGED.shortValue(), IEEE8021Q::new); + // etherTypeClassMap.put(EtherTypes.OLDQINQ.shortValue(), IEEE8021Q::new); + // etherTypeClassMap.put(EtherTypes.QINQ.shortValue(), IEEE8021Q::new); + // etherTypeClassMap.put(EtherTypes.CISCOQINQ.shortValue(), IEEE8021Q::new); } @SuppressWarnings("serial") - private static Map> fieldCoordinates - = new LinkedHashMap>() { { + private static Map> fieldCoordinates = new LinkedHashMap<>() { { put(DMAC, new ImmutablePair<>(0, 48)); put(SMAC, new ImmutablePair<>(48, 48)); put(ETHT, new ImmutablePair<>(96, 16)); } }; + private final Map fieldValues; /** @@ -78,8 +78,7 @@ public class Ethernet extends Packet { @Override public void setHeaderField(String headerField, byte[] readValue) { if (headerField.equals(ETHT)) { - payloadClass = etherTypeClassMap.get(BitBufferHelper - .getShort(readValue)); + payloadFactory = etherTypeClassMap.get(BitBufferHelper.getShort(readValue)); } hdrFieldsMap.put(headerField, readValue); } diff --git a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/packet/IPv4.java b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/packet/IPv4.java index 5960e68e2..8b5ebd0df 100644 --- a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/packet/IPv4.java +++ b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/packet/IPv4.java @@ -7,11 +7,13 @@ */ package org.opendaylight.genius.mdsalutil.packet; +import com.google.common.collect.ImmutableMap; import java.net.InetAddress; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.ThreadLocalRandom; +import java.util.function.Supplier; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.opendaylight.openflowplugin.libraries.liblldp.BitBufferHelper; @@ -47,18 +49,13 @@ public class IPv4 extends Packet { private static final int UNIT_SIZE = 1 << UNIT_SIZE_SHIFT; private static final int MIN_HEADER_SIZE = 20; - private static final Map> PROTOCOL_CLASS_MAP; - - static { - PROTOCOL_CLASS_MAP = new HashMap<>(); - PROTOCOL_CLASS_MAP.put(IPProtocols.ICMP.byteValue(), ICMP.class); - PROTOCOL_CLASS_MAP.put(IPProtocols.UDP.byteValue(), UDP.class); - PROTOCOL_CLASS_MAP.put(IPProtocols.TCP.byteValue(), TCP.class); - } + private static final Map> PROTOCOL_CLASS_MAP = ImmutableMap.of( + IPProtocols.ICMP.byteValue(), ICMP::new, + IPProtocols.UDP.byteValue(), UDP::new, + IPProtocols.TCP.byteValue(), TCP::new); @SuppressWarnings("serial") - private static final Map> FIELD_COORDINATES - = new LinkedHashMap<>() { { + private static final Map> FIELD_COORDINATES = new LinkedHashMap<>() { { put(VERSION, new ImmutablePair<>(0, 4)); put(HEADERLENGTH, new ImmutablePair<>(4, 4)); put(DIFFSERV, new ImmutablePair<>(8, 6)); @@ -260,13 +257,13 @@ public class IPv4 extends Packet { // Don't set payloadClass if framgment offset is not zero. byte[] fragoff = hdrFieldsMap.get(FRAGOFFSET); if (fragoff == null || BitBufferHelper.getShort(fragoff) == 0) { - payloadClass = PROTOCOL_CLASS_MAP.get(readValue[0]); + payloadFactory = PROTOCOL_CLASS_MAP.get(readValue[0]); } } else if (headerField.equals(FRAGOFFSET)) { if (readValue != null && BitBufferHelper.getShort(readValue) != 0) { // Clear payloadClass because protocol header is not present // in this packet. - payloadClass = null; + payloadFactory = null; } } else if (headerField.equals(OPTIONS) && (readValue == null || readValue.length == 0)) { -- 2.36.6