Merge "OPNFLWPLUG-929 : Remove deprecated guava library"
authorAnil Vishnoi <vishnoianil@gmail.com>
Tue, 23 Jan 2018 02:33:23 +0000 (02:33 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 23 Jan 2018 02:33:23 +0000 (02:33 +0000)
121 files changed:
.gitignore
applications/bulk-o-matic/pom.xml
applications/bulk-o-matic/src/main/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/FlowReader.java
applications/bulk-o-matic/src/main/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/FlowWriterSequential.java
applications/forwardingrules-manager/pom.xml
applications/forwardingrules-sync/pom.xml
applications/lldp-speaker/pom.xml
applications/lldp-speaker/src/main/java/org/opendaylight/openflowplugin/applications/lldpspeaker/LLDPSpeaker.java
applications/lldp-speaker/src/main/java/org/opendaylight/openflowplugin/applications/lldpspeaker/LLDPUtil.java
applications/lldp-speaker/src/test/java/org/opendaylight/openflowplugin/applications/lldpspeaker/TestUtils.java
applications/notification-supplier/pom.xml
applications/notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/notification/supplier/NotificationProvider.java
applications/notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/notification/supplier/tools/NotificationProviderConfig.java
applications/notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/notification/supplier/NotificationProviderTest.java
applications/notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/notification/supplier/impl/helper/TestChangeEventBuildHelper.java
applications/notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/notification/supplier/impl/helper/TestSupplierVerifyHelper.java
applications/of-switch-config-pusher/pom.xml
applications/pom.xml
applications/reconciliation-framework/pom.xml
applications/southbound-cli/pom.xml
applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/util/ShellUtil.java
applications/table-miss-enforcer/pom.xml
applications/topology-lldp-discovery/pom.xml
applications/topology-manager/pom.xml
applications/topology-manager/src/main/java/org/opendaylight/openflowplugin/applications/topology/manager/TopologyManagerUtil.java
applications/topology-manager/src/test/java/org/opendaylight/openflowplugin/applications/topology/manager/TestUtils.java
artifacts/pom.xml
distribution/karaf/pom.xml
extension/features-extension-aggregator/features-openflowplugin-extension/pom.xml
extension/features-extension-aggregator/odl-openflowplugin-nxm-extensions/pom.xml
extension/features-extension-aggregator/odl-openflowplugin-onf-extensions/pom.xml
extension/features-extension-aggregator/pom.xml
extension/openflowjava-extension-nicira/pom.xml
extension/openflowplugin-extension-api/pom.xml
extension/openflowplugin-extension-nicira/pom.xml
extension/test-extension/pom.xml
features-aggregator/features-openflowplugin/pom.xml
features-aggregator/odl-openflowplugin-app-bulk-o-matic/pom.xml
features-aggregator/odl-openflowplugin-app-config-pusher/pom.xml
features-aggregator/odl-openflowplugin-app-forwardingrules-manager/pom.xml
features-aggregator/odl-openflowplugin-app-forwardingrules-sync/pom.xml
features-aggregator/odl-openflowplugin-app-notifications/pom.xml
features-aggregator/odl-openflowplugin-app-reconciliation-framework/pom.xml
features-aggregator/odl-openflowplugin-app-southbound-cli/pom.xml
features-aggregator/odl-openflowplugin-app-table-miss-enforcer/pom.xml
features-aggregator/odl-openflowplugin-app-topology/pom.xml
features-aggregator/odl-openflowplugin-drop-test/pom.xml
features-aggregator/odl-openflowplugin-flow-services-rest/pom.xml
features-aggregator/odl-openflowplugin-flow-services/pom.xml
features-aggregator/odl-openflowplugin-nsf-model/pom.xml
features-aggregator/odl-openflowplugin-southbound/pom.xml
features-aggregator/pom.xml
libraries/liblldp/pom.xml [new file with mode: 0644]
libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/BitBufferHelper.java [new file with mode: 0644]
libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/BufferException.java [new file with mode: 0644]
libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/ConstructionException.java [new file with mode: 0644]
libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/CustomTLVKey.java [new file with mode: 0644]
libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/DataLinkAddress.java [new file with mode: 0644]
libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/EtherTypes.java [new file with mode: 0644]
libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/Ethernet.java [new file with mode: 0644]
libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/EthernetAddress.java [new file with mode: 0644]
libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/HexEncode.java [new file with mode: 0644]
libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/LLDP.java [new file with mode: 0644]
libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/LLDPTLV.java [new file with mode: 0644]
libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/NetUtils.java [new file with mode: 0644]
libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/Packet.java [new file with mode: 0644]
libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/PacketException.java [new file with mode: 0644]
libraries/liblldp/src/test/java/org/opendaylight/controller/liblldp/HexEncodeTest.java [new file with mode: 0644]
libraries/liblldp/src/test/java/org/opendaylight/controller/liblldp/LLDPTLVTest.java [new file with mode: 0644]
libraries/liblldp/src/test/java/org/opendaylight/controller/liblldp/LLDPTest.java [new file with mode: 0644]
libraries/liblldp/src/test/java/org/opendaylight/controller/sal/packet/BitBufferHelperTest.java [new file with mode: 0644]
libraries/liblldp/src/test/java/org/opendaylight/controller/sal/packet/address/EthernetAddressTest.java [new file with mode: 0644]
libraries/liblldp/src/test/resources/log4j.xml [new file with mode: 0644]
model/pom.xml
openflowjava/features-openflowjava-aggregator/features-openflowjava/pom.xml
openflowjava/features-openflowjava-aggregator/odl-openflowjava-protocol/pom.xml
openflowjava/features-openflowjava-aggregator/pom.xml
openflowjava/openflow-protocol-api/pom.xml
openflowjava/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionConfiguration.java
openflowjava/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/SerializerRegistry.java
openflowjava/openflow-protocol-impl/pom.xml
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderFactoryImpl.java
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/MessageFactoryInitializer.java
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializerRegistryImpl.java
openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionConfigurationImpl.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImpl02Test.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImplTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java
openflowjava/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/IntegrationTest.java
openflowjava/openflow-protocol-spi/pom.xml
openflowjava/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java
openflowjava/openflow-protocol-spi/src/main/yang/openflow-switch-connection-config.yang
openflowjava/openflowjava-blueprint-config/src/main/resources/initial/default-openflow-connection-config.xml
openflowjava/openflowjava-blueprint-config/src/main/resources/initial/legacy-openflow-connection-config.xml
openflowjava/pom.xml
openflowplugin-api/pom.xml
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/ConnectionContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/HandshakeManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/lifecycle/ContextChainImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/MessageSerializerInjector.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/SerializerInjector.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/protocol/serialization/messages/GroupMessageSerializer.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/common/MultipartRequestInputFactoryTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/karaf/ClearStatsCommandProviderTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/protocol/serialization/AbstractSerializerTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/registry/flow/DeviceFlowRegistryImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatServiceTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/translator/PacketReceivedTranslatorTest.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/extension/RegistrationCloser.java
parent/pom.xml
test-provider/pom.xml

index af1fb3cfea12caf0dcbb9d6bdbd8445405cc21a9..af2cea949ae20c3206397a2c5a09fb844973d23c 100644 (file)
@@ -30,3 +30,4 @@ maven-metadata-local.xml
 nbactions.xml
 nb-configuration.xml
 .fbExcludeFilterFile
+.factorypath
index 8fb01faa1f1f0d06e422605b9022c7356c1f124c..ddd3a7c07be164093fa031925c63e6b49c16cd9b 100644 (file)
 
   <build>
     <plugins>
-      <plugin>
-        <groupId>org.opendaylight.yangtools</groupId>
-        <artifactId>yang-maven-plugin</artifactId>
-      </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-checkstyle-plugin</artifactId>
index de5f8952a4274e27dab4fa4186a662a202b458fd..9968f4e0b1bb44583d4d002b1a0ef9b1b08ecafd 100644 (file)
@@ -63,14 +63,14 @@ public final class FlowReader implements Runnable, FlowCounterMBean {
 
     @Override
     public void run() {
-        readFlowsX(dpnCount, flowsPerDpn, verbose);
+        readFlowsX();
     }
 
-    private void readFlowsX(Integer dpnCount, Integer flowsPerDPN, boolean verbose) {
+    private void readFlowsX() {
         readOpStatus.set(FlowCounter.OperationStatus.IN_PROGRESS.status());
         for (int i = 1; i <= dpnCount; i++) {
             String dpId = BulkOMaticUtils.DEVICE_TYPE_PREFIX + i;
-            for (int j = 0; j < flowsPerDPN; j++) {
+            for (int j = 0; j < flowsPerDpn; j++) {
                 short tableRollover = (short) (endTableId - startTableId + 1);
                 short tableId = (short) (j % tableRollover + startTableId);
 
index bc10525785de7b53e3674ec525bc7d98a06d2bb2..7e8fe0009fab658b03f81e8f2ae3379d13100036 100644 (file)
@@ -39,24 +39,24 @@ public class FlowWriterSequential implements FlowCounterMBean {
         LOG.info("Using Sequential implementation of Flow Writer.");
     }
 
-    public void addFlows(Integer dpnCount, Integer flowsPerDPN, int batchSize, int sleepMillis, short startTableId,
+    public void addFlows(Integer count, Integer flowsPerDPN, int batchSize, int sleepMillis, short startTableId,
             short endTableId, boolean isCreateParents) {
         LOG.info("Using Sequential implementation of Flow Writer.");
-        this.dpnCount = dpnCount;
-        countDpnWriteCompletion.set(dpnCount);
+        this.dpnCount = count;
+        countDpnWriteCompletion.set(count);
         startTime = System.nanoTime();
-        for (int i = 1; i <= dpnCount; i++) {
+        for (int i = 1; i <= count; i++) {
             FlowHandlerTask task = new FlowHandlerTask(Integer.toString(i), flowsPerDPN, true, batchSize, sleepMillis,
                     startTableId, endTableId, isCreateParents);
             flowPusher.execute(task);
         }
     }
 
-    public void deleteFlows(Integer dpnCount, Integer flowsPerDPN, int batchSize, short startTableId,
+    public void deleteFlows(Integer count, Integer flowsPerDPN, int batchSize, short startTableId,
             short endTableId) {
         LOG.info("Using Sequential implementation of Flow Writer.");
-        countDpnWriteCompletion.set(dpnCount);
-        for (int i = 1; i <= dpnCount; i++) {
+        countDpnWriteCompletion.set(count);
+        for (int i = 1; i <= count; i++) {
             FlowHandlerTask task = new FlowHandlerTask(Integer.toString(i), flowsPerDPN, false, batchSize, 0,
                     startTableId, endTableId, false);
             flowPusher.execute(task);
index 9daf04c9c34fe557eea7db59d8546e5a19baf44e..73086738522c4fbbffbdd4df5ddae7db8e4b8fec 100644 (file)
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
       </plugin>
-      <plugin>
-        <groupId>org.opendaylight.yangtools</groupId>
-        <artifactId>yang-maven-plugin</artifactId>
-      </plugin>
-      <plugin>
-        <groupId>org.opendaylight.yangtools</groupId>
-        <artifactId>yang-maven-plugin</artifactId>
-      </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-checkstyle-plugin</artifactId>
index 1e835fdd27b75913e732417b87128248fdb70528..ba636dd3d8be5f823e67c1e199d0ca5cd9997a1b 100644 (file)
@@ -92,7 +92,7 @@
         </dependency>
 
         <dependency>
-            <groupId>org.codehaus.sonar-plugins.java</groupId>
+            <groupId>org.sonarsource.java</groupId>
             <artifactId>sonar-jacoco-listeners</artifactId>
             <version>${sonar-jacoco-listeners.version}</version>
             <scope>test</scope>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
             </plugin>
-            <plugin>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-            </plugin>
         </plugins>
     </build>
 
index e13121cb6046275bf1281e662b6d6571dce70429..67119e81e72fca591cdf1c8277aa9ceace319383 100644 (file)
                     <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
                 </configuration>
             </plugin>
-            <plugin>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-            </plugin>
         </plugins>
     </build>
 </project>
index 14d82dd220e1c25a7791fdba8fa16d0176137eef..e0684923749c5f41db173fba71adb261629a12fb 100644 (file)
@@ -110,9 +110,6 @@ public class LLDPSpeaker implements AutoCloseable, NodeConnectorEventsObserver,
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public void nodeConnectorAdded(final InstanceIdentifier<NodeConnector> nodeConnectorInstanceId,
                                    final FlowCapableNodeConnector flowConnector) {
@@ -154,9 +151,6 @@ public class LLDPSpeaker implements AutoCloseable, NodeConnectorEventsObserver,
         packetProcessingService.transmitPacket(packet);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     public void nodeConnectorRemoved(final InstanceIdentifier<NodeConnector> nodeConnectorInstanceId) {
         nodeConnectorMap.remove(nodeConnectorInstanceId);
index 8373d97338d580333294c341a8922eaa1282327a..0966303200bb058382bce2533b608fb2941be270 100644 (file)
@@ -33,6 +33,9 @@ public final class LLDPUtil {
     private static final Logger LOG = LoggerFactory.getLogger(LLDPUtil.class);
     private static final String OF_URI_PREFIX = "openflow:";
 
+    private LLDPUtil() {
+    }
+
     static byte[] buildLldpFrame(final NodeId nodeId, final NodeConnectorId nodeConnectorId, final MacAddress src,
                                  final Long outPortNo, final MacAddress destinationAddress) {
         // Create discovery pkt
index e6ab666b65a0405e66194ed651f3d943068cf00c..a36bdb5010f56ce047266361fed2d1203b09e440 100644 (file)
@@ -25,7 +25,10 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 /**
  * Helper methods that are used by multiple tests.
  */
-public class TestUtils {
+public final class TestUtils {
+    private TestUtils() {
+    }
+
     static InstanceIdentifier<NodeConnector> createNodeConnectorId(String nodeKey, String nodeConnectorKey) {
         return InstanceIdentifier.builder(Nodes.class)
                 .child(Node.class, new NodeKey(new NodeId(nodeKey)))
index d46a1aa522f8ae645c7d283102a481b098ad0e00..1c17367dade4e45fd5091444308494a02ba6d52b 100644 (file)
                     <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
                 </configuration>
             </plugin>
-            <plugin>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-            </plugin>
         </plugins>
     </build>
 </project>
index 496d6741eeeff8286d3ce8f5ca403570dbb01c2b..6432c98f06e60d5a3e13f70fb5acee5420b9444a 100644 (file)
@@ -113,25 +113,26 @@ public class NotificationProvider implements AutoCloseable {
     /**
      * Method to initialize NotificationProviderConfig.
      */
-    private NotificationProviderConfig initializeNotificationProviderConfig(boolean flowSupp, boolean meterSupp,
-                                                                            boolean groupSupp,
-                                                                            boolean connectorStatSupp,
-                                                                            boolean flowStatSupp,
-                                                                            boolean flowTableStatSupp,
-                                                                            boolean meterStatSupp,
-                                                                            boolean groupStatSupp,
-                                                                            boolean queueStatSupp) {
+    private NotificationProviderConfig initializeNotificationProviderConfig(boolean hasFlowSupp,
+                                                                            boolean hasMeterSupp,
+                                                                            boolean hasGroupSupp,
+                                                                            boolean hasConnectorStatSupp,
+                                                                            boolean hasFlowStatSupp,
+                                                                            boolean hasFlowTableStatSupp,
+                                                                            boolean hasMeterStatSupp,
+                                                                            boolean hasGroupStatSupp,
+                                                                            boolean hasQueueStatSupp) {
         NotificationProviderConfig.NotificationProviderConfigBuilder notif
                 = new NotificationProviderConfig.NotificationProviderConfigBuilder();
-        notif.setFlowSupport(flowSupp);
-        notif.setMeterSupport(meterSupp);
-        notif.setGroupSupport(groupSupp);
-        notif.setNodeConnectorStatSupport(connectorStatSupp);
-        notif.setFlowStatSupport(flowStatSupp);
-        notif.setFlowTableStatSupport(flowTableStatSupp);
-        notif.setMeterStatSupport(meterStatSupp);
-        notif.setGroupStatSupport(groupStatSupp);
-        notif.setQueueStatSupport(queueStatSupp);
+        notif.setFlowSupport(hasFlowSupp);
+        notif.setMeterSupport(hasMeterSupp);
+        notif.setGroupSupport(hasGroupSupp);
+        notif.setNodeConnectorStatSupport(hasConnectorStatSupp);
+        notif.setFlowStatSupport(hasFlowStatSupp);
+        notif.setFlowTableStatSupport(hasFlowTableStatSupp);
+        notif.setMeterStatSupport(hasMeterStatSupp);
+        notif.setGroupStatSupport(hasGroupStatSupp);
+        notif.setQueueStatSupport(hasQueueStatSupp);
         return notif.build();
     }
 
index ef926439969ec6ec3c72bfc2e9d81c3c72996a63..f5c34558a5e3ec501ea4c3c9bc8718b4efd9cd60 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.openflowplugin.applications.notification.supplier.tools
 /**
  * Class is designed as ConfigSubsystem settings holder.
  */
-public class NotificationProviderConfig {
+public final class NotificationProviderConfig {
 
     private final boolean flowSupport;
     private final boolean meterSupport;
index bb2b976858f9ba3fb921be045c6c228b83443fa6..8d39252a35fc2032c8e84db37cc58da524d50655 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.openflowplugin.applications.notification.supplier.tools.
 public class NotificationProviderTest {
 
     private NotificationProviderService notificationProviderService;
-    private NotificationProviderConfig config;
     private DataBroker dataBroker;
 
     @Before
@@ -32,26 +31,22 @@ public class NotificationProviderTest {
     }
 
     @Test
-    public void testCreateAllSuppliers() {
+    public void testCreateAllSuppliers() throws Exception {
         final NotificationProviderConfig config = createAllConfigSupplier();
-        final NotificationProvider provider = new NotificationProvider(notificationProviderService, dataBroker,
-                                                                       config.isFlowSupport(), config.isMeterSupport(),
-                                                                       config.isGroupSupport(),
-                                                                       config.isNodeConnectorStatSupport(),
-                                                                       config.isFlowStatSupport(),
-                                                                       config.isFlowTableStatSupport(),
-                                                                       config.isMeterStatSupport(),
-                                                                       config.isGroupStatSupport(),
-                                                                       config.isQueueStatSupport());
-        provider.start();
-        final List<NotificationSupplierDefinition<?>> listSuppliers = provider.getSupplierList();
-        int nrOfSuppliers = 0;
-        for (final NotificationSupplierDefinition<?> supplier : listSuppliers) {
-            if (supplier != null) {
-                nrOfSuppliers++;
+        try (NotificationProvider provider = new NotificationProvider(notificationProviderService, dataBroker,
+                config.isFlowSupport(), config.isMeterSupport(), config.isGroupSupport(),
+                config.isNodeConnectorStatSupport(), config.isFlowStatSupport(), config.isFlowTableStatSupport(),
+                config.isMeterStatSupport(), config.isGroupStatSupport(), config.isQueueStatSupport())) {
+            provider.start();
+            final List<NotificationSupplierDefinition<?>> listSuppliers = provider.getSupplierList();
+            int nrOfSuppliers = 0;
+            for (final NotificationSupplierDefinition<?> supplier : listSuppliers) {
+                if (supplier != null) {
+                    nrOfSuppliers++;
+                }
             }
+            assertEquals(11, nrOfSuppliers);
         }
-        assertEquals(11, nrOfSuppliers);
     }
 
     @Test
index 7200d6cb682bb94f05fbe4e5e13c5a19083f3cff..19976b34e18c439e6dcae8307af5b367689e25d6 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.openflowplugin.applications.notification.supplier.impl.
 import java.util.Collection;
 import java.util.Collections;
 
-public class TestChangeEventBuildHelper {
+public final class TestChangeEventBuildHelper {
 
     private TestChangeEventBuildHelper() {
         throw new UnsupportedOperationException("Test utility class");
index 0e801b4336dc55d4e9b58f41c8a50385bcd4a164..adba9bf4fc92984c3b8baa8da04fe44be4564a3d 100644 (file)
@@ -14,7 +14,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 
-public class TestSupplierVerifyHelper {
+public final class TestSupplierVerifyHelper {
 
     private TestSupplierVerifyHelper() {
         throw new UnsupportedOperationException("Test utility class");
index 1340faabd157c11e8bf596da73ce2ee4a4705fe3..8451968a54e1b6d77f71cd1fd01e9ca9cf84a6fc 100644 (file)
             <scope>test</scope>
         </dependency>
     </dependencies>
-    
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-            </plugin>
-        </plugins>
-    </build>
 </project>
index fb20896803fe29cefb3698438c0e5e54ddb18dfd..aa80e136118c629df2cdfc905833918c386c1dea 100644 (file)
     <packaging>pom</packaging>
 
     <build>
-        <pluginManagement>
-            <plugins>
-                <plugin>
-                    <groupId>org.opendaylight.yangtools</groupId>
-                    <artifactId>yang-maven-plugin</artifactId>
-                    <executions>
-                        <execution>
-                            <goals>
-                                <goal>generate-sources</goal>
-                            </goals>
-                            <configuration>
-                                <codeGenerators>
-                                    <generator>
-                                        <codeGeneratorClass>
-                                            org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl
-                                        </codeGeneratorClass>
-                                        <outputBaseDir>${project.build.directory}/generated-sources/sal</outputBaseDir>
-                                    </generator>
-                                </codeGenerators>
-                                <inspectDependencies>true</inspectDependencies>
-                            </configuration>
-                        </execution>
-                    </executions>
-                    <dependencies>
-                        <dependency>
-                            <groupId>org.opendaylight.mdsal</groupId>
-                            <artifactId>maven-sal-api-gen-plugin</artifactId>
-                            <version>${mdsal.model.version}</version>
-                            <type>jar</type>
-                        </dependency>
-                    </dependencies>
-                </plugin>
-            </plugins>
-        </pluginManagement>
         <plugins>
             <plugin>
                 <groupId>org.apache.felix</groupId>
index 000f66f6b6b5b2e0db45c05b15f092ce177634a3..a592a8060476a1d9ef818bcba21f40e09f66bacf 100644 (file)
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
             </plugin>
-            <plugin>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-            </plugin>
         </plugins>
     </build>
 
index 0de3fb14ec65c2694cf1fb79862bfe08c4d29090..f458a1ba830043b39d86f20b90bbe72fdb06c489 100644 (file)
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
             </plugin>
-            <plugin>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-            </plugin>
         </plugins>
     </build>
 
index fcd851b1be42c4039697386e6b8e710f6af1f056..0da9d0d4541e49055f29fe779d15913db23369ae 100644 (file)
@@ -30,11 +30,14 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ShellUtil {
+public final class ShellUtil {
     private static final Logger LOG = LoggerFactory.getLogger(ShellUtil.class);
 
     public static final String NODE_PREFIX = "openflow:";
 
+    private ShellUtil() {
+    }
+
     public static List<OFNode> getAllNodes(final DataBroker broker) {
         List<Node> nodes = null;
         ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
@@ -138,4 +141,4 @@ public class ShellUtil {
         }
         return ofNode;
     }
-}
\ No newline at end of file
+}
index 40c3f77624902b133b3ad90c1df31ea8b104a852..6dba8a7aad19415528df43381ede00e49bdc9b3c 100644 (file)
                  <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
              </configuration>
          </plugin>
-         <plugin>
-             <groupId>org.opendaylight.yangtools</groupId>
-             <artifactId>yang-maven-plugin</artifactId>
-         </plugin>
      </plugins>
     </build>
 </project>
index 16131488e9c036eb1845f97b6db82ae282232abc..4d7ca1b4cd512f3e9cc32dc719e0c7dd75b70d8a 100644 (file)
@@ -2,35 +2,16 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
-    <groupId>org.opendaylight.mdsal</groupId>
-    <artifactId>binding-parent</artifactId>
-    <version>0.12.0-SNAPSHOT</version>
-    <relativePath/>
+    <groupId>org.opendaylight.openflowplugin</groupId>
+    <artifactId>openflowplugin-parent</artifactId>
+    <version>0.6.0-SNAPSHOT</version>
+    <relativePath>../../parent</relativePath>
   </parent>
   <groupId>org.opendaylight.openflowplugin.applications</groupId>
   <artifactId>topology-lldp-discovery</artifactId>
   <version>0.6.0-SNAPSHOT</version>
   <packaging>bundle</packaging>
 
-  <dependencyManagement>
-    <dependencies>
-      <dependency>
-        <groupId>org.opendaylight.openflowplugin</groupId>
-        <artifactId>openflowplugin-artifacts</artifactId>
-        <version>${project.version}</version>
-        <type>pom</type>
-        <scope>import</scope>
-      </dependency>
-      <dependency>
-        <groupId>org.opendaylight.controller</groupId>
-        <artifactId>mdsal-artifacts</artifactId>
-        <version>1.7.0-SNAPSHOT</version>
-        <type>pom</type>
-        <scope>import</scope>
-      </dependency>
-    </dependencies>
-  </dependencyManagement>
-
   <dependencies>
     <dependency>
       <groupId>com.google.guava</groupId>
index cf9304b513f4b167c6f84b690aa7ed7fb6a89ed7..257562a57568fb856cc4767fd7d6c76d22c10a77 100644 (file)
@@ -2,35 +2,16 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
-    <groupId>org.opendaylight.mdsal</groupId>
-    <artifactId>binding-parent</artifactId>
-    <version>0.12.0-SNAPSHOT</version>
-    <relativePath/>
+    <groupId>org.opendaylight.openflowplugin</groupId>
+    <artifactId>openflowplugin-parent</artifactId>
+    <version>0.6.0-SNAPSHOT</version>
+    <relativePath>../../parent</relativePath>
   </parent>
   <groupId>org.opendaylight.openflowplugin.applications</groupId>
   <artifactId>topology-manager</artifactId>
   <version>0.6.0-SNAPSHOT</version>
   <packaging>bundle</packaging>
 
-  <dependencyManagement>
-    <dependencies>
-      <dependency>
-        <groupId>org.opendaylight.openflowplugin</groupId>
-        <artifactId>openflowplugin-artifacts</artifactId>
-        <version>${project.version}</version>
-        <type>pom</type>
-        <scope>import</scope>
-      </dependency>
-      <dependency>
-        <groupId>org.opendaylight.controller</groupId>
-        <artifactId>mdsal-artifacts</artifactId>
-        <version>1.7.0-SNAPSHOT</version>
-        <type>pom</type>
-        <scope>import</scope>
-      </dependency>
-    </dependencies>
-  </dependencyManagement>
-
   <dependencies>
     <dependency>
       <groupId>com.google.guava</groupId>
           <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
         </configuration>
       </plugin>
-      <plugin>
-        <groupId>org.opendaylight.yangtools</groupId>
-        <artifactId>yang-maven-plugin</artifactId>
-      </plugin>
     </plugins>
   </build>
 
index 25de9159b262543e3a9608a5387b9785b6805fc3..bc2fb8a994f9579c1611903f814ce00ef7a6402c 100644 (file)
@@ -21,7 +21,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-class TopologyManagerUtil {
+final class TopologyManagerUtil {
 
     private static final Logger LOG = LoggerFactory.getLogger(TopologyManagerUtil.class);
 
index 93dcc0daf87e6e429903f7cc4b7a618fb6888530..38e8b72afb02c68d02a6baeb6ce2cb92bb44ac18 100644 (file)
@@ -18,7 +18,6 @@ import static org.mockito.Mockito.inOrder;
 import static org.mockito.Mockito.never;
 
 import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.SettableFuture;
 import com.google.common.util.concurrent.Uninterruptibles;
@@ -28,11 +27,8 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import org.mockito.ArgumentCaptor;
 import org.mockito.InOrder;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
@@ -49,7 +45,10 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 
-public class TestUtils {
+public final class TestUtils {
+    private TestUtils() {
+    }
+
     static void verifyMockTx(ReadWriteTransaction mockTx) {
         InOrder inOrder = inOrder(mockTx);
         inOrder.verify(mockTx, atLeast(0)).submit();
@@ -88,12 +87,9 @@ public class TestUtils {
 
     static CountDownLatch setupStubbedSubmit(ReadWriteTransaction mockTx) {
         final CountDownLatch latch = new CountDownLatch(1);
-        doAnswer(new Answer<CheckedFuture<Void, TransactionCommitFailedException>>() {
-            @Override
-            public CheckedFuture<Void, TransactionCommitFailedException> answer(InvocationOnMock invocation) {
-                latch.countDown();
-                return Futures.immediateCheckedFuture(null);
-            }
+        doAnswer(invocation -> {
+            latch.countDown();
+            return Futures.immediateCheckedFuture(null);
         }).when(mockTx).submit();
 
         return latch;
@@ -102,12 +98,9 @@ public class TestUtils {
     @SuppressWarnings("rawtypes")
     static void setupStubbedDeletes(ReadWriteTransaction mockTx, ArgumentCaptor<InstanceIdentifier> deletedLinkIDs,
                                     final CountDownLatch latch) {
-        doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(InvocationOnMock invocation) {
-                latch.countDown();
-                return null;
-            }
+        doAnswer(invocation -> {
+            latch.countDown();
+            return null;
         }).when(mockTx).delete(eq(LogicalDatastoreType.OPERATIONAL), deletedLinkIDs.capture());
     }
 
index c194959b72dbe8819e6822f8101540a976ced4d5..ea271f9b00b4506e5d6f52b94c868cc104088ade 100644 (file)
@@ -13,7 +13,7 @@
   <parent>
     <groupId>org.opendaylight.odlparent</groupId>
     <artifactId>odlparent-lite</artifactId>
-    <version>2.0.5</version>
+    <version>3.0.2</version>
     <relativePath/>
   </parent>
 
index e412f6f4784db6d800e7bcbbd86d8370abd7286b..f4aba67b5e363e841fc38df2d9e2c18c661deae9 100644 (file)
@@ -4,7 +4,7 @@
   <parent>
     <groupId>org.opendaylight.odlparent</groupId>
     <artifactId>karaf4-parent</artifactId>
-    <version>2.0.5</version>
+    <version>3.0.2</version>
   </parent>
   <groupId>org.opendaylight.openflowplugin</groupId>
   <artifactId>openflowplugin-karaf</artifactId>
index 8607899d831d50c55e43df5152b3db7534bf28d8..4cff693461d3284fdf63dfafea5cc2aed0578cb3 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>feature-repo-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 4f36c0dd442dbaa2a278a603eb11d37f768a7ad7..dd8f9d023042db6edd9831fc100da1d2244f2160 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 3f8c7ebcd252f65007ce1fbd75779e4811deeddc..cc6d90cc67a2b8d609191a18756d6ff6fef25962 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 03e3af44ea58c9b972498805cf6d7591dadbc61e..8174c186b10e5064756989c967302a642acc5276 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>odlparent-lite</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
     <modelVersion>4.0.0</modelVersion>
index c836c9d2b3848f06d0f7ea262863d143cf874941..a36d8cb75c998ec9e4dfb9f5324abae343e4ec3c 100644 (file)
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
             </plugin>
-
-            <plugin>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>generate-sources</goal>
-                        </goals>
-                        <configuration>
-                            <codeGenerators>
-                                <generator>
-                                    <codeGeneratorClass>
-                                        org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl
-                                    </codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/generated-sources/sal</outputBaseDir>
-                                </generator>
-                                <generator>
-                                    <codeGeneratorClass>org.opendaylight.mdsal.binding.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/site/models</outputBaseDir>
-                                </generator>
-                            </codeGenerators>
-                            <inspectDependencies>true</inspectDependencies>
-                        </configuration>
-                    </execution>
-                </executions>
-                <dependencies>
-                    <dependency>
-                        <groupId>org.opendaylight.mdsal</groupId>
-                        <artifactId>maven-sal-api-gen-plugin</artifactId>
-                        <version>${mdsal.model.version}</version>
-                        <type>jar</type>
-                    </dependency>
-                </dependencies>
-            </plugin>
         </plugins>
     </build>
 
index 81308e9e945cd6b778b398f8522a0dd3b31af7e9..97739a9d40c960ed73974c0cdbe593d94fe8be09 100644 (file)
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
             </plugin>
-
-            <plugin>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>generate-sources</goal>
-                        </goals>
-                        <configuration>
-                            <codeGenerators>
-                                <generator>
-                                    <codeGeneratorClass>
-                                        org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl
-                                    </codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/generated-sources/sal</outputBaseDir>
-                                </generator>
-                                <generator>
-                                    <codeGeneratorClass>org.opendaylight.mdsal.binding.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/site/models</outputBaseDir>
-                                </generator>
-                            </codeGenerators>
-                            <inspectDependencies>true</inspectDependencies>
-                        </configuration>
-                    </execution>
-                </executions>
-                <dependencies>
-                    <dependency>
-                        <groupId>org.opendaylight.mdsal</groupId>
-                        <artifactId>maven-sal-api-gen-plugin</artifactId>
-                        <version>${mdsal.model.version}</version>
-                        <type>jar</type>
-                    </dependency>
-                </dependencies>
-            </plugin>
         </plugins>
     </build>
 
index 554654a178300b5a28ef1379faa5104489572e21..38e6c1f9777d57fc44b3c486543fb5b778454f25 100644 (file)
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
             </plugin>
-
-            <plugin>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>generate-sources</goal>
-                        </goals>
-                        <configuration>
-                            <codeGenerators>
-                                <generator>
-                                    <codeGeneratorClass>
-                                        org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl
-                                    </codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/generated-sources/sal</outputBaseDir>
-                                </generator>
-                                <generator>
-                                    <codeGeneratorClass>org.opendaylight.mdsal.binding.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/site/models</outputBaseDir>
-                                </generator>
-                            </codeGenerators>
-                            <inspectDependencies>true</inspectDependencies>
-                        </configuration>
-                    </execution>
-                </executions>
-                <dependencies>
-                    <dependency>
-                        <groupId>org.opendaylight.mdsal</groupId>
-                        <artifactId>maven-sal-api-gen-plugin</artifactId>
-                        <version>${mdsal.model.version}</version>
-                        <type>jar</type>
-                    </dependency>
-                </dependencies>
-            </plugin>
         </plugins>
     </build>
 
index 8d75e53413b8e47cc6be7d94f248c15ab5dde079..190ea88f3a529c5d47987045c1572db47fd67f11 100644 (file)
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
             </plugin>
-
-            <plugin>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>generate-sources</goal>
-                        </goals>
-                        <configuration>
-                            <codeGenerators>
-                                <generator>
-                                    <codeGeneratorClass>
-                                        org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl
-                                    </codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/generated-sources/sal</outputBaseDir>
-                                </generator>
-                                <generator>
-                                    <codeGeneratorClass>org.opendaylight.mdsal.binding.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/site/models</outputBaseDir>
-                                </generator>
-                            </codeGenerators>
-                            <inspectDependencies>true</inspectDependencies>
-                        </configuration>
-                    </execution>
-                </executions>
-                <dependencies>
-                    <dependency>
-                        <groupId>org.opendaylight.mdsal</groupId>
-                        <artifactId>maven-sal-api-gen-plugin</artifactId>
-                        <version>${mdsal.model.version}</version>
-                        <type>jar</type>
-                    </dependency>
-                </dependencies>
-            </plugin>
         </plugins>
     </build>
 
index 7dfa420c08a553e462fb526aec94c7615b823e92..416f962518ef0106aa2e121934123343e5f96891 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>feature-repo-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 29280fac987d5ac4012e464430041fd1a9795dd2..90cbe1ddc977e0443f9fc75915e722f3cc35272e 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 1bdddb921914274481431ee2a3bd72f5f1f372d2..e589a4952b1534cc571fc219624175fda636f20b 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 36339c23a5ec1136132f2fb71d625a74021aabb8..8fa1c7739da6dc60e972c5cbe374122f62cd7001 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 4316d9f8fb2b9e8f4919d95794b915d301e53bb5..914c4adfab880d419caf00ecfc3c0e86358ad6f9 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index fc3730a23f2d2a6de62a74c36a33f1dd5ad3ef55..b8f9edcb4a270037c5bad54f179c3e8df16a035d 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 579a677550f8ec78f26ea15c6fb316bba7da8757..38685f985b3a2c53a79585ea4845fdee05a46f8b 100644 (file)
@@ -5,7 +5,7 @@
 <parent>
     <groupId>org.opendaylight.odlparent</groupId>
     <artifactId>single-feature-parent</artifactId>
-    <version>2.0.5</version>
+    <version>3.0.2</version>
     <relativePath/>
 </parent>
 
index 042e15d58264b97ac7c8eac2f3d1770b1981936b..f2553efe03dd3e9c32ee1281f90bedb13f59b32e 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 11b82f111f6831dcd697b37ba66789a009228059..03e1ae0215fd15bba50fc65a4da39973e5177bbf 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 3852d7639029d9c427964420a2130b633faf10be..4d4008b13e32788e94f015a34f851fd509f5c6c1 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 42deb1bd43b0183bf38fafc86db90944d1580aa6..c5d5377d51b1245e5a2c3caed28bc2bdb150ef54 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 31b7697f2f0958331b90c3f1e220682802266232..8c0b9b0859a883999f2dbf7a46652ec2ecbe73e2 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 916b4e55963ef7b9a7386890ecb414bdf47c37b5..645fcfb3cc72e089bfcbf0b6d108ede19002b9b8 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 4971d280e269e1cfa31602f7c52bfddf2be2ee94..58c307603d2b817f697032861ca9bd191255a83a 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index 2a6c089e15c7ff2ef846109253c122be190fe690..f4dc0cbe08f839fe5d0fe2b73da123deaf5869f6 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
index c87ad97db858242e8cc80fef71e1a577caafd838..4924218828b08519fd0fc91c3a7eda4c1c13386f 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>odlparent-lite</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
diff --git a/libraries/liblldp/pom.xml b/libraries/liblldp/pom.xml
new file mode 100644 (file)
index 0000000..ccb265a
--- /dev/null
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.opendaylight.odlparent</groupId>
+    <artifactId>bundle-parent</artifactId>
+    <version>3.0.2</version>
+    <relativePath/>
+  </parent>
+
+  <groupId>org.opendaylight.controller</groupId>
+  <artifactId>liblldp</artifactId>
+  <version>0.14.0-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Export-Package>
+              org.opendaylight.controller.liblldp</Export-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <scm>
+    <connection>scm:git:http://git.opendaylight.org/gerrit/controller.git</connection>
+    <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
+    <tag>HEAD</tag>
+    <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main</url>
+  </scm>
+</project>
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/BitBufferHelper.java b/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/BitBufferHelper.java
new file mode 100644 (file)
index 0000000..a184d40
--- /dev/null
@@ -0,0 +1,669 @@
+/*
+ * Copyright (c) 2013, 2017 Cisco Systems, Inc. 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.controller.liblldp;
+
+import java.util.Arrays;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * BitBufferHelper class that provides utility methods to - fetch specific bits
+ * from a serialized stream of bits - convert bits to primitive data type - like
+ * short, int, long - store bits in specified location in stream of bits -
+ * convert primitive data types to stream of bits.
+ */
+public abstract class BitBufferHelper {
+    protected static final Logger LOG = LoggerFactory.getLogger(BitBufferHelper.class);
+
+    public static final long ByteMask = 0xFF;
+
+    // Getters
+    // data: array where data are stored
+    // startOffset: bit from where to start reading
+    // numBits: number of bits to read
+    // All this function return an exception if overflow or underflow
+
+    /**
+     * Returns the first byte from the byte array.
+     *
+     * @return byte value
+     */
+    public static byte getByte(final byte[] data) {
+        if (data.length * NetUtils.NumBitsInAByte > Byte.SIZE) {
+            try {
+                throw new BufferException("Container is too small for the number of requested bits");
+            } catch (final BufferException e) {
+                LOG.error("", e);
+            }
+        }
+        return data[0];
+    }
+
+    /**
+     * Returns the short value for the byte array passed. Size of byte array is
+     * restricted to Short.SIZE
+     *
+     * @return short value
+     */
+    public static short getShort(final byte[] data) {
+        if (data.length > Short.SIZE) {
+            try {
+                throw new BufferException("Container is too small for the number of requested bits");
+            } catch (final BufferException e) {
+                LOG.error("", e);
+            }
+        }
+        return (short) toNumber(data);
+    }
+
+    /**
+     * Returns the int value for the byte array passed. Size of byte array is
+     * restricted to Integer.SIZE
+     *
+     * @return int - the integer value of byte array
+     */
+    public static int getInt(final byte[] data) {
+        if (data.length > Integer.SIZE) {
+            try {
+                throw new BufferException("Container is too small for the number of requested bits");
+            } catch (final BufferException e) {
+                LOG.error("", e);
+            }
+        }
+        return (int) toNumber(data);
+    }
+
+    /**
+     * Returns the long value for the byte array passed. Size of byte array is
+     * restricted to Long.SIZE
+     *
+     * @return long - the integer value of byte array
+     */
+    public static long getLong(final byte[] data) {
+        if (data.length > Long.SIZE) {
+            try {
+                throw new BufferException("Container is too small for the number of requested bits");
+            } catch (final Exception e) {
+                LOG.error("", e);
+            }
+        }
+        return toNumber(data);
+    }
+
+    /**
+     * Returns the short value for the last numBits of the byte array passed.
+     * Size of numBits is restricted to Short.SIZE
+     *
+     * @return short - the short value of byte array
+     */
+    public static short getShort(final byte[] data, final int numBits) {
+        if (numBits > Short.SIZE) {
+            try {
+                throw new BufferException("Container is too small for the number of requested bits");
+            } catch (final BufferException e) {
+                LOG.error("", e);
+            }
+        }
+        int startOffset = data.length * NetUtils.NumBitsInAByte - numBits;
+        byte[] bits = null;
+        try {
+            bits = BitBufferHelper.getBits(data, startOffset, numBits);
+        } catch (final BufferException e) {
+            LOG.error("", e);
+        }
+        return (short) toNumber(bits, numBits);
+    }
+
+    /**
+     * Returns the int value for the last numBits of the byte array passed. Size
+     * of numBits is restricted to Integer.SIZE
+     *
+     * @return int - the integer value of byte array
+     */
+    public static int getInt(final byte[] data, final int numBits) {
+        if (numBits > Integer.SIZE) {
+            try {
+                throw new BufferException("Container is too small for the number of requested bits");
+            } catch (final BufferException e) {
+                LOG.error("", e);
+            }
+        }
+        int startOffset = data.length * NetUtils.NumBitsInAByte - numBits;
+        byte[] bits = null;
+        try {
+            bits = BitBufferHelper.getBits(data, startOffset, numBits);
+        } catch (final BufferException e) {
+            LOG.error("", e);
+        }
+        return (int) toNumber(bits, numBits);
+    }
+
+    /**
+     * Returns the long value for the last numBits of the byte array passed.
+     * Size of numBits is restricted to Long.SIZE
+     *
+     * @return long - the integer value of byte array
+     */
+    public static long getLong(final byte[] data, final int numBits) {
+        if (numBits > Long.SIZE) {
+            try {
+                throw new BufferException("Container is too small for the number of requested bits");
+            } catch (final BufferException e) {
+                LOG.error("", e);
+            }
+        }
+        if (numBits > data.length * NetUtils.NumBitsInAByte) {
+            try {
+                throw new BufferException("Trying to read more bits than contained in the data buffer");
+            } catch (final BufferException e) {
+                LOG.error("", e);
+            }
+        }
+        int startOffset = data.length * NetUtils.NumBitsInAByte - numBits;
+        byte[] bits = null;
+        try {
+            bits = BitBufferHelper.getBits(data, startOffset, numBits);
+        } catch (final BufferException e) {
+            LOG.error("", e);
+        }
+        return toNumber(bits, numBits);
+    }
+
+    /**
+     * Reads the specified number of bits from the passed byte array starting to
+     * read from the specified offset The bits read are stored in a byte array
+     * which size is dictated by the number of bits to be stored. The bits are
+     * stored in the byte array LSB aligned.
+     *
+     * Ex. Read 7 bits at offset 10 0 9 10 16 17 0101000010 | 0000101 |
+     * 1111001010010101011 will be returned as {0,0,0,0,0,1,0,1}
+     *
+     * @param startOffset
+     *            - offset to start fetching bits from data from
+     * @param numBits
+     *            - number of bits to be fetched from data
+     * @return byte [] - LSB aligned bits
+     *
+     * @throws BufferException
+     *             when the startOffset and numBits parameters are not congruent
+     *             with the data buffer size
+     */
+    public static byte[] getBits(final byte[] data, final int startOffset, final int numBits) throws BufferException {
+        int startByteOffset = 0;
+        int valfromcurr, valfromnext;
+        int extranumBits = numBits % NetUtils.NumBitsInAByte;
+        int extraOffsetBits = startOffset % NetUtils.NumBitsInAByte;
+        int numBytes = numBits % NetUtils.NumBitsInAByte != 0 ? 1 + numBits / NetUtils.NumBitsInAByte
+                : numBits / NetUtils.NumBitsInAByte;
+        byte[] shiftedBytes = new byte[numBytes];
+        startByteOffset = startOffset / NetUtils.NumBitsInAByte;
+        byte[] bytes = new byte[numBytes];
+        if (numBits == 0) {
+            return bytes;
+        }
+
+        checkExceptions(data, startOffset, numBits);
+
+        if (extraOffsetBits == 0) {
+            if (extranumBits == 0) {
+                System.arraycopy(data, startByteOffset, bytes, 0, numBytes);
+                return bytes;
+            } else {
+                System.arraycopy(data, startByteOffset, bytes, 0, numBytes - 1);
+                bytes[numBytes - 1] = (byte) (data[startByteOffset + numBytes - 1] & getMSBMask(extranumBits));
+            }
+        } else {
+            int i;
+            for (i = 0; i < numBits / NetUtils.NumBitsInAByte; i++) {
+                // Reading numBytes starting from offset
+                valfromcurr = data[startByteOffset + i] & getLSBMask(NetUtils.NumBitsInAByte - extraOffsetBits);
+                valfromnext = data[startByteOffset + i + 1] & getMSBMask(extraOffsetBits);
+                bytes[i] = (byte) (valfromcurr << extraOffsetBits
+                        | valfromnext >> NetUtils.NumBitsInAByte - extraOffsetBits);
+            }
+            // Now adding the rest of the bits if any
+            if (extranumBits != 0) {
+                if (extranumBits < NetUtils.NumBitsInAByte - extraOffsetBits) {
+                    valfromnext = (byte) (data[startByteOffset + i] & getMSBMask(extranumBits) >> extraOffsetBits);
+                    bytes[i] = (byte) (valfromnext << extraOffsetBits);
+                } else if (extranumBits == NetUtils.NumBitsInAByte - extraOffsetBits) {
+                    valfromcurr = data[startByteOffset + i] & getLSBMask(NetUtils.NumBitsInAByte - extraOffsetBits);
+                    bytes[i] = (byte) (valfromcurr << extraOffsetBits);
+                } else {
+                    valfromcurr = data[startByteOffset + i] & getLSBMask(NetUtils.NumBitsInAByte - extraOffsetBits);
+                    valfromnext = data[startByteOffset + i + 1]
+                            & getMSBMask(extranumBits - (NetUtils.NumBitsInAByte - extraOffsetBits));
+                    bytes[i] = (byte) (valfromcurr << extraOffsetBits
+                            | valfromnext >> NetUtils.NumBitsInAByte - extraOffsetBits);
+                }
+
+            }
+        }
+        // Aligns the bits to LSB
+        shiftedBytes = shiftBitsToLSB(bytes, numBits);
+        return shiftedBytes;
+    }
+
+    // Setters
+    // data: array where data will be stored
+    // input: the data that need to be stored in the data array
+    // startOffset: bit from where to start writing
+    // numBits: number of bits to read
+
+    /**
+     * Bits are expected to be stored in the input byte array from LSB
+     *
+     * @param data
+     *            to set the input byte
+     * @param input
+     *            byte to be inserted
+     * @param startOffset
+     *            offset of data[] to start inserting byte from
+     * @param numBits
+     *            number of bits of input to be inserted into data[]
+     *
+     * @throws BufferException
+     *             when the input, startOffset and numBits are not congruent
+     *             with the data buffer size
+     */
+    public static void setByte(final byte[] data, final byte input, final int startOffset, final int numBits)
+            throws BufferException {
+        byte[] inputByteArray = new byte[1];
+        Arrays.fill(inputByteArray, 0, 1, input);
+        setBytes(data, inputByteArray, startOffset, numBits);
+    }
+
+    /**
+     * Bits are expected to be stored in the input byte array from LSB
+     *
+     * @param data
+     *            to set the input byte
+     * @param input
+     *            bytes to be inserted
+     * @param startOffset
+     *            offset of data[] to start inserting byte from
+     * @param numBits
+     *            number of bits of input to be inserted into data[]
+     * @throws BufferException
+     *             when the startOffset and numBits parameters are not congruent
+     *             with data and input buffers' size
+     */
+    public static void setBytes(final byte[] data, final byte[] input, final int startOffset, final int numBits)
+            throws BufferException {
+        checkExceptions(data, startOffset, numBits);
+        insertBits(data, input, startOffset, numBits);
+    }
+
+    /**
+     * Returns numBits 1's in the MSB position
+     */
+    public static int getMSBMask(final int numBits) {
+        int mask = 0;
+        for (int i = 0; i < numBits; i++) {
+            mask = mask | 1 << 7 - i;
+        }
+        return mask;
+    }
+
+    /**
+     * Returns numBits 1's in the LSB position
+     */
+    public static int getLSBMask(final int numBits) {
+        int mask = 0;
+        for (int i = 0; i < numBits; i++) {
+            mask = mask | 1 << i;
+        }
+        return mask;
+    }
+
+    /**
+     * Returns the numerical value of the byte array passed
+     *
+     * @return long - numerical value of byte array passed
+     */
+    static public long toNumber(final byte[] array) {
+        long ret = 0;
+        long length = array.length;
+        int value = 0;
+        for (int i = 0; i < length; i++) {
+            value = array[i];
+            if (value < 0) {
+                value += 256;
+            }
+            ret = ret | (long) value << (length - i - 1) * NetUtils.NumBitsInAByte;
+        }
+        return ret;
+    }
+
+    /**
+     * Returns the numerical value of the last numBits (LSB bits) of the byte
+     * array passed
+     *
+     * @return long - numerical value of byte array passed
+     */
+    static public long toNumber(final byte[] array, final int numBits) {
+        int length = numBits / NetUtils.NumBitsInAByte;
+        int bitsRest = numBits % NetUtils.NumBitsInAByte;
+        int startOffset = array.length - length;
+        long ret = 0;
+        int value = 0;
+
+        value = array[startOffset - 1] & getLSBMask(bitsRest);
+        value = array[startOffset - 1] < 0 ? array[startOffset - 1] + 256 : array[startOffset - 1];
+        ret = ret | value << (array.length - startOffset) * NetUtils.NumBitsInAByte;
+
+        for (int i = startOffset; i < array.length; i++) {
+            value = array[i];
+            if (value < 0) {
+                value += 256;
+            }
+            ret = ret | (long) value << (array.length - i - 1) * NetUtils.NumBitsInAByte;
+        }
+
+        return ret;
+    }
+
+    /**
+     * Accepts a number as input and returns its value in byte form in LSB
+     * aligned form example: input = 5000 [1001110001000] bytes = 19, -120
+     * [00010011] [10001000]
+     */
+    public static byte[] toByteArray(final Number input) {
+        Class<? extends Number> dataType = input.getClass();
+        short size = 0;
+        long longValue = input.longValue();
+
+        if (dataType == Byte.class || dataType == byte.class) {
+            size = Byte.SIZE;
+        } else if (dataType == Short.class || dataType == short.class) {
+            size = Short.SIZE;
+        } else if (dataType == Integer.class || dataType == int.class) {
+            size = Integer.SIZE;
+        } else if (dataType == Long.class || dataType == long.class) {
+            size = Long.SIZE;
+        } else {
+            throw new IllegalArgumentException("Parameter must one of the following: Short/Int/Long\n");
+        }
+
+        int length = size / NetUtils.NumBitsInAByte;
+        byte bytes[] = new byte[length];
+
+        // Getting the bytes from input value
+        for (int i = 0; i < length; i++) {
+            bytes[i] = (byte) (longValue >> NetUtils.NumBitsInAByte * (length - i - 1) & ByteMask);
+        }
+        return bytes;
+    }
+
+    /**
+     * Accepts a number as input and returns its value in byte form in MSB
+     * aligned form example: input = 5000 [1001110001000] bytes = -114, 64
+     * [10011100] [01000000]
+     *
+     * @param numBits
+     *            - the number of bits to be returned
+     * @return byte[]
+     *
+     */
+    public static byte[] toByteArray(final Number input, final int numBits) {
+        Class<? extends Number> dataType = input.getClass();
+        short size = 0;
+        long longValue = input.longValue();
+
+        if (dataType == Short.class) {
+            size = Short.SIZE;
+        } else if (dataType == Integer.class) {
+            size = Integer.SIZE;
+        } else if (dataType == Long.class) {
+            size = Long.SIZE;
+        } else {
+            throw new IllegalArgumentException("Parameter must one of the following: Short/Int/Long\n");
+        }
+
+        int length = size / NetUtils.NumBitsInAByte;
+        byte bytes[] = new byte[length];
+        byte[] inputbytes = new byte[length];
+        byte shiftedBytes[];
+
+        // Getting the bytes from input value
+        for (int i = 0; i < length; i++) {
+            bytes[i] = (byte) (longValue >> NetUtils.NumBitsInAByte * (length - i - 1) & ByteMask);
+        }
+
+        if (bytes[0] == 0 && dataType == Long.class || bytes[0] == 0 && dataType == Integer.class) {
+            int index = 0;
+            for (index = 0; index < length; ++index) {
+                if (bytes[index] != 0) {
+                    bytes[0] = bytes[index];
+                    break;
+                }
+            }
+            System.arraycopy(bytes, index, inputbytes, 0, length - index);
+            Arrays.fill(bytes, length - index + 1, length - 1, (byte) 0);
+        } else {
+            System.arraycopy(bytes, 0, inputbytes, 0, length);
+        }
+
+        shiftedBytes = shiftBitsToMSB(inputbytes, numBits);
+
+        return shiftedBytes;
+    }
+
+    /**
+     * Takes an LSB aligned byte array and returned the LSB numBits in a MSB
+     * aligned byte array.
+     * <p>
+     * It aligns the last numBits bits to the head of the byte array following
+     * them with numBits % 8 zero bits.
+     *
+     * Example: For inputbytes = [00000111][01110001] and numBits = 12 it
+     * returns: shiftedBytes = [01110111][00010000]
+     *
+     * @param numBits
+     *            - number of bits to be left aligned
+     * @return byte[]
+     */
+    public static byte[] shiftBitsToMSB(final byte[] inputBytes, final int numBits) {
+        int numBitstoShiftBy = 0, leadZeroesMSB = 8, numEndRestBits = 0;
+        int size = inputBytes.length;
+        byte[] shiftedBytes = new byte[size];
+        int i;
+
+        for (i = 0; i < Byte.SIZE; i++) {
+            if ((byte) (inputBytes[0] & getMSBMask(i + 1)) != 0) {
+                leadZeroesMSB = i;
+                break;
+            }
+        }
+
+        if (numBits % NetUtils.NumBitsInAByte == 0) {
+            numBitstoShiftBy = 0;
+        } else {
+            numBitstoShiftBy = NetUtils.NumBitsInAByte - numBits % NetUtils.NumBitsInAByte < leadZeroesMSB
+                    ? NetUtils.NumBitsInAByte - numBits % NetUtils.NumBitsInAByte : leadZeroesMSB;
+        }
+        if (numBitstoShiftBy == 0) {
+            return inputBytes;
+        }
+
+        if (numBits < NetUtils.NumBitsInAByte) {
+            // inputbytes.length = 1 OR read less than a byte
+            shiftedBytes[0] = (byte) ((inputBytes[0] & getLSBMask(numBits)) << numBitstoShiftBy);
+        } else {
+            // # of bits to read from last byte
+            numEndRestBits = NetUtils.NumBitsInAByte
+                    - (inputBytes.length * NetUtils.NumBitsInAByte - numBits - numBitstoShiftBy);
+
+            for (i = 0; i < size - 1; i++) {
+                if (i + 1 == size - 1) {
+                    if (numEndRestBits > numBitstoShiftBy) {
+                        shiftedBytes[i] = (byte) (inputBytes[i] << numBitstoShiftBy
+                                | (inputBytes[i + 1] & getMSBMask(numBitstoShiftBy)) >> numEndRestBits
+                                        - numBitstoShiftBy);
+                        shiftedBytes[i + 1] = (byte) ((inputBytes[i + 1]
+                                & getLSBMask(numEndRestBits - numBitstoShiftBy)) << numBitstoShiftBy);
+                    } else {
+                        shiftedBytes[i] = (byte) (inputBytes[i] << numBitstoShiftBy
+                                | (inputBytes[i + 1] & getMSBMask(numEndRestBits)) >> NetUtils.NumBitsInAByte
+                                        - numEndRestBits);
+                    }
+                }
+                shiftedBytes[i] = (byte) (inputBytes[i] << numBitstoShiftBy
+                        | (inputBytes[i + 1] & getMSBMask(numBitstoShiftBy)) >> NetUtils.NumBitsInAByte
+                                - numBitstoShiftBy);
+            }
+
+        }
+        return shiftedBytes;
+    }
+
+    /**
+     * It aligns the first numBits bits to the right end of the byte array
+     * preceding them with numBits % 8 zero bits.
+     *
+     * Example: For inputbytes = [01110111][00010000] and numBits = 12 it
+     * returns: shiftedBytes = [00000111][01110001]
+     *
+     * @param inputBytes
+     * @param numBits
+     *            - number of bits to be right aligned
+     * @return byte[]
+     */
+    public static byte[] shiftBitsToLSB(final byte[] inputBytes, final int numBits) {
+        int numBytes = inputBytes.length;
+        int numBitstoShift = numBits % NetUtils.NumBitsInAByte;
+        byte[] shiftedBytes = new byte[numBytes];
+        int inputLsb = 0, inputMsb = 0;
+
+        if (numBitstoShift == 0) {
+            return inputBytes;
+        }
+
+        for (int i = 1; i < numBytes; i++) {
+            inputLsb = inputBytes[i - 1] & getLSBMask(NetUtils.NumBitsInAByte - numBitstoShift);
+            inputLsb = inputLsb < 0 ? inputLsb + 256 : inputLsb;
+            inputMsb = inputBytes[i] & getMSBMask(numBitstoShift);
+            inputMsb = inputBytes[i] < 0 ? inputBytes[i] + 256 : inputBytes[i];
+            shiftedBytes[i] = (byte) (inputLsb << numBitstoShift
+                    | inputMsb >> NetUtils.NumBitsInAByte - numBitstoShift);
+        }
+        inputMsb = inputBytes[0] & getMSBMask(numBitstoShift);
+        inputMsb = inputMsb < 0 ? inputMsb + 256 : inputMsb;
+        shiftedBytes[0] = (byte) (inputMsb >> NetUtils.NumBitsInAByte - numBitstoShift);
+        return shiftedBytes;
+    }
+
+    /**
+     * Insert in the data buffer at position dictated by the offset the number
+     * of bits specified from the input data byte array. The input byte array
+     * has the bits stored starting from the LSB
+     */
+    public static void insertBits(final byte[] data, final byte[] inputdataLSB, final int startOffset,
+            final int numBits) {
+        byte[] inputdata = shiftBitsToMSB(inputdataLSB, numBits); // Align to
+                                                                    // MSB the
+                                                                    // passed
+                                                                    // byte
+                                                                    // array
+        int numBytes = numBits / NetUtils.NumBitsInAByte;
+        int startByteOffset = startOffset / NetUtils.NumBitsInAByte;
+        int extraOffsetBits = startOffset % NetUtils.NumBitsInAByte;
+        int extranumBits = numBits % NetUtils.NumBitsInAByte;
+        int RestBits = numBits % NetUtils.NumBitsInAByte;
+        int InputMSBbits = 0, InputLSBbits = 0;
+        int i;
+
+        if (numBits == 0) {
+            return;
+        }
+
+        if (extraOffsetBits == 0) {
+            if (extranumBits == 0) {
+                numBytes = numBits / NetUtils.NumBitsInAByte;
+                System.arraycopy(inputdata, 0, data, startByteOffset, numBytes);
+            } else {
+                System.arraycopy(inputdata, 0, data, startByteOffset, numBytes);
+                data[startByteOffset + numBytes] = (byte) (data[startByteOffset + numBytes]
+                        | inputdata[numBytes] & getMSBMask(extranumBits));
+            }
+        } else {
+            for (i = 0; i < numBytes; i++) {
+                if (i != 0) {
+                    InputLSBbits = inputdata[i - 1] & getLSBMask(extraOffsetBits);
+                }
+                InputMSBbits = (byte) (inputdata[i] & getMSBMask(NetUtils.NumBitsInAByte - extraOffsetBits));
+                InputMSBbits = InputMSBbits >= 0 ? InputMSBbits : InputMSBbits + 256;
+                data[startByteOffset + i] = (byte) (data[startByteOffset + i]
+                        | InputLSBbits << NetUtils.NumBitsInAByte - extraOffsetBits | InputMSBbits >> extraOffsetBits);
+                InputMSBbits = InputLSBbits = 0;
+            }
+            if (RestBits < NetUtils.NumBitsInAByte - extraOffsetBits) {
+                if (numBytes != 0) {
+                    InputLSBbits = inputdata[i - 1] & getLSBMask(extraOffsetBits);
+                }
+                InputMSBbits = (byte) (inputdata[i] & getMSBMask(RestBits));
+                InputMSBbits = InputMSBbits >= 0 ? InputMSBbits : InputMSBbits + 256;
+                data[startByteOffset + i] = (byte) (data[startByteOffset + i]
+                        | InputLSBbits << NetUtils.NumBitsInAByte - extraOffsetBits | InputMSBbits >> extraOffsetBits);
+            } else if (RestBits == NetUtils.NumBitsInAByte - extraOffsetBits) {
+                if (numBytes != 0) {
+                    InputLSBbits = inputdata[i - 1] & getLSBMask(extraOffsetBits);
+                }
+                InputMSBbits = (byte) (inputdata[i] & getMSBMask(NetUtils.NumBitsInAByte - extraOffsetBits));
+                InputMSBbits = InputMSBbits >= 0 ? InputMSBbits : InputMSBbits + 256;
+                data[startByteOffset + i] = (byte) (data[startByteOffset + i]
+                        | InputLSBbits << NetUtils.NumBitsInAByte - extraOffsetBits | InputMSBbits >> extraOffsetBits);
+            } else {
+                if (numBytes != 0) {
+                    InputLSBbits = inputdata[i - 1] & getLSBMask(extraOffsetBits);
+                }
+                InputMSBbits = (byte) (inputdata[i] & getMSBMask(NetUtils.NumBitsInAByte - extraOffsetBits));
+                InputMSBbits = InputMSBbits >= 0 ? InputMSBbits : InputMSBbits + 256;
+                data[startByteOffset + i] = (byte) (data[startByteOffset + i]
+                        | InputLSBbits << NetUtils.NumBitsInAByte - extraOffsetBits | InputMSBbits >> extraOffsetBits);
+
+                InputLSBbits = inputdata[i]
+                        & getLSBMask(RestBits - (NetUtils.NumBitsInAByte - extraOffsetBits)) << NetUtils.NumBitsInAByte
+                                - RestBits;
+                data[startByteOffset + i + 1] = (byte) (data[startByteOffset + i + 1]
+                        | InputLSBbits << NetUtils.NumBitsInAByte - extraOffsetBits);
+            }
+        }
+    }
+
+    /**
+     * Checks for overflow and underflow exceptions
+     *
+     * @throws BufferException
+     *             when the startOffset and numBits parameters are not congruent
+     *             with the data buffer's size
+     */
+    public static void checkExceptions(final byte[] data, final int startOffset, final int numBits)
+            throws BufferException {
+        int endOffsetByte;
+        int startByteOffset;
+        endOffsetByte = startOffset / NetUtils.NumBitsInAByte + numBits / NetUtils.NumBitsInAByte
+                + (numBits % NetUtils.NumBitsInAByte != 0 ? 1 : startOffset % NetUtils.NumBitsInAByte != 0 ? 1 : 0);
+        startByteOffset = startOffset / NetUtils.NumBitsInAByte;
+
+        if (data == null) {
+            throw new BufferException("data[] is null\n");
+        }
+
+        if (startOffset < 0 || startByteOffset >= data.length || endOffsetByte > data.length || numBits < 0
+                || numBits > NetUtils.NumBitsInAByte * data.length) {
+            throw new BufferException("Illegal arguement/out of bound exception - data.length = " + data.length
+                    + " startOffset = " + startOffset + " numBits " + numBits);
+        }
+    }
+}
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/BufferException.java b/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/BufferException.java
new file mode 100644 (file)
index 0000000..f584a23
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.liblldp;
+
+/**
+ * Describes an exception that is raised during BitBufferHelper operations.
+ */
+public class BufferException extends Exception {
+    private static final long serialVersionUID = 1L;
+
+    public BufferException(final String message) {
+        super(message);
+    }
+}
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/ConstructionException.java b/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/ConstructionException.java
new file mode 100644 (file)
index 0000000..d5f854f
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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
+ */
+
+/**
+ * @file   ConstructionException.java
+ *
+ *
+ * @brief  Describe an exception that is raised when a construction
+ * for a Node/NodeConnector/Edge or any of the SAL basic object fails
+ * because input passed are not valid or compatible
+ *
+ *
+ */
+package org.opendaylight.controller.liblldp;
+
+public class ConstructionException extends Exception {
+    private static final long serialVersionUID = 1L;
+
+    public ConstructionException(final String message) {
+        super(message);
+    }
+}
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/CustomTLVKey.java b/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/CustomTLVKey.java
new file mode 100644 (file)
index 0000000..fd5c210
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.liblldp;
+
+public class CustomTLVKey {
+
+    private int oui;
+    private byte subtype;
+
+    /**
+     * @param oui
+     * @param subtype
+     */
+    public CustomTLVKey(final int oui, final byte subtype) {
+        this.oui = oui;
+        this.subtype = subtype;
+    }
+
+    /**
+     * @return the oui
+     */
+    public int getOui() {
+        return oui;
+    }
+
+    /**
+     * @return the subtype
+     */
+    public byte getSubtype() {
+        return subtype;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + oui;
+        result = prime * result + subtype;
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (obj == null) {
+            return false;
+        }
+
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+
+        CustomTLVKey other = (CustomTLVKey) obj;
+        if (oui != other.oui) {
+            return false;
+        }
+
+        if (subtype != other.subtype) {
+            return false;
+        }
+
+        return true;
+    }
+
+}
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/DataLinkAddress.java b/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/DataLinkAddress.java
new file mode 100644 (file)
index 0000000..a9bc910
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.liblldp;
+
+import java.io.Serializable;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @file   DataLinkAddress.java
+ *
+ * @brief  Abstract base class for a Datalink Address
+ *
+ */
+
+/**
+ * Abstract base class for a Datalink Address
+ *
+ */
+@XmlRootElement
+abstract public class DataLinkAddress implements Serializable {
+    private static final long serialVersionUID = 1L;
+    private String name;
+
+    public DataLinkAddress() {
+
+    }
+
+    /**
+     * Constructor of super class
+     *
+     * @param name Create a new DataLink, not for general use but
+     * available only for sub classes
+     */
+    protected DataLinkAddress(final String name) {
+        this.name = name;
+    }
+
+    /**
+     * Used to copy the DataLinkAddress in a polymorphic way
+     *
+     *
+     * @return A clone of this DataLinkAddress
+     */
+    @Override
+    abstract public DataLinkAddress clone();
+
+    /**
+     * Allow to distinguish among different data link addresses
+     *
+     *
+     * @return Name of the DataLinkAdress we are working on
+     */
+    public String getName() {
+        return this.name;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        DataLinkAddress other = (DataLinkAddress) obj;
+        if (name == null) {
+            if (other.name != null) {
+                return false;
+            }
+        } else if (!name.equals(other.name)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return "DataLinkAddress [name=" + name + "]";
+    }
+}
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/EtherTypes.java b/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/EtherTypes.java
new file mode 100644 (file)
index 0000000..84f47da
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.liblldp;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The enum contains the most common 802.3 ethernet types and 802.2 + SNAP protocol ids
+ *
+ *
+ *
+ */
+public enum EtherTypes {
+    PVSTP("PVSTP", 0x010B), // 802.2 + SNAP (Spanning Tree)
+    CDP("CDP", 0x2000), // 802.2 + SNAP
+    VTP("VTP", 0x2003), // 802.2 + SNAP
+    IPv4("IPv4", 0x800), ARP("ARP", 0x806), RARP("Reverse ARP", 0x8035), VLANTAGGED(
+            "VLAN Tagged", 0x8100), // 802.1Q
+    IPv6("IPv6", 0x86DD), MPLSUCAST("MPLS Unicast", 0x8847), MPLSMCAST(
+            "MPLS Multicast", 0x8848), QINQ("QINQ", 0x88A8), // Standard 802.1ad QinQ
+    LLDP("LLDP", 0x88CC), OLDQINQ("Old QINQ", 0x9100), // Old non-standard QinQ
+    CISCOQINQ("Cisco QINQ", 0x9200); // Cisco non-standard QinQ
+
+    private static final String regexNumberString = "^[0-9]+$";
+    private String description;
+    private int number;
+
+    EtherTypes(final String description, final int number) {
+        this.description = description;
+        this.number = number;
+    }
+
+    public String toString() {
+        return description;
+    }
+
+    public int intValue() {
+        return number;
+    }
+
+    public short shortValue() {
+        return ((Integer) number).shortValue();
+    }
+
+    public static String getEtherTypeName(final int number) {
+        return getEtherTypeInternal(number);
+    }
+
+    public static String getEtherTypeName(final short number) {
+        return getEtherTypeInternal(number & 0xffff);
+    }
+
+    public static String getEtherTypeName(final byte number) {
+        return getEtherTypeInternal(number & 0xff);
+    }
+
+    private static String getEtherTypeInternal(final int number) {
+        for (EtherTypes type : EtherTypes.values()) {
+            if (type.number == number) {
+                return type.toString();
+            }
+        }
+        return "0x" + Integer.toHexString(number);
+    }
+
+    public static short getEtherTypeNumberShort(final String name) {
+        if (name.matches(regexNumberString)) {
+            return Short.valueOf(name);
+        }
+        for (EtherTypes type : EtherTypes.values()) {
+            if (type.description.equalsIgnoreCase(name)) {
+                return type.shortValue();
+            }
+        }
+        return 0;
+    }
+
+    public static int getEtherTypeNumberInt(final String name) {
+        if (name.matches(regexNumberString)) {
+            return Integer.valueOf(name);
+        }
+        for (EtherTypes type : EtherTypes.values()) {
+            if (type.description.equalsIgnoreCase(name)) {
+                return type.intValue();
+            }
+        }
+        return 0;
+    }
+
+    public static List<String> getEtherTypesNameList() {
+        List<String> ethertypesList = new ArrayList<>();
+        for (EtherTypes type : EtherTypes.values()) {
+            ethertypesList.add(type.toString());
+        }
+        return ethertypesList;
+    }
+
+    public static EtherTypes loadFromString(final String string) {
+        int intType = Integer.parseInt(string);
+
+        for (EtherTypes type : EtherTypes.values()) {
+            if (type.number == intType) {
+                return type;
+            }
+        }
+        return null;
+    }
+
+}
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/Ethernet.java b/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/Ethernet.java
new file mode 100644 (file)
index 0000000..a78ff6a
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.liblldp;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+
+/**
+ * Class that represents the Ethernet frame objects
+ */
+public class Ethernet extends Packet {
+    private static final String DMAC = "DestinationMACAddress";
+    private static final String SMAC = "SourceMACAddress";
+    private static final String ETHT = "EtherType";
+
+    // TODO: This has to be outside and it should be possible for osgi
+    // to add new coming packet classes
+    public static final Map<Short, Class<? extends Packet>> etherTypeClassMap;
+    static {
+        etherTypeClassMap = new HashMap<>();
+        etherTypeClassMap.put(EtherTypes.LLDP.shortValue(), LLDP.class);
+    }
+    private static Map<String, Pair<Integer, Integer>> fieldCoordinates = new LinkedHashMap<String, Pair<Integer, Integer>>() {
+        private static final long serialVersionUID = 1L;
+        {
+            put(DMAC, new ImmutablePair<>(0, 48));
+            put(SMAC, new ImmutablePair<>(48, 48));
+            put(ETHT, new ImmutablePair<>(96, 16));
+        }
+    };
+    private final Map<String, byte[]> fieldValues;
+
+    /**
+     * Default constructor that creates and sets the HashMap
+     */
+    public Ethernet() {
+        fieldValues = new HashMap<>();
+        hdrFieldCoordMap = fieldCoordinates;
+        hdrFieldsMap = fieldValues;
+    }
+
+    /**
+     * Constructor that sets the access level for the packet and
+     * creates and sets the HashMap
+     */
+    public Ethernet(final boolean writeAccess) {
+        super(writeAccess);
+        fieldValues = new HashMap<>();
+        hdrFieldCoordMap = fieldCoordinates;
+        hdrFieldsMap = fieldValues;
+    }
+
+    @Override
+    public void setHeaderField(final String headerField, final byte[] readValue) {
+        if (headerField.equals(ETHT)) {
+            payloadClass = etherTypeClassMap.get(BitBufferHelper
+                    .getShort(readValue));
+        }
+        hdrFieldsMap.put(headerField, readValue);
+    }
+
+    /**
+     * Gets the destination MAC address stored
+     * @return byte[] - the destinationMACAddress
+     */
+    public byte[] getDestinationMACAddress() {
+        return fieldValues.get(DMAC);
+    }
+
+    /**
+     * Gets the source MAC address stored
+     * @return byte[] - the sourceMACAddress
+     */
+    public byte[] getSourceMACAddress() {
+        return fieldValues.get(SMAC);
+    }
+
+    /**
+     * Gets the etherType stored
+     * @return short - the etherType
+     */
+    public short getEtherType() {
+        return BitBufferHelper.getShort(fieldValues.get(ETHT));
+    }
+
+    public boolean isBroadcast(){
+        return NetUtils.isBroadcastMACAddr(getDestinationMACAddress());
+    }
+
+    public boolean isMulticast(){
+        return NetUtils.isMulticastMACAddr(getDestinationMACAddress());
+    }
+
+    /**
+     * Sets the destination MAC address for the current Ethernet object instance
+     * @param destinationMACAddress the destinationMACAddress to set
+     */
+    public Ethernet setDestinationMACAddress(final byte[] destinationMACAddress) {
+        fieldValues.put(DMAC, destinationMACAddress);
+        return this;
+    }
+
+    /**
+     * Sets the source MAC address for the current Ethernet object instance
+     * @param sourceMACAddress the sourceMACAddress to set
+     */
+    public Ethernet setSourceMACAddress(final byte[] sourceMACAddress) {
+        fieldValues.put(SMAC, sourceMACAddress);
+        return this;
+    }
+
+    /**
+     * Sets the etherType for the current Ethernet object instance
+     * @param etherType the etherType to set
+     */
+    public Ethernet setEtherType(final short etherType) {
+        byte[] ethType = BitBufferHelper.toByteArray(etherType);
+        fieldValues.put(ETHT, ethType);
+        return this;
+    }
+
+}
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/EthernetAddress.java b/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/EthernetAddress.java
new file mode 100644 (file)
index 0000000..fb75532
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.liblldp;
+
+import java.util.Arrays;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
+public class EthernetAddress extends DataLinkAddress {
+    private static final long serialVersionUID = 1L;
+    @XmlTransient
+    private byte[] macAddress;
+
+    public static final EthernetAddress BROADCASTMAC = createWellKnownAddress(new byte[] {
+            (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+            (byte) 0xff });
+
+    public static final EthernetAddress INVALIDHOST = BROADCASTMAC;
+
+    public static final String addressName = "Ethernet MAC Address";
+    public static final int SIZE = 6;
+
+    private static final EthernetAddress createWellKnownAddress(final byte[] mac) {
+        try {
+            return new EthernetAddress(mac);
+        } catch (final ConstructionException ce) {
+            return null;
+        }
+    }
+
+    /* Private constructor to satisfy JAXB */
+    @SuppressWarnings("unused")
+    private EthernetAddress() {
+    }
+
+    /**
+     * Public constructor for an Ethernet MAC address starting from
+     * the byte constituing the address, the constructor validate the
+     * size of the arrive to make sure it met the expected size
+     *
+     * @param macAddress A byte array in big endian format
+     * representing the Ethernet MAC Address
+     */
+    public EthernetAddress(final byte[] macAddress) throws ConstructionException {
+        super(addressName);
+
+        if (macAddress == null) {
+            throw new ConstructionException("Null input parameter passed");
+        }
+
+        if (macAddress.length != SIZE) {
+            throw new ConstructionException(
+                    "Wrong size of passed byte array, expected:" + SIZE
+                            + " got:" + macAddress.length);
+        }
+        this.macAddress = new byte[SIZE];
+        System.arraycopy(macAddress, 0, this.macAddress, 0, SIZE);
+    }
+
+    public EthernetAddress clone() {
+        try {
+            return new EthernetAddress(this.macAddress.clone());
+        } catch (final ConstructionException ce) {
+            return null;
+        }
+    }
+
+    /**
+     * Return the Ethernet Mac address in byte array format
+     *
+     * @return The Ethernet Mac address in byte array format
+     */
+    public byte[] getValue() {
+        return this.macAddress;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + Arrays.hashCode(macAddress);
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        EthernetAddress other = (EthernetAddress) obj;
+        if (!Arrays.equals(macAddress, other.macAddress)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return "EthernetAddress [macAddress=" + HexEncode.bytesToHexStringFormat(macAddress)
+                + "]";
+    }
+
+    @XmlElement(name = "macAddress")
+    public String getMacAddress() {
+        return HexEncode.bytesToHexStringFormat(macAddress);
+    }
+}
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/HexEncode.java b/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/HexEncode.java
new file mode 100644 (file)
index 0000000..bb18149
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.liblldp;
+
+import java.math.BigInteger;
+
+/**
+ * The class provides methods to convert hex encode strings
+ *
+ *
+ */
+public class HexEncode {
+    /**
+     * This method converts byte array into String format without ":" inserted.
+     *
+     * @param bytes
+     *            The byte array to convert to string
+     * @return The hexadecimal representation of the byte array. If bytes is
+     *         null, "null" string is returned
+     */
+    public static String bytesToHexString(final byte[] bytes) {
+
+        if (bytes == null) {
+            return "null";
+        }
+
+        StringBuilder buf = new StringBuilder();
+        for (int i = 0; i < bytes.length; i++) {
+            short u8byte = (short) (bytes[i] & 0xff);
+            String tmp = Integer.toHexString(u8byte);
+            if (tmp.length() == 1) {
+                buf.append("0");
+            }
+            buf.append(tmp);
+        }
+        return buf.toString();
+    }
+
+    public static String longToHexString(final long val) {
+        char arr[] = Long.toHexString(val).toCharArray();
+        StringBuilder buf = new StringBuilder();
+        // prepend the right number of leading zeros
+        int i = 0;
+        for (; i < (16 - arr.length); i++) {
+            buf.append("0");
+            if ((i & 0x01) == 1) {
+                buf.append(":");
+            }
+        }
+        for (int j = 0; j < arr.length; j++) {
+            buf.append(arr[j]);
+            if ((((i + j) & 0x01) == 1) && (j < (arr.length - 1))) {
+                buf.append(":");
+            }
+        }
+        return buf.toString();
+    }
+
+
+    public static byte[] bytesFromHexString(final String values) {
+        String target = "";
+        if (values != null) {
+            target = values;
+        }
+        String[] octets = target.split(":");
+
+        byte[] ret = new byte[octets.length];
+        for (int i = 0; i < octets.length; i++) {
+            ret[i] = Integer.valueOf(octets[i], 16).byteValue();
+        }
+        return ret;
+    }
+
+    public static long stringToLong(final String values) {
+        long value = new BigInteger(values.replaceAll(":", ""), 16).longValue();
+        return value;
+    }
+
+    /**
+     * This method converts byte array into HexString format with ":" inserted.
+     */
+    public static String bytesToHexStringFormat(final byte[] bytes) {
+        if (bytes == null) {
+            return "null";
+        }
+        StringBuilder buf = new StringBuilder();
+        for (int i = 0; i < bytes.length; i++) {
+            if (i > 0) {
+                buf.append(":");
+            }
+            short u8byte = (short) (bytes[i] & 0xff);
+            String tmp = Integer.toHexString(u8byte);
+            if (tmp.length() == 1) {
+                buf.append("0");
+            }
+            buf.append(tmp);
+        }
+        return buf.toString();
+    }
+}
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/LLDP.java b/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/LLDP.java
new file mode 100644 (file)
index 0000000..7ed1ede
--- /dev/null
@@ -0,0 +1,294 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.liblldp;
+
+import com.google.common.collect.Iterables;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Class that represents the LLDP frame objects
+ */
+
+public class LLDP extends Packet {
+    private static final String CHASSISID = "ChassisId";
+    private static final String SYSTEMNAMEID = "SystemNameID";
+    private static final String PORTID = "PortId";
+    private static final String TTL = "TTL";
+    private static final int LLDPDefaultTlvs = 3;
+    private static final LLDPTLV emptyTLV = new LLDPTLV().setLength((short) 0).setType((byte) 0);
+    public static final byte[] LLDPMulticastMac = { 1, (byte) 0x80, (byte) 0xc2, 0, 0, (byte) 0xe };
+
+    private Map<Byte, LLDPTLV> mandatoryTLVs;
+    private Map<Byte, LLDPTLV> optionalTLVs;
+    private Map<CustomTLVKey, LLDPTLV> customTLVs;
+
+    /**
+     * Default constructor that creates the tlvList LinkedHashMap
+     */
+    public LLDP() {
+        init();
+    }
+
+    /**
+     * Constructor that creates the tlvList LinkedHashMap and sets the write access for the same
+     */
+    public LLDP(final boolean writeAccess) {
+        super(writeAccess);
+        init();
+    }
+
+    private void init() {
+        mandatoryTLVs = new LinkedHashMap<>(LLDPDefaultTlvs);
+        optionalTLVs = new LinkedHashMap<>();
+        customTLVs = new LinkedHashMap<>();
+    }
+
+    /**
+     * @param String
+     *            - description of the type of TLV
+     * @return byte - type of TLV
+     */
+    private byte getType(final String typeDesc) {
+        if (typeDesc.equals(CHASSISID)) {
+            return LLDPTLV.TLVType.ChassisID.getValue();
+        } else if (typeDesc.equals(PORTID)) {
+            return LLDPTLV.TLVType.PortID.getValue();
+        } else if (typeDesc.equals(TTL)) {
+            return LLDPTLV.TLVType.TTL.getValue();
+        } else if (typeDesc.equals(SYSTEMNAMEID)) {
+            return LLDPTLV.TLVType.SystemName.getValue();
+        } else {
+            return LLDPTLV.TLVType.Unknown.getValue();
+        }
+    }
+
+    private LLDPTLV getFromTLVs(final Byte type) {
+        LLDPTLV tlv = null;
+        tlv = mandatoryTLVs.get(type);
+        if (tlv == null) {
+            tlv = optionalTLVs.get(type);
+        }
+        return tlv;
+    }
+
+    private void putToTLVs(final Byte type, final LLDPTLV tlv) {
+        if (type == LLDPTLV.TLVType.ChassisID.getValue() || type == LLDPTLV.TLVType.PortID.getValue()
+                || type == LLDPTLV.TLVType.TTL.getValue()) {
+            mandatoryTLVs.put(type, tlv);
+        } else if (type != LLDPTLV.TLVType.Custom.getValue()) {
+            optionalTLVs.put(type, tlv);
+        }
+    }
+
+    /**
+     * @param type
+     *            - description of the type of TLV
+     * @return LLDPTLV - full TLV
+     */
+    public LLDPTLV getTLV(final String type) {
+        return getFromTLVs(getType(type));
+    }
+
+    public LLDPTLV getCustomTLV(final CustomTLVKey key) {
+        return customTLVs.get(key);
+    }
+
+    /**
+     * @param type
+     *            - description of the type of TLV
+     * @param tlv
+     *            - tlv to set
+     */
+    public void setTLV(final String type, final LLDPTLV tlv) {
+        putToTLVs(getType(type), tlv);
+    }
+
+    /**
+     * @return the chassisId TLV
+     */
+    public LLDPTLV getChassisId() {
+        return getTLV(CHASSISID);
+    }
+
+    /**
+     * @param chassisId
+     *            - the chassisId to set
+     */
+    public LLDP setChassisId(final LLDPTLV chassisId) {
+        setTLV(CHASSISID, chassisId);
+        return this;
+    }
+
+    /**
+     * @return the SystemName TLV
+     */
+    public LLDPTLV getSystemNameId() {
+        return getTLV(SYSTEMNAMEID);
+    }
+
+    /**
+     * @param systemNameId
+     *            - the systemNameId to set
+     */
+    public LLDP setSystemNameId(final LLDPTLV systemNameId) {
+        setTLV(SYSTEMNAMEID, systemNameId);
+        return this;
+    }
+
+    /**
+     * @return LLDPTLV - the portId TLV
+     */
+    public LLDPTLV getPortId() {
+        return getTLV(PORTID);
+    }
+
+    /**
+     * @param portId
+     *            - the portId to set
+     * @return LLDP
+     */
+    public LLDP setPortId(final LLDPTLV portId) {
+        setTLV(PORTID, portId);
+        return this;
+    }
+
+    /**
+     * @return LLDPTLV - the ttl TLV
+     */
+    public LLDPTLV getTtl() {
+        return getTLV(TTL);
+    }
+
+    /**
+     * @param ttl
+     *            - the ttl to set
+     * @return LLDP
+     */
+    public LLDP setTtl(final LLDPTLV ttl) {
+        setTLV(TTL, ttl);
+        return this;
+    }
+
+    /**
+     * @return the optionalTLVList
+     */
+    public Iterable<LLDPTLV> getOptionalTLVList() {
+        return optionalTLVs.values();
+    }
+
+    /**
+     * @return the customTlvList
+     */
+    public Iterable<LLDPTLV> getCustomTlvList() {
+        return customTLVs.values();
+    }
+
+    /**
+     * @param optionalTLVList
+     *            the optionalTLVList to set
+     * @return LLDP
+     */
+    public LLDP setOptionalTLVList(final List<LLDPTLV> optionalTLVList) {
+        for (LLDPTLV tlv : optionalTLVList) {
+            optionalTLVs.put(tlv.getType(), tlv);
+        }
+        return this;
+    }
+
+    /**
+     * @param customTLV
+     *            the list of custom TLVs to set
+     * @return this LLDP
+     */
+    public LLDP addCustomTLV(final LLDPTLV customTLV) {
+        CustomTLVKey key = new CustomTLVKey(LLDPTLV.extractCustomOUI(customTLV),
+                LLDPTLV.extractCustomSubtype(customTLV));
+        customTLVs.put(key, customTLV);
+
+        return this;
+    }
+
+    @Override
+    public Packet deserialize(final byte[] data, final int bitOffset, final int size) throws PacketException {
+        int lldpOffset = bitOffset; // LLDP start
+        int lldpSize = size; // LLDP size
+
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("LLDP: {} (offset {} bitsize {})", new Object[] { HexEncode.bytesToHexString(data),
+                    lldpOffset, lldpSize });
+        }
+        /*
+         * Deserialize the TLVs until we reach the end of the packet
+         */
+        while (lldpSize > 0) {
+            LLDPTLV tlv = new LLDPTLV();
+            tlv.deserialize(data, lldpOffset, lldpSize);
+            if (tlv.getType() == 0 && tlv.getLength() == 0) {
+                break;
+            }
+            int tlvSize = tlv.getTLVSize(); // Size of current TLV in bits
+            lldpOffset += tlvSize;
+            lldpSize -= tlvSize;
+            if (tlv.getType() == LLDPTLV.TLVType.Custom.getValue()) {
+                addCustomTLV(tlv);
+            } else {
+                this.putToTLVs(tlv.getType(), tlv);
+            }
+        }
+        return this;
+    }
+
+    @Override
+    public byte[] serialize() throws PacketException {
+        int startOffset = 0;
+        byte[] serializedBytes = new byte[getLLDPPacketLength()];
+
+        final Iterable<LLDPTLV> allTlvs = Iterables.concat(mandatoryTLVs.values(), optionalTLVs.values(), customTLVs.values());
+        for (LLDPTLV tlv : allTlvs) {
+            int numBits = tlv.getTLVSize();
+            try {
+                BitBufferHelper.setBytes(serializedBytes, tlv.serialize(), startOffset, numBits);
+            } catch (final BufferException e) {
+                throw new PacketException(e.getMessage());
+            }
+            startOffset += numBits;
+        }
+        // Now add the empty LLDPTLV at the end
+        try {
+            BitBufferHelper.setBytes(serializedBytes, LLDP.emptyTLV.serialize(), startOffset,
+                    LLDP.emptyTLV.getTLVSize());
+        } catch (final BufferException e) {
+            throw new PacketException(e.getMessage());
+        }
+
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("LLDP: serialized: {}", HexEncode.bytesToHexString(serializedBytes));
+        }
+        return serializedBytes;
+    }
+
+    /**
+     * Returns the size of LLDP packet in bytes
+     *
+     * @return int - LLDP Packet size in bytes
+     */
+    private int getLLDPPacketLength() {
+        int len = 0;
+
+        for (LLDPTLV lldptlv : Iterables.concat(mandatoryTLVs.values(), optionalTLVs.values(), customTLVs.values())) {
+            len += lldptlv.getTLVSize();
+        }
+
+        len += LLDP.emptyTLV.getTLVSize();
+
+        return len / NetUtils.NumBitsInAByte;
+    }
+}
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/LLDPTLV.java b/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/LLDPTLV.java
new file mode 100644 (file)
index 0000000..24b350c
--- /dev/null
@@ -0,0 +1,373 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.liblldp;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.slf4j.LoggerFactory;
+
+import org.slf4j.Logger;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.apache.commons.lang3.tuple.MutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+
+/**
+ * Class that represents the LLDPTLV objects
+ */
+
+public class LLDPTLV extends Packet {
+    private static final String TYPE = "Type";
+    private static final String LENGTH = "Length";
+    private static final String VALUE = "Value";
+    private static final int LLDPTLVFields = 3;
+
+    /** OpenFlow OUI */
+    public static final byte[] OFOUI = new byte[] { (byte) 0x00, (byte) 0x26,
+        (byte) 0xe1 };
+
+    /** Length of Organizationally defined subtype field of TLV in bytes   */
+    private static final byte customTlvSubTypeLength = (byte)1;
+
+    /** OpenFlow subtype: nodeConnectorId of source */
+    public static final byte[] CUSTOM_TLV_SUB_TYPE_NODE_CONNECTOR_ID = new byte[] { 0 };
+
+    /** OpenFlow subtype: custom sec = hash code of verification of origin of LLDP */
+    public static final byte[] CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC = new byte[] { 1 };
+
+    public static final int customTlvOffset = OFOUI.length + customTlvSubTypeLength;
+    public static final byte chassisIDSubType[] = new byte[] { 4 }; // MAC address for the system
+    public static final byte portIDSubType[] = new byte[] { 7 }; // locally assigned
+
+    private static final Logger LOG = LoggerFactory.getLogger(LLDPTLV.class);
+
+    public enum TLVType {
+        Unknown((byte) 0), ChassisID((byte) 1), PortID((byte) 2), TTL((byte) 3), PortDesc(
+                (byte) 4), SystemName((byte) 5), SystemDesc((byte) 6), Custom(
+                        (byte) 127);
+
+        private byte value;
+
+        TLVType(final byte value) {
+            this.value = value;
+        }
+
+        public byte getValue() {
+            return value;
+        }
+    }
+
+    private static Map<String, Pair<Integer, Integer>> fieldCoordinates = new LinkedHashMap<String, Pair<Integer, Integer>>() {
+        private static final long serialVersionUID = 1L;
+
+        {
+            put(TYPE, new MutablePair<>(0, 7));
+            put(LENGTH, new MutablePair<>(7, 9));
+            put(VALUE, new MutablePair<>(16, 0));
+        }
+    };
+
+    protected Map<String, byte[]> fieldValues;
+
+    /**
+     * Default constructor that creates and sets the hash map values and sets
+     * the payload to null
+     */
+    public LLDPTLV() {
+        payload = null;
+        fieldValues = new HashMap<>(LLDPTLVFields);
+        hdrFieldCoordMap = fieldCoordinates;
+        hdrFieldsMap = fieldValues;
+    }
+
+    /**
+     * Constructor that writes the passed LLDPTLV values to the hdrFieldsMap
+     */
+    public LLDPTLV(final LLDPTLV other) {
+        for (Map.Entry<String, byte[]> entry : other.hdrFieldsMap.entrySet()) {
+            this.hdrFieldsMap.put(entry.getKey(), entry.getValue());
+        }
+    }
+
+    /**
+     * @return int - the length of TLV
+     */
+    public int getLength() {
+        return (int) BitBufferHelper.toNumber(fieldValues.get(LENGTH),
+                fieldCoordinates.get(LENGTH).getRight().intValue());
+    }
+
+    /**
+     * @return byte - the type of TLV
+     */
+    public byte getType() {
+        return BitBufferHelper.getByte(fieldValues.get(TYPE));
+    }
+
+    /**
+     * @return byte[] - the value field of TLV
+     */
+    public byte[] getValue() {
+        return fieldValues.get(VALUE);
+    }
+
+    /**
+     * @param type the type to set
+     * @return LLDPTLV
+     */
+    public LLDPTLV setType(final byte type) {
+        byte[] lldpTLVtype = { type };
+        fieldValues.put(TYPE, lldpTLVtype);
+        return this;
+    }
+
+    /**
+     * @param length the length to set
+     * @return LLDPTLV
+     */
+    public LLDPTLV setLength(final short length) {
+        fieldValues.put(LENGTH, BitBufferHelper.toByteArray(length));
+        return this;
+    }
+
+    /**
+     * @param value the value to set
+     * @return LLDPTLV
+     */
+    public LLDPTLV setValue(final byte[] value) {
+        fieldValues.put(VALUE, value);
+        return this;
+    }
+
+    @Override
+    public void setHeaderField(final String headerField, final byte[] readValue) {
+        hdrFieldsMap.put(headerField, readValue);
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result
+                + ((fieldValues == null) ? 0 : fieldValues.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        LLDPTLV other = (LLDPTLV) obj;
+        if (fieldValues == null) {
+            if (other.fieldValues != null) {
+                return false;
+            }
+        } else if (!fieldValues.equals(other.fieldValues)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public int getfieldnumBits(final String fieldName) {
+        if (fieldName.equals(VALUE)) {
+            return (NetUtils.NumBitsInAByte * BitBufferHelper.getShort(
+                    fieldValues.get(LENGTH), fieldCoordinates.get(LENGTH)
+                    .getRight().intValue()));
+        }
+        return fieldCoordinates.get(fieldName).getRight();
+    }
+
+    /**
+     * Returns the size in bits of the whole TLV
+     *
+     * @return int - size in bits of full TLV
+     */
+    public int getTLVSize() {
+        return (LLDPTLV.fieldCoordinates.get(TYPE).getRight() + // static
+                LLDPTLV.fieldCoordinates.get(LENGTH).getRight() + // static
+                getfieldnumBits(VALUE)); // variable
+    }
+
+    /**
+     * Creates the SystemName TLV value
+     *
+     * @param nodeId
+     *            node identifier string
+     * @return the SystemName TLV value in byte array
+     */
+    static public byte[] createSystemNameTLVValue(final String nodeId) {
+        byte[] nid = nodeId.getBytes();
+        return nid;
+    }
+
+    /**
+     * Creates the ChassisID TLV value including the subtype and ChassisID
+     * string
+     *
+     * @param nodeId
+     *            node identifier string
+     * @return the ChassisID TLV value in byte array
+     */
+    static public byte[] createChassisIDTLVValue(final String nodeId) {
+        byte[] nid = HexEncode.bytesFromHexString(nodeId);
+        byte[] cid = new byte[6];
+        int srcPos = 0, dstPos = 0;
+
+        if (nid.length > cid.length) {
+            srcPos = nid.length - cid.length;
+        } else {
+            dstPos = cid.length - nid.length;
+        }
+        System.arraycopy(nid, srcPos, cid, dstPos, cid.length);
+
+        byte[] cidValue = new byte[cid.length + chassisIDSubType.length];
+
+        System.arraycopy(chassisIDSubType, 0, cidValue, 0,
+                chassisIDSubType.length);
+        System.arraycopy(cid, 0, cidValue, chassisIDSubType.length, cid.length);
+
+        return cidValue;
+    }
+
+    /**
+     * Creates the PortID TLV value including the subtype and PortID string
+     *
+     * @param portId
+     *            port identifier string
+     * @return the PortID TLV value in byte array
+     */
+    static public byte[] createPortIDTLVValue(final String portId) {
+        byte[] pid = portId.getBytes(Charset.defaultCharset());
+        byte[] pidValue = new byte[pid.length + portIDSubType.length];
+
+        System.arraycopy(portIDSubType, 0, pidValue, 0, portIDSubType.length);
+        System.arraycopy(pid, 0, pidValue, portIDSubType.length, pid.length);
+
+        return pidValue;
+    }
+
+    /**
+     * Creates the custom TLV value including OUI, subtype and custom string
+     *
+     * @param customString
+     *            port identifier string
+     * @return the custom TLV value in byte array
+     * @see #createCustomTLVValue(byte[],byte[])
+     */
+    static public byte[] createCustomTLVValue(final String customString) {
+        byte[] customByteArray = customString.getBytes(Charset.defaultCharset());
+        return createCustomTLVValue(CUSTOM_TLV_SUB_TYPE_NODE_CONNECTOR_ID, customByteArray);
+    }
+
+    /**
+     * Creates the custom TLV value including OUI, subtype and custom string
+     * @param subtype openflow subtype
+     * @param customByteArray
+     *            port identifier string
+     * @return the custom TLV value in byte array
+     */
+    static public byte[] createCustomTLVValue(final byte[] subtype, final byte[] customByteArray) {
+        byte[] customValue = new byte[customTlvOffset + customByteArray.length];
+
+        System.arraycopy(OFOUI, 0, customValue, 0, OFOUI.length);
+        System.arraycopy(subtype, 0, customValue, OFOUI.length, 1);
+        System.arraycopy(customByteArray, 0, customValue, customTlvOffset,
+                customByteArray.length);
+
+        return customValue;
+    }
+
+    /**
+     * Retrieves the string from TLV value and returns it in HexString format
+     *
+     * @param tlvValue
+     *            the TLV value
+     * @param tlvLen
+     *            the TLV length
+     * @return the HexString
+     */
+    static public String getHexStringValue(final byte[] tlvValue, final int tlvLen) {
+        byte[] cidBytes = new byte[tlvLen - chassisIDSubType.length];
+        System.arraycopy(tlvValue, chassisIDSubType.length, cidBytes, 0,
+                cidBytes.length);
+        return HexEncode.bytesToHexStringFormat(cidBytes);
+    }
+
+    /**
+     * Retrieves the string from TLV value
+     *
+     * @param tlvValue
+     *            the TLV value
+     * @param tlvLen
+     *            the TLV length
+     * @return the string
+     */
+    static public String getStringValue(final byte[] tlvValue, final int tlvLen) {
+        byte[] pidSubType = new byte[portIDSubType.length];
+        byte[] pidBytes = new byte[tlvLen - portIDSubType.length];
+        System.arraycopy(tlvValue, 0, pidSubType, 0,
+                pidSubType.length);
+        System.arraycopy(tlvValue, portIDSubType.length, pidBytes, 0,
+                pidBytes.length);
+        if (pidSubType[0] == (byte) 0x3) {
+            return HexEncode.bytesToHexStringFormat(pidBytes);
+        } else {
+            return (new String(pidBytes, Charset.defaultCharset()));
+        }
+    }
+
+    /**
+     * Retrieves the custom string from the Custom TLV value which includes OUI,
+     * subtype and custom string
+     *
+     * @param customTlvValue
+     *            the custom TLV value
+     * @param customTlvLen
+     *            the custom TLV length
+     * @return the custom string
+     */
+    static public String getCustomString(final byte[] customTlvValue, final int customTlvLen) {
+        String customString = "";
+        byte[] vendor = new byte[3];
+        System.arraycopy(customTlvValue, 0, vendor, 0, vendor.length);
+        if (Arrays.equals(vendor, LLDPTLV.OFOUI)) {
+            int customArrayLength = customTlvLen - customTlvOffset;
+            byte[] customArray = new byte[customArrayLength];
+            System.arraycopy(customTlvValue, customTlvOffset, customArray, 0,
+                    customArrayLength);
+            try {
+                customString = new String(customArray, "UTF-8");
+            } catch (final UnsupportedEncodingException e) {
+            }
+        }
+
+        return customString;
+    }
+
+    public static int extractCustomOUI(final LLDPTLV lldptlv) {
+        byte[] value = lldptlv.getValue();
+        return BitBufferHelper.getInt(ArrayUtils.subarray(value, 0, 3));
+    }
+
+    public static byte extractCustomSubtype(final LLDPTLV lldptlv) {
+        byte[] value = lldptlv.getValue();
+        return BitBufferHelper.getByte(ArrayUtils.subarray(value, 3, 4));
+    }
+}
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/NetUtils.java b/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/NetUtils.java
new file mode 100644 (file)
index 0000000..2ed7787
--- /dev/null
@@ -0,0 +1,521 @@
+/*
+ * Copyright (c) 2013, 2015 Cisco Systems, Inc. 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.controller.liblldp;
+
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Utility class containing the common utility functions needed for operating on
+ * networking data structures
+ */
+public abstract class NetUtils {
+    protected static final Logger LOG = LoggerFactory.getLogger(NetUtils.class);
+    /**
+     * Constant holding the number of bits in a byte
+     */
+    public static final int NumBitsInAByte = 8;
+
+    /**
+     * Constant holding the number of bytes in MAC Address
+     */
+    public static final int MACAddrLengthInBytes = 6;
+
+    /**
+     * Constant holding the number of words in MAC Address
+     */
+    public static final int MACAddrLengthInWords = 3;
+
+    /**
+     * Constant holding the broadcast MAC address
+     */
+    private static final byte[] BroadcastMACAddr = {-1, -1, -1, -1, -1, -1};
+
+    /**
+     * Converts a 4 bytes array into an integer number
+     *
+     * @param ba
+     *            the 4 bytes long byte array
+     * @return the integer number
+     */
+    public static int byteArray4ToInt(final byte[] ba) {
+        if (ba == null || ba.length != 4) {
+            return 0;
+        }
+        return (0xff & ba[0]) << 24 | (0xff & ba[1]) << 16 | (0xff & ba[2]) << 8 | 0xff & ba[3];
+    }
+
+    /**
+     * Converts a 6 bytes array into a long number MAC addresses.
+     *
+     * @param ba
+     *            The 6 bytes long byte array.
+     * @return The long number.
+     *         Zero is returned if {@code ba} is {@code null} or
+     *         the length of it is not six.
+     */
+    public static long byteArray6ToLong(final byte[] ba) {
+        if (ba == null || ba.length != MACAddrLengthInBytes) {
+            return 0L;
+        }
+        long num = 0L;
+        int i = 0;
+        do {
+            num <<= NumBitsInAByte;
+            num |= 0xff & ba[i];
+            i++;
+        } while (i < MACAddrLengthInBytes);
+        return num;
+    }
+
+    /**
+     * Converts a long number to a 6 bytes array for MAC addresses.
+     *
+     * @param addr
+     *            The long number.
+     * @return The byte array.
+     */
+    public static byte[] longToByteArray6(long addr){
+        byte[] mac = new byte[MACAddrLengthInBytes];
+        int i = MACAddrLengthInBytes - 1;
+        do {
+            mac[i] = (byte) addr;
+            addr >>>= NumBitsInAByte;
+            i--;
+        } while (i >= 0);
+        return mac;
+    }
+
+    /**
+     * Converts an integer number into a 4 bytes array
+     *
+     * @param i
+     *            the integer number
+     * @return the byte array
+     */
+    public static byte[] intToByteArray4(final int i) {
+        return new byte[] { (byte) (i >> 24 & 0xff), (byte) (i >> 16 & 0xff), (byte) (i >> 8 & 0xff),
+                (byte) (i & 0xff) };
+    }
+
+    /**
+     * Converts an IP address passed as integer value into the respective
+     * InetAddress object
+     *
+     * @param address
+     *            the IP address in integer form
+     * @return the IP address in InetAddress form
+     */
+    public static InetAddress getInetAddress(final int address) {
+        InetAddress ip = null;
+        try {
+            ip = InetAddress.getByAddress(NetUtils.intToByteArray4(address));
+        } catch (final UnknownHostException e) {
+            LOG.error("", e);
+        }
+        return ip;
+    }
+
+    /**
+     * Return the InetAddress Network Mask given the length of the prefix bit
+     * mask. The prefix bit mask indicates the contiguous leading bits that are
+     * NOT masked out. Example: A prefix bit mask length of 8 will give an
+     * InetAddress Network Mask of 255.0.0.0
+     *
+     * @param prefixMaskLength
+     *            integer representing the length of the prefix network mask
+     * @param isV6
+     *            boolean representing the IP version of the returned address
+     * @return
+     */
+    public static InetAddress getInetNetworkMask(final int prefixMaskLength, final boolean isV6) {
+        if (prefixMaskLength < 0 || !isV6 && prefixMaskLength > 32 || isV6 && prefixMaskLength > 128) {
+            return null;
+        }
+        byte v4Address[] = { 0, 0, 0, 0 };
+        byte v6Address[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+        byte address[] = isV6 ? v6Address : v4Address;
+        int numBytes = prefixMaskLength / 8;
+        int numBits = prefixMaskLength % 8;
+        int i = 0;
+        for (; i < numBytes; i++) {
+            address[i] = (byte) 0xff;
+        }
+        if (numBits > 0) {
+            int rem = 0;
+            for (int j = 0; j < numBits; j++) {
+                rem |= 1 << 7 - j;
+            }
+            address[i] = (byte) rem;
+        }
+
+        try {
+            return InetAddress.getByAddress(address);
+        } catch (final UnknownHostException e) {
+            LOG.error("", e);
+        }
+        return null;
+    }
+
+    /**
+     * Returns the prefix size in bits of the specified subnet mask. Example:
+     * For the subnet mask ff.ff.ff.e0 it returns 25 while for ff.00.00.00 it
+     * returns 8. If the passed subnetMask array is null, 0 is returned.
+     *
+     * @param subnetMask
+     *            the subnet mask as byte array
+     * @return the prefix length as number of bits
+     */
+    public static int getSubnetMaskLength(final byte[] subnetMask) {
+        int maskLength = 0;
+        if (subnetMask != null && (subnetMask.length == 4 || subnetMask.length == 16)) {
+            int index = 0;
+            while (index < subnetMask.length && subnetMask[index] == (byte) 0xFF) {
+                maskLength += NetUtils.NumBitsInAByte;
+                index++;
+            }
+            if (index != subnetMask.length) {
+                int bits = NetUtils.NumBitsInAByte - 1;
+                while (bits >= 0 && (subnetMask[index] & 1 << bits)  != 0) {
+                    bits--;
+                    maskLength++;
+                }
+            }
+        }
+        return maskLength;
+    }
+
+    /**
+     * Returns the prefix size in bits of the specified subnet mask. Example:
+     * For the subnet mask 255.255.255.128 it returns 25 while for 255.0.0.0 it
+     * returns 8. If the passed subnetMask object is null, 0 is returned
+     *
+     * @param subnetMask
+     *            the subnet mask as InetAddress
+     * @return the prefix length as number of bits
+     */
+    public static int getSubnetMaskLength(final InetAddress subnetMask) {
+        return subnetMask == null ? 0 : NetUtils.getSubnetMaskLength(subnetMask.getAddress());
+    }
+
+    /**
+     * Given an IP address and a prefix network mask length, it returns the
+     * equivalent subnet prefix IP address Example: for ip = "172.28.30.254" and
+     * maskLen = 25 it will return "172.28.30.128"
+     *
+     * @param ip
+     *            the IP address in InetAddress form
+     * @param maskLen
+     *            the length of the prefix network mask
+     * @return the subnet prefix IP address in InetAddress form
+     */
+    public static InetAddress getSubnetPrefix(final InetAddress ip, final int maskLen) {
+        int bytes = maskLen / 8;
+        int bits = maskLen % 8;
+        byte modifiedByte;
+        byte[] sn = ip.getAddress();
+        if (bits > 0) {
+            modifiedByte = (byte) (sn[bytes] >> 8 - bits);
+            sn[bytes] = (byte) (modifiedByte << 8 - bits);
+            bytes++;
+        }
+        for (; bytes < sn.length; bytes++) {
+            sn[bytes] = (byte) 0;
+        }
+        try {
+            return InetAddress.getByAddress(sn);
+        } catch (final UnknownHostException e) {
+            return null;
+        }
+    }
+
+    /**
+     * Checks if the test address and mask conflicts with the filter address and
+     * mask
+     *
+     * For example:
+     * testAddress: 172.28.2.23
+     * testMask: 255.255.255.0
+     * filterAddress: 172.28.1.10
+     * testMask: 255.255.255.0
+     * do conflict
+     *
+     * testAddress: 172.28.2.23
+     * testMask: 255.255.255.0
+     * filterAddress: 172.28.1.10
+     * testMask: 255.255.0.0
+     * do not conflict
+     *
+     * Null parameters are permitted
+     *
+     * @param testAddress
+     * @param filterAddress
+     * @param testMask
+     * @param filterMask
+     * @return
+     */
+    public static boolean inetAddressConflict(final InetAddress testAddress, final InetAddress filterAddress, final InetAddress testMask,
+            final InetAddress filterMask) {
+        // Sanity check
+        if (testAddress == null || filterAddress == null) {
+            return false;
+        }
+
+        // Presence check
+        if (isAny(testAddress) || isAny(filterAddress)) {
+            return false;
+        }
+
+        int testMaskLen = testMask == null ? testAddress instanceof Inet4Address ? 32 : 128 : NetUtils
+                .getSubnetMaskLength(testMask);
+        int filterMaskLen = filterMask == null ? testAddress instanceof Inet4Address ? 32 : 128 : NetUtils
+                .getSubnetMaskLength(filterMask);
+
+        // Mask length check. Test mask has to be more specific than filter one
+        if (testMaskLen < filterMaskLen) {
+            return true;
+        }
+
+        // Subnet Prefix on filter mask length must be the same
+        InetAddress prefix1 = getSubnetPrefix(testAddress, filterMaskLen);
+        InetAddress prefix2 = getSubnetPrefix(filterAddress, filterMaskLen);
+        return !prefix1.equals(prefix2);
+    }
+
+    /**
+     * Returns true if the passed MAC address is all zero
+     *
+     * @param mac
+     *            the byte array representing the MAC address
+     * @return true if all MAC bytes are zero
+     */
+    public static boolean isZeroMAC(final byte[] mac) {
+        for (short i = 0; i < 6; i++) {
+            if (mac[i] != 0) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * Returns true if the MAC address is the broadcast MAC address and false
+     * otherwise.
+     *
+     * @param MACAddress
+     * @return
+     */
+    public static boolean isBroadcastMACAddr(final byte[] MACAddress) {
+        if (MACAddress.length == MACAddrLengthInBytes) {
+            for (int i = 0; i < 6; i++) {
+                if (MACAddress[i] != BroadcastMACAddr[i]) {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        return false;
+    }
+    /**
+     * Returns true if the MAC address is a unicast MAC address and false
+     * otherwise.
+     *
+     * @param MACAddress
+     * @return
+     */
+    public static boolean isUnicastMACAddr(final byte[] MACAddress) {
+        if (MACAddress.length == MACAddrLengthInBytes) {
+            return (MACAddress[0] & 1) == 0;
+        }
+        return false;
+    }
+
+    /**
+     * Returns true if the MAC address is a multicast MAC address and false
+     * otherwise. Note that this explicitly returns false for the broadcast MAC
+     * address.
+     *
+     * @param MACAddress
+     * @return
+     */
+    public static boolean isMulticastMACAddr(final byte[] MACAddress) {
+        if (MACAddress.length == MACAddrLengthInBytes && !isBroadcastMACAddr(MACAddress)) {
+            return (MACAddress[0] & 1) != 0;
+        }
+        return false;
+    }
+
+    /**
+     * Returns true if the passed InetAddress contains all zero
+     *
+     * @param ip
+     *            the IP address to test
+     * @return true if the address is all zero
+     */
+    public static boolean isAny(final InetAddress ip) {
+        for (byte b : ip.getAddress()) {
+            if (b != 0) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static boolean fieldsConflict(final int field1, final int field2) {
+        if (field1 == 0 || field2 == 0 || field1 == field2) {
+            return false;
+        }
+        return true;
+    }
+
+    public static InetAddress parseInetAddress(final String addressString) {
+        InetAddress address = null;
+        try {
+            address = InetAddress.getByName(addressString);
+        } catch (final UnknownHostException e) {
+            LOG.error("", e);
+        }
+        return address;
+    }
+
+    /**
+     * Checks if the passed IP v4 address in string form is valid The address
+     * may specify a mask at the end as "/MM"
+     *
+     * @param cidr
+     *            the v4 address as A.B.C.D/MM
+     * @return
+     */
+    public static boolean isIPv4AddressValid(final String cidr) {
+        if (cidr == null) {
+            return false;
+        }
+
+        String values[] = cidr.split("/");
+        Pattern ipv4Pattern = Pattern
+                .compile("(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])");
+        Matcher mm = ipv4Pattern.matcher(values[0]);
+        if (!mm.matches()) {
+            return false;
+        }
+        if (values.length >= 2) {
+            int prefix = Integer.valueOf(values[1]);
+            if (prefix < 0 || prefix > 32) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * Checks if the passed IP v6 address in string form is valid The address
+     * may specify a mask at the end as "/MMM"
+     *
+     * @param cidr
+     *            the v6 address as A::1/MMM
+     * @return
+     */
+    public static boolean isIPv6AddressValid(final String cidr) {
+        if (cidr == null) {
+            return false;
+        }
+
+        String values[] = cidr.split("/");
+        try {
+            // when given an IP address, InetAddress.getByName validates the ip
+            // address
+            InetAddress addr = InetAddress.getByName(values[0]);
+            if (!(addr instanceof Inet6Address)) {
+                return false;
+            }
+        } catch (final UnknownHostException ex) {
+            return false;
+        }
+
+        if (values.length >= 2) {
+            int prefix = Integer.valueOf(values[1]);
+            if (prefix < 0 || prefix > 128) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * Checks if the passed IP address in string form is a valid v4 or v6
+     * address. The address may specify a mask at the end as "/MMM"
+     *
+     * @param cidr
+     *            the v4 or v6 address as IP/MMM
+     * @return
+     */
+    public static boolean isIPAddressValid(final String cidr) {
+        return NetUtils.isIPv4AddressValid(cidr) || NetUtils.isIPv6AddressValid(cidr);
+    }
+
+    /*
+     * Following utilities are useful when you need to compare or bit shift java
+     * primitive type variable which are inherently signed
+     */
+    /**
+     * Returns the unsigned value of the passed byte variable
+     *
+     * @param b
+     *            the byte value
+     * @return the int variable containing the unsigned byte value
+     */
+    public static int getUnsignedByte(final byte b) {
+        return b & 0xFF;
+    }
+
+    /**
+     * Return the unsigned value of the passed short variable
+     *
+     * @param s
+     *            the short value
+     * @return the int variable containing the unsigned short value
+     */
+    public static int getUnsignedShort(final short s) {
+        return s & 0xFFFF;
+    }
+
+    /**
+     * Returns the highest v4 or v6 InetAddress
+     *
+     * @param v6
+     *            true for IPv6, false for Ipv4
+     * @return The highest IPv4 or IPv6 address
+     */
+    public static InetAddress gethighestIP(final boolean v6) {
+        try {
+            return v6 ? InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") : InetAddress
+                    .getByName("255.255.255.255");
+        } catch (final UnknownHostException e) {
+            return null;
+        }
+    }
+
+    /**
+     * Returns Broadcast MAC Address
+     *
+     * @return the byte array containing  broadcast mac address
+     */
+    public static byte[] getBroadcastMACAddr() {
+        return Arrays.copyOf(BroadcastMACAddr, BroadcastMACAddr.length);
+    }
+}
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/Packet.java b/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/Packet.java
new file mode 100644 (file)
index 0000000..3e3ad14
--- /dev/null
@@ -0,0 +1,359 @@
+/*
+ * Copyright (c) 2013, 2015 Cisco Systems, Inc. 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.controller.liblldp;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract class which represents the generic network packet object It provides
+ * the basic methods which are common for all the packets, like serialize and
+ * deserialize
+ */
+
+public abstract class Packet {
+    protected static final Logger LOG = LoggerFactory.getLogger(Packet.class);
+    // Access level granted to this packet
+    protected boolean writeAccess;
+    // When deserialized from wire, packet could result corrupted
+    protected boolean corrupted;
+    // The packet that encapsulate this packet
+    protected Packet parent;
+    // The packet encapsulated by this packet
+    protected Packet payload;
+    // The unparsed raw payload carried by this packet
+    protected byte[] rawPayload;
+    // Bit coordinates of packet header fields
+    protected Map<String, Pair<Integer, Integer>> hdrFieldCoordMap;
+    // Header fields values: Map<FieldName,Value>
+    protected Map<String, byte[]> hdrFieldsMap;
+    // The class of the encapsulated packet object
+    protected Class<? extends Packet> payloadClass;
+
+    public Packet() {
+        writeAccess = false;
+        corrupted = false;
+    }
+
+    public Packet(final boolean writeAccess) {
+        this.writeAccess = writeAccess;
+        corrupted = false;
+    }
+
+    public Packet getParent() {
+        return parent;
+    }
+
+    public Packet getPayload() {
+        return payload;
+    }
+
+    public void setParent(final Packet parent) {
+        this.parent = parent;
+    }
+
+    public void setPayload(final Packet payload) {
+        this.payload = payload;
+    }
+
+    public void setHeaderField(final String headerField, final byte[] readValue) {
+        hdrFieldsMap.put(headerField, readValue);
+    }
+
+    /**
+     * This method deserializes the data bits obtained from the wire into the
+     * respective header and payload which are of type Packet
+     *
+     * @param data - data from wire to deserialize
+     * @param bitOffset bit position where packet header starts in data
+     *        array
+     * @param size size of packet in bits
+     * @return Packet
+     * @throws PacketException
+     */
+    public Packet deserialize(final byte[] data, final int bitOffset, final int size)
+            throws PacketException {
+
+        // Deserialize the header fields one by one
+        int startOffset = 0, numBits = 0;
+        for (Entry<String, Pair<Integer, Integer>> pairs : hdrFieldCoordMap
+                .entrySet()) {
+            String hdrField = pairs.getKey();
+            startOffset = bitOffset + this.getfieldOffset(hdrField);
+            numBits = this.getfieldnumBits(hdrField);
+
+            byte[] hdrFieldBytes = null;
+            try {
+                hdrFieldBytes = BitBufferHelper.getBits(data, startOffset,
+                        numBits);
+            } catch (final BufferException e) {
+                throw new PacketException(e.getMessage());
+            }
+
+            /*
+             * Store the raw read value, checks the payload type and set the
+             * payloadClass accordingly
+             */
+            this.setHeaderField(hdrField, hdrFieldBytes);
+
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("{}: {}: {} (offset {} bitsize {})",
+                        new Object[] { this.getClass().getSimpleName(), hdrField,
+                        HexEncode.bytesToHexString(hdrFieldBytes),
+                        startOffset, numBits });
+            }
+        }
+
+        // Deserialize the payload now
+        int payloadStart = startOffset + numBits;
+        int payloadSize = data.length * NetUtils.NumBitsInAByte - payloadStart;
+
+        if (payloadClass != null) {
+            try {
+                payload = payloadClass.newInstance();
+            } catch (final Exception e) {
+                throw new RuntimeException(
+                        "Error parsing payload for Ethernet packet", e);
+            }
+            payload.deserialize(data, payloadStart, payloadSize);
+            payload.setParent(this);
+        } else {
+            /*
+             *  The payload class was not set, it means no class for parsing
+             *  this payload is present. Let's store the raw payload if any.
+             */
+            int start = payloadStart / NetUtils.NumBitsInAByte;
+            int stop = start + payloadSize / NetUtils.NumBitsInAByte;
+            rawPayload = Arrays.copyOfRange(data, start, stop);
+        }
+
+
+        // Take care of computation that can be done only after deserialization
+        postDeserializeCustomOperation(data, payloadStart - getHeaderSize());
+
+        return this;
+    }
+
+    /**
+     * This method serializes the header and payload from the respective
+     * packet class, into a single stream of bytes to be sent on the wire
+     *
+     * @return The byte array representing the serialized Packet
+     * @throws PacketException
+     */
+    public byte[] serialize() throws PacketException {
+
+        // Acquire or compute the serialized payload
+        byte[] payloadBytes = null;
+        if (payload != null) {
+            payloadBytes = payload.serialize();
+        } else if (rawPayload != null) {
+            payloadBytes = rawPayload;
+        }
+        int payloadSize = payloadBytes == null ? 0 : payloadBytes.length;
+
+        // Allocate the buffer to contain the full (header + payload) packet
+        int headerSize = this.getHeaderSize() / NetUtils.NumBitsInAByte;
+        byte packetBytes[] = new byte[headerSize + payloadSize];
+        if (payloadBytes != null) {
+            System.arraycopy(payloadBytes, 0, packetBytes, headerSize, payloadSize);
+        }
+
+        // Serialize this packet header, field by field
+        for (Map.Entry<String, Pair<Integer, Integer>> pairs : hdrFieldCoordMap
+                .entrySet()) {
+            String field = pairs.getKey();
+            byte[] fieldBytes = hdrFieldsMap.get(field);
+            // Let's skip optional fields when not set
+            if (fieldBytes != null) {
+                try {
+                    BitBufferHelper.setBytes(packetBytes, fieldBytes,
+                            getfieldOffset(field), getfieldnumBits(field));
+                } catch (final BufferException e) {
+                    throw new PacketException(e.getMessage());
+                }
+            }
+        }
+
+        // Perform post serialize operations (like checksum computation)
+        postSerializeCustomOperation(packetBytes);
+
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("{}: {}", this.getClass().getSimpleName(),
+                    HexEncode.bytesToHexString(packetBytes));
+        }
+
+        return packetBytes;
+    }
+
+    /**
+     * This method gets called at the end of the serialization process It is
+     * intended for the child packets to insert some custom data into the output
+     * byte stream which cannot be done or cannot be done efficiently during the
+     * normal Packet.serialize() path. An example is the checksum computation
+     * for IPv4
+     *
+     * @param myBytes serialized bytes
+     * @throws PacketException
+     */
+    protected void postSerializeCustomOperation(byte[] myBytes)
+            throws PacketException {
+        // no op
+    }
+
+    /**
+     * This method re-computes the checksum of the bits received on the wire and
+     * validates it with the checksum in the bits received Since the computation
+     * of checksum varies based on the protocol, this method is overridden.
+     * Currently only IPv4 and ICMP do checksum computation and validation. TCP
+     * and UDP need to implement these if required.
+     *
+     * @param data The byte stream representing the Ethernet frame
+     * @param startBitOffset The bit offset from where the byte array corresponding to this Packet starts in the frame
+     * @throws PacketException
+     */
+    protected void postDeserializeCustomOperation(byte[] data, int startBitOffset)
+            throws PacketException {
+        // no op
+    }
+
+    /**
+     * Gets the header length in bits
+     *
+     * @return int the header length in bits
+     */
+    public int getHeaderSize() {
+        int size = 0;
+        /*
+         * We need to iterate over the fields that were read in the frame
+         * (hdrFieldsMap) not all the possible ones described in
+         * hdrFieldCoordMap. For ex, 802.1Q may or may not be there
+         */
+        for (Map.Entry<String, byte[]> fieldEntry : hdrFieldsMap.entrySet()) {
+            if (fieldEntry.getValue() != null) {
+                String field = fieldEntry.getKey();
+                size += getfieldnumBits(field);
+            }
+        }
+        return size;
+    }
+
+    /**
+     * This method fetches the start bit offset for header field specified by
+     * 'fieldname'. The offset is present in the hdrFieldCoordMap of the
+     * respective packet class
+     *
+     * @return Integer - startOffset of the requested field
+     */
+    public int getfieldOffset(final String fieldName) {
+        return hdrFieldCoordMap.get(fieldName).getLeft();
+    }
+
+    /**
+     * This method fetches the number of bits for header field specified by
+     * 'fieldname'. The numBits are present in the hdrFieldCoordMap of the
+     * respective packet class
+     *
+     * @return Integer - number of bits of the requested field
+     */
+    public int getfieldnumBits(final String fieldName) {
+        return hdrFieldCoordMap.get(fieldName).getRight();
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder ret = new StringBuilder();
+        ret.append(this.getClass().getSimpleName());
+        ret.append(": [");
+        for (String field : hdrFieldCoordMap.keySet()) {
+            byte[] value = hdrFieldsMap.get(field);
+            ret.append(field);
+            ret.append(": ");
+            ret.append(HexEncode.bytesToHexString(value));
+            ret.append(", ");
+        }
+        ret.replace(ret.length()-2, ret.length()-1, "]");
+        return ret.toString();
+    }
+
+    /**
+     * Returns the raw payload carried by this packet in case payload was not
+     * parsed. Caller can call this function in case the getPaylod() returns null.
+     *
+     * @return The raw payload if not parsable as an array of bytes, null otherwise
+     */
+    public byte[] getRawPayload() {
+        return rawPayload;
+    }
+
+    /**
+     * Set a raw payload in the packet class
+     *
+     * @param payload The raw payload as byte array
+     */
+    public void setRawPayload(final byte[] payload) {
+        this.rawPayload = Arrays.copyOf(payload, payload.length);
+    }
+
+    /**
+     * Return whether the deserialized packet is to be considered corrupted.
+     * This is the case when the checksum computed after reconstructing the
+     * packet received from wire is not equal to the checksum read from the
+     * stream. For the Packet class which do not have a checksum field, this
+     * function will always return false.
+     *
+     *
+     * @return true if the deserialized packet's recomputed checksum is not
+     *         equal to the packet carried checksum
+     */
+    public boolean isCorrupted() {
+        return corrupted;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result
+                + (this.hdrFieldsMap == null ? 0 : hdrFieldsMap.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        Packet other = (Packet) obj;
+        if (hdrFieldsMap == other.hdrFieldsMap) {
+            return true;
+        }
+        if (hdrFieldsMap == null || other.hdrFieldsMap == null) {
+            return false;
+        }
+        if (hdrFieldsMap != null && other.hdrFieldsMap != null) {
+            for (String field : hdrFieldsMap.keySet()) {
+                if (!Arrays.equals(hdrFieldsMap.get(field), other.hdrFieldsMap.get(field))) {
+                    return false;
+                }
+            }
+        } else {
+            return false;
+        }
+        return true;
+    }
+}
diff --git a/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/PacketException.java b/libraries/liblldp/src/main/java/org/opendaylight/controller/liblldp/PacketException.java
new file mode 100644 (file)
index 0000000..14990e1
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.liblldp;
+
+/**
+ * Describes an exception that is raised when the process of serializing or
+ * deserializing a network packet/stream fails. This generally happens when the
+ * packet/stream is malformed.
+ *
+ */
+public class PacketException extends Exception {
+    private static final long serialVersionUID = 1L;
+
+    public PacketException(final String message) {
+        super(message);
+    }
+
+    public PacketException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}
diff --git a/libraries/liblldp/src/test/java/org/opendaylight/controller/liblldp/HexEncodeTest.java b/libraries/liblldp/src/test/java/org/opendaylight/controller/liblldp/HexEncodeTest.java
new file mode 100644 (file)
index 0000000..18aa300
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.liblldp;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class HexEncodeTest {
+    @Test
+    public void testbytesToHexString() {
+        byte[] bytes1 = { (byte) 0x01, (byte) 0x02, (byte) 0x03 };
+        String str1 = HexEncode.bytesToHexString(bytes1);
+        Assert.assertTrue(str1.equals("010203"));
+
+        byte[] bytes2 = { (byte) 0x11, (byte) 0x22, (byte) 0x33 };
+        String str2 = HexEncode.bytesToHexString(bytes2);
+        Assert.assertFalse(str2.equals("010203"));
+
+    }
+
+    @Test
+    public void testLongToHexString() {
+        long value1 = 12345678L;
+        String str1 = HexEncode.longToHexString(value1);
+        Assert.assertTrue(str1.equals("00:00:00:00:00:bc:61:4e"));
+
+        long value2 = 98765432L;
+        String str2 = HexEncode.longToHexString(value2);
+        Assert.assertFalse(str2.equals("00:44:33:22:11:bc:61:4e"));
+
+    }
+
+    @Test
+    public void testBytesFromHexString() {
+        String byteStr1 = "00:11:22:33:44:55";
+        byte byteArray1[] = HexEncode.bytesFromHexString(byteStr1);
+
+        Assert.assertTrue(byteArray1[0] == (byte) 0x0);
+        Assert.assertTrue(byteArray1[1] == (byte) 0x11);
+        Assert.assertTrue(byteArray1[2] == (byte) 0x22);
+        Assert.assertTrue(byteArray1[3] == (byte) 0x33);
+        Assert.assertTrue(byteArray1[4] == (byte) 0x44);
+        Assert.assertTrue(byteArray1[5] == (byte) 0x55);
+
+        String byteStr2 = "00:11:22:33:44:55";
+        byte byteArray2[] = HexEncode.bytesFromHexString(byteStr2);
+
+        Assert.assertFalse(byteArray2[0] == (byte) 0x55);
+        Assert.assertFalse(byteArray2[1] == (byte) 0x44);
+        Assert.assertFalse(byteArray2[2] == (byte) 0x33);
+        Assert.assertFalse(byteArray2[3] == (byte) 0x22);
+        Assert.assertFalse(byteArray2[4] == (byte) 0x11);
+        Assert.assertFalse(byteArray2[5] == (byte) 0x0);
+
+    }
+}
diff --git a/libraries/liblldp/src/test/java/org/opendaylight/controller/liblldp/LLDPTLVTest.java b/libraries/liblldp/src/test/java/org/opendaylight/controller/liblldp/LLDPTLVTest.java
new file mode 100644 (file)
index 0000000..23f8ae6
--- /dev/null
@@ -0,0 +1,81 @@
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.controller.liblldp;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.io.BaseEncoding;
+import com.google.common.primitives.Bytes;
+
+/**
+ *
+ */
+public class LLDPTLVTest {
+
+    /** dummy custom tlv value */
+    private static final String CUSTOM_TLV_ULTIMATE = "What do you get when you multiply 6 by 9?";
+    /** dummy custom tlv value in binary form */
+    private static final byte[] CUSTOM_TLV_ULTIMATE_BIN = new byte[] {
+        0x57, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x67, 0x65, 0x74,
+        0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6d, 0x75, 0x6c, 0x74, 0x69,
+        0x70, 0x6c, 0x79, 0x20, 0x36, 0x20, 0x62, 0x79, 0x20, 0x39, 0x3f
+    };
+
+    private static final Logger LOG = LoggerFactory.getLogger(LLDPTLVTest.class);
+
+    /**
+     * Test method for
+     * {@link org.opendaylight.controller.liblldp.LLDPTLV#createCustomTLVValue(java.lang.String)}
+     * .
+     */
+    @Test
+    public void testCreateCustomTLVValue() {
+        byte[] tlv = LLDPTLV.createCustomTLVValue(CUSTOM_TLV_ULTIMATE);
+
+        byte[] expectedCustomTlv = Bytes.concat(new byte[] {
+                // custom type (7b) + length (9b) = 16b = 2B  (skipped)
+                // 0x7f, 24,
+                // openflow OUI
+                0x00, 0x26, (byte) 0xe1,
+                // subtype
+                0x00},
+                // custom value
+                CUSTOM_TLV_ULTIMATE_BIN);
+
+        BaseEncoding be = BaseEncoding.base16().withSeparator(" ", 2).lowerCase();
+        LOG.debug("expected: {}", be.encode(expectedCustomTlv));
+        LOG.debug("actual  : {}", be.encode(tlv));
+        Assert.assertArrayEquals(expectedCustomTlv, tlv);
+    }
+
+    /**
+     * Test method for
+     * {@link org.opendaylight.controller.liblldp.LLDPTLV#getCustomString(byte[], int)}
+     * .
+     * @throws Exception
+     */
+    @Test
+    public void testGetCustomString() throws Exception {
+        byte[] inputCustomTlv = Bytes.concat(new byte[] {
+                // custom type (7b) + length (9b) = 16b = 2B  (skipped)
+                // 0x7f, 24,
+                // openflow OUI
+                0x00, 0x26, (byte) 0xe1,
+                // subtype
+                0x00},
+                // custom value
+                CUSTOM_TLV_ULTIMATE_BIN);
+
+        String actual = LLDPTLV.getCustomString(inputCustomTlv, inputCustomTlv.length);
+        LOG.debug("actual custom TLV value as string: {}", actual);
+        Assert.assertEquals(CUSTOM_TLV_ULTIMATE, actual);
+    }
+}
diff --git a/libraries/liblldp/src/test/java/org/opendaylight/controller/liblldp/LLDPTest.java b/libraries/liblldp/src/test/java/org/opendaylight/controller/liblldp/LLDPTest.java
new file mode 100644 (file)
index 0000000..6716ffa
--- /dev/null
@@ -0,0 +1,257 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.controller.liblldp;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.internal.ArrayComparisonFailure;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.primitives.Bytes;
+
+/**
+ * Test of {@link LLDP} serialization feature (TODO: and deserialization)
+ */
+public class LLDPTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(LLDPTest.class);
+
+    private static final byte[] CHASSIS_ID_VALUE = "chassis".getBytes();
+    private static final short CHASSIS_ID_LENGTH = (short) CHASSIS_ID_VALUE.length;
+
+    private static final byte[] TTL_VALUE = new byte[] { (byte) 0, (byte) 100 };
+    private static final short TTL_LENGTH = (short) TTL_VALUE.length;
+
+    private static final byte[] PORT_VALUE = "dummy port id".getBytes();
+    private static final short PORT_LENGTH = (short) PORT_VALUE.length;
+
+    private static final byte[] SYSTEM_NAME_VALUE = "dummy system name".getBytes();
+    private static final short SYSTEM_NAME_LENGTH = (short) SYSTEM_NAME_VALUE.length;
+
+    private static final byte SYSTEM_CAPABILITIES_TLV = 8;
+    private static final byte[] SYSTEM_CAPABILITIES_VALUE = "dummy system capabilities".getBytes();
+    private static final short SYSTEM_CAPABILITIES_LENGTH = (short) SYSTEM_CAPABILITIES_VALUE.length;
+
+    private static final byte[] OUI = LLDPTLV.OFOUI;
+
+    private static final byte[] OUI_SUBTYPE_A = new byte[] { (byte) 0 };
+    private static final byte[] CUSTOM_SUBTYPE_A_VALUE = "first custom value A".getBytes();
+    private static final short CUSTOM_SUBTYPE_A_LENGTH = (short) (OUI.length + OUI_SUBTYPE_A.length + CUSTOM_SUBTYPE_A_VALUE.length);
+
+    private static final byte[] OUI_SUBTYPE_B = new byte[] { (byte) 1 };
+    private static final byte[] CUSTOM_SUBTYPE_B_VALUE = "second custom value B".getBytes();
+    private static final short CUSTOM_SUBTYPE_B_LENGTH = (short) (OUI.length + OUI_SUBTYPE_B.length + CUSTOM_SUBTYPE_B_VALUE.length);
+
+    private static final byte[] BYTES_BEFORE_CUSTOM_A = new byte[] { 0x00, 0x26, (byte) 0xe1, OUI_SUBTYPE_A[0] };
+    private static final byte[] BYTES_BEFORE_CUSTOM_B = new byte[] { 0x00, 0x26, (byte) 0xe1, OUI_SUBTYPE_B[0] };
+    private LLDP lldpBuilder;
+
+    @Before
+    public void setup() {
+        lldpBuilder = new LLDP();
+    }
+
+    /**
+     * Tests whether serialization of LLDP packet is correct
+     *
+     * @see LLDP#serialize()
+     * @throws PacketException
+     */
+    @Test
+    public void testSerialize() throws PacketException {
+        lldpBuilder.setChassisId(dummyTlv(LLDPTLV.TLVType.ChassisID.getValue(), CHASSIS_ID_LENGTH, CHASSIS_ID_VALUE));
+        lldpBuilder.setTtl(dummyTlv(LLDPTLV.TLVType.TTL.getValue(), TTL_LENGTH, TTL_VALUE));
+        lldpBuilder.setPortId(dummyTlv(LLDPTLV.TLVType.PortID.getValue(), PORT_LENGTH, PORT_VALUE));
+        lldpBuilder.setSystemNameId(dummyTlv(LLDPTLV.TLVType.SystemName.getValue(), SYSTEM_NAME_LENGTH,
+                SYSTEM_NAME_VALUE));
+
+        // adding optional TLVs for which doesn't exist special set* methods in LLDP
+        final List<LLDPTLV> optionalTLVs = new ArrayList<>();
+        // System Capabilities TLV (type = 7)
+        optionalTLVs.add(dummyTlv(SYSTEM_CAPABILITIES_TLV, SYSTEM_CAPABILITIES_LENGTH, SYSTEM_CAPABILITIES_VALUE));
+        lldpBuilder.setOptionalTLVList(optionalTLVs);
+
+        // adding custom TLVs
+        lldpBuilder.addCustomTLV(dummyCustomTlv(LLDPTLV.TLVType.Custom.getValue(), OUI, OUI_SUBTYPE_A,
+                CUSTOM_SUBTYPE_A_LENGTH, CUSTOM_SUBTYPE_A_VALUE));
+        lldpBuilder.addCustomTLV(dummyCustomTlv(LLDPTLV.TLVType.Custom.getValue(), OUI, OUI_SUBTYPE_B,
+                CUSTOM_SUBTYPE_B_LENGTH, CUSTOM_SUBTYPE_B_VALUE));
+
+        byte[] serialized = lldpBuilder.serialize();
+
+        int offset = 0;
+        offset = checkTLV(serialized, offset, (byte) 0b00000010, "ChassisID", CHASSIS_ID_LENGTH, CHASSIS_ID_VALUE);
+        offset = checkTLV(serialized, offset, (byte) 0b00000110, "TTL", TTL_LENGTH, TTL_VALUE);
+        offset = checkTLV(serialized, offset, (byte) 0b00000100, "PortID", PORT_LENGTH, PORT_VALUE);
+        offset = checkTLV(serialized, offset, (byte) 0b00001010, "SystemName", SYSTEM_NAME_LENGTH, SYSTEM_NAME_VALUE);
+        offset = checkTLV(serialized, offset, (byte) 0b00010000, "System capabilities", SYSTEM_CAPABILITIES_LENGTH,
+                SYSTEM_CAPABILITIES_VALUE);
+        offset = checkTLV(serialized, offset, (byte) 0b11111110, "Custom subtype A", CUSTOM_SUBTYPE_A_LENGTH,
+                CUSTOM_SUBTYPE_A_VALUE, OUI[0], OUI[1], OUI[2], OUI_SUBTYPE_A[0]);
+        offset = checkTLV(serialized, offset, (byte) 0b11111110, "Custom subtype B", CUSTOM_SUBTYPE_B_LENGTH,
+                CUSTOM_SUBTYPE_B_VALUE, OUI[0], OUI[1], OUI[2], OUI_SUBTYPE_B[0]);
+
+    }
+
+    /**
+     * Tests whether serialization of LLDP packet is correct
+     *
+     * @see LLDP#deserialize(byte[], int, int)
+     * @throws Exception
+     */
+    @Test
+    public void testDeserialize() throws Exception {
+
+        byte[] rawLldpTlv = Bytes
+                .concat(awaitedBytes((byte) 0b00000010, CHASSIS_ID_LENGTH, CHASSIS_ID_VALUE, null),
+                        awaitedBytes((byte) 0b00000110, TTL_LENGTH, TTL_VALUE, null),
+                        awaitedBytes((byte) 0b00000100, PORT_LENGTH, PORT_VALUE, null),
+                        awaitedBytes((byte) 0b00001010, SYSTEM_NAME_LENGTH, SYSTEM_NAME_VALUE, null),
+                        awaitedBytes((byte) 0b00010010, SYSTEM_CAPABILITIES_LENGTH, SYSTEM_CAPABILITIES_VALUE, null),
+                        awaitedBytes((byte) 0b11111110, CUSTOM_SUBTYPE_A_LENGTH, CUSTOM_SUBTYPE_A_VALUE,
+                                BYTES_BEFORE_CUSTOM_A),
+                        awaitedBytes((byte) 0b11111110, CUSTOM_SUBTYPE_B_LENGTH, CUSTOM_SUBTYPE_B_VALUE,
+                                BYTES_BEFORE_CUSTOM_B));
+
+        lldpBuilder.deserialize(rawLldpTlv, 0, rawLldpTlv.length * NetUtils.NumBitsInAByte);
+        Assert.assertEquals("chassis", new String(lldpBuilder.getChassisId().getValue()));
+        Assert.assertArrayEquals(TTL_VALUE, lldpBuilder.getTtl().getValue());
+        Assert.assertEquals("dummy port id", new String(lldpBuilder.getPortId().getValue()));
+        Assert.assertEquals("dummy system name", new String(lldpBuilder.getSystemNameId().getValue()));
+
+        // optional items check
+        Iterator<LLDPTLV> iteratorTlvOptional = lldpBuilder.getOptionalTLVList().iterator();
+
+        assertTrue(iteratorTlvOptional.hasNext());
+        LLDPTLV item0 = iteratorTlvOptional.next();
+        Assert.assertEquals(5, item0.getType());
+        Assert.assertEquals("dummy system name", new String(item0.getValue()));
+        assertTrue(iteratorTlvOptional.hasNext());
+
+        assertTrue(iteratorTlvOptional.hasNext());
+        LLDPTLV item1 = iteratorTlvOptional.next();
+        Assert.assertEquals(9, item1.getType());
+        Assert.assertEquals("dummy system capabilities", new String(item1.getValue()));
+        assertFalse(iteratorTlvOptional.hasNext());
+
+        // custom items check
+        Iterable<LLDPTLV> customTlvs = lldpBuilder.getCustomTlvList();
+        Iterator<LLDPTLV> iteratorLLDPTLV = customTlvs.iterator();
+        assertEquals(true, iteratorLLDPTLV.hasNext());
+        checkCustomTlv(iteratorLLDPTLV.next(), "first custom value A");
+        assertEquals(true, iteratorLLDPTLV.hasNext());
+        checkCustomTlv(iteratorLLDPTLV.next(), "second custom value B");
+        assertEquals(false, iteratorLLDPTLV.hasNext());
+    }
+
+    /**
+     * Test of {@link LLDP#addCustomTLV(LLDPTLV)}
+     *
+     * @throws PacketException
+     */
+    @Test
+    public void testAddCustomTLV() throws PacketException {
+        byte[] customA = awaitedBytes((byte) 0b11111110, CUSTOM_SUBTYPE_A_LENGTH, CUSTOM_SUBTYPE_A_VALUE,
+                BYTES_BEFORE_CUSTOM_A);
+        byte[] customB = awaitedBytes((byte) 0b11111110, CUSTOM_SUBTYPE_B_LENGTH, CUSTOM_SUBTYPE_B_VALUE,
+                BYTES_BEFORE_CUSTOM_B);
+
+        Packet lldptlvA = new LLDPTLV().deserialize(customA, 0, customA.length);
+        assertTrue(lldptlvA instanceof LLDPTLV);
+        Packet lldptlvB = new LLDPTLV().deserialize(customB, 0, customB.length);
+        assertTrue(lldptlvB instanceof LLDPTLV);
+
+        lldpBuilder.addCustomTLV((LLDPTLV) lldptlvA);
+        lldpBuilder.addCustomTLV((LLDPTLV) lldptlvB);
+
+        Iterator<LLDPTLV> customTLVsIterator = lldpBuilder.getCustomTlvList().iterator();
+        assertTrue(customTLVsIterator.hasNext());
+        customTLVsIterator.next();
+        assertTrue(customTLVsIterator.hasNext());
+        customTLVsIterator.next();
+        assertFalse(customTLVsIterator.hasNext());
+    }
+
+    @Test
+    public void testGetCustomTLV() throws PacketException {
+        int ouiInt = BitBufferHelper.getInt(OUI);
+        CustomTLVKey key = new CustomTLVKey(ouiInt, OUI_SUBTYPE_A[0]);
+        LLDPTLV customTLV = lldpBuilder.getCustomTLV(key);
+        assertNull(customTLV);
+
+        byte[] customA = awaitedBytes((byte) 0b11111110, CUSTOM_SUBTYPE_A_LENGTH, CUSTOM_SUBTYPE_A_VALUE,
+                BYTES_BEFORE_CUSTOM_A);
+        lldpBuilder.deserialize(customA, 0, customA.length);
+
+        customTLV = lldpBuilder.getCustomTLV(key);
+        assertNotNull(customTLV);
+        assertEquals(ouiInt, LLDPTLV.extractCustomOUI(customTLV));
+        assertEquals(OUI_SUBTYPE_A[0], LLDPTLV.extractCustomSubtype(customTLV));
+    }
+
+    /**
+     * @param customItem
+     * @param expectedValue
+     */
+    private static void checkCustomTlv(final LLDPTLV customItem, final String expectedValue) {
+        Assert.assertEquals(127, customItem.getType());
+        LOG.debug("custom TLV1.length: {}", customItem.getLength());
+        Assert.assertEquals(expectedValue,
+                new String(LLDPTLV.getCustomString(customItem.getValue(), customItem.getLength())));
+    }
+
+    private static int checkTLV(final byte[] serializedData, final int offset, final byte typeTLVBits, final String typeTLVName,
+            final short lengthTLV, final byte[] valueTLV, final byte... bytesBeforeValue) throws ArrayComparisonFailure {
+        byte[] concreteTlvAwaited = awaitedBytes(typeTLVBits, lengthTLV, valueTLV, bytesBeforeValue);
+        int concreteTlvAwaitLength = concreteTlvAwaited.length;
+        assertArrayEquals("Serialization problem " + typeTLVName, concreteTlvAwaited,
+                ArrayUtils.subarray(serializedData, offset, offset + concreteTlvAwaitLength));
+        return offset + concreteTlvAwaitLength;
+    }
+
+    private static byte[] awaitedBytes(final byte typeTLV, final short length, final byte[] value, final byte[] bytesBeforeValue) {
+        byte[] awaited = ArrayUtils.EMPTY_BYTE_ARRAY;
+
+        // 0 - the less meaning byte (right), 1 most meaning byte (left)
+        byte lengthByte0 = (byte) length;
+        byte lengthByte1 = (byte) (length >> 8);
+
+        awaited = ArrayUtils.addAll(awaited, (byte) (typeTLV | lengthByte1), lengthByte0);
+        awaited = ArrayUtils.addAll(awaited, bytesBeforeValue);
+        awaited = ArrayUtils.addAll(awaited, value);
+        return awaited;
+    }
+
+    private static LLDPTLV dummyCustomTlv(final byte tlvType, final byte[] oui, final byte[] ouiSubtype, final short customLength,
+            final byte[] subtypeValue) {
+        byte[] fullCustomValue = new byte[0];
+        fullCustomValue = ArrayUtils.addAll(fullCustomValue, oui);
+        fullCustomValue = ArrayUtils.addAll(fullCustomValue, ouiSubtype);
+        fullCustomValue = ArrayUtils.addAll(fullCustomValue, subtypeValue);
+        return dummyTlv(tlvType, customLength, fullCustomValue);
+    }
+
+    private static LLDPTLV dummyTlv(final byte concreteTlv, final short concreteLength, final byte[] concreteValue) {
+        LLDPTLV tlv = new LLDPTLV();
+        tlv.setType(concreteTlv).setLength(concreteLength).setValue(concreteValue);
+        return tlv;
+    }
+}
diff --git a/libraries/liblldp/src/test/java/org/opendaylight/controller/sal/packet/BitBufferHelperTest.java b/libraries/liblldp/src/test/java/org/opendaylight/controller/sal/packet/BitBufferHelperTest.java
new file mode 100644 (file)
index 0000000..0ba5476
--- /dev/null
@@ -0,0 +1,691 @@
+/*
+ * Copyright (c) 2014, 2015 Cisco Systems, Inc. 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.controller.sal.packet;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.controller.liblldp.BitBufferHelper;
+
+public class BitBufferHelperTest {
+
+    @Test
+    public void testGetByte() {
+        byte[] data = { 100 };
+        Assert.assertTrue(BitBufferHelper.getByte(data) == 100);
+    }
+
+    @Test
+    public void testGetBits() throws Exception {
+        byte[] data = { 10, 12, 14, 20, 55, 69, 82, 97, 109, 117, 127, -50 };
+        byte[] bits;
+
+        bits = BitBufferHelper.getBits(data, 88, 8); //BYTE extraOffsetBits = extranumBits = 0
+        Assert.assertTrue(bits[0] == -50);
+
+        bits = BitBufferHelper.getBits(data, 8, 16); //Short
+        Assert.assertTrue(bits[0] == 12);
+        Assert.assertTrue(bits[1] == 14);
+
+        bits = BitBufferHelper.getBits(data, 32, 32); //Int
+        Assert.assertTrue(bits[0] == 55);
+        Assert.assertTrue(bits[1] == 69);
+        Assert.assertTrue(bits[2] == 82);
+        Assert.assertTrue(bits[3] == 97);
+
+        bits = BitBufferHelper.getBits(data, 16, 48); //Long
+        Assert.assertTrue(bits[0] == 14);
+        Assert.assertTrue(bits[1] == 20);
+        Assert.assertTrue(bits[2] == 55);
+        Assert.assertTrue(bits[3] == 69);
+        Assert.assertTrue(bits[4] == 82);
+        Assert.assertTrue(bits[5] == 97);
+
+        bits = BitBufferHelper.getBits(data, 40, 7); //BYTE extraOffsetBits = extranumBits != 0
+        Assert.assertTrue(bits[0] == 34);
+
+        bits = BitBufferHelper.getBits(data, 8, 13); //Short
+        Assert.assertTrue(bits[0] == 1);
+        Assert.assertTrue(bits[1] == -127);
+
+        bits = BitBufferHelper.getBits(data, 32, 28); //Int
+        Assert.assertTrue(bits[0] == 3);
+        Assert.assertTrue(bits[1] == 116);
+        Assert.assertTrue(bits[2] == 85);
+        Assert.assertTrue(bits[3] == 38);
+
+        bits = BitBufferHelper.getBits(data, 16, 41); //Long
+        Assert.assertTrue(bits[0] == 0);
+        Assert.assertTrue(bits[1] == 28);
+        Assert.assertTrue(bits[2] == 40);
+        Assert.assertTrue(bits[3] == 110);
+        Assert.assertTrue(bits[4] == -118);
+        Assert.assertTrue(bits[5] == -92);
+
+        bits = BitBufferHelper.getBits(data, 3, 7); //BYTE extraOffsetBits != 0; extranumBits == 0
+        Assert.assertTrue(bits[0] == 40);
+
+        bits = BitBufferHelper.getBits(data, 13, 16); //Short
+        Assert.assertTrue(bits[0] == -127);
+        Assert.assertTrue(bits[1] == -62);
+
+        bits = BitBufferHelper.getBits(data, 5, 32); //Int
+        Assert.assertTrue(bits[0] == 65);
+        Assert.assertTrue(bits[1] == -127);
+        Assert.assertTrue(bits[2] == -62);
+        Assert.assertTrue(bits[3] == -122);
+
+        bits = BitBufferHelper.getBits(data, 23, 48); //Long
+        Assert.assertTrue(bits[0] == 10);
+        Assert.assertTrue(bits[1] == 27);
+        Assert.assertTrue(bits[2] == -94);
+        Assert.assertTrue(bits[3] == -87);
+        Assert.assertTrue(bits[4] == 48);
+        Assert.assertTrue(bits[5] == -74);
+
+        bits = BitBufferHelper.getBits(data, 66, 9); //BYTE extraOffsetBits != 0; extranumBits != 0
+        Assert.assertTrue(bits[0] == 1);
+        Assert.assertTrue(bits[1] == 107);
+
+        bits = BitBufferHelper.getBits(data, 13, 15); //Short
+        Assert.assertTrue(bits[0] == 64);
+        Assert.assertTrue(bits[1] == -31);
+
+        bits = BitBufferHelper.getBits(data, 5, 29); //Int
+        Assert.assertTrue(bits[0] == 8);
+        Assert.assertTrue(bits[1] == 48);
+        Assert.assertTrue(bits[2] == 56);
+        Assert.assertTrue(bits[3] == 80);
+
+        bits = BitBufferHelper.getBits(data, 31, 43); //Long
+        Assert.assertTrue(bits[0] == 0);
+        Assert.assertTrue(bits[1] == -35);
+        Assert.assertTrue(bits[2] == 21);
+        Assert.assertTrue(bits[3] == 73);
+        Assert.assertTrue(bits[4] == -123);
+        Assert.assertTrue(bits[5] == -75);
+
+        bits = BitBufferHelper.getBits(data, 4, 12); //Short
+        Assert.assertTrue(bits[0] == 10);
+        Assert.assertTrue(bits[1] == 12);
+
+        byte[] data1 = { 0, 8 };
+        bits = BitBufferHelper.getBits(data1, 7, 9); //Short
+        Assert.assertTrue(bits[0] == 0);
+        Assert.assertTrue(bits[1] == 8);
+
+        byte[] data2 = { 2, 8 };
+        bits = BitBufferHelper.getBits(data2, 0, 7); //Short
+        Assert.assertTrue(bits[0] == 1);
+
+        bits = BitBufferHelper.getBits(data2, 7, 9); //Short
+        Assert.assertTrue(bits[0] == 0);
+        Assert.assertTrue(bits[1] == 8);
+    }
+
+    // [01101100][01100000]
+    //     [01100011]
+    @Test
+    public void testGetBytes() throws Exception {
+        byte data[] = { 108, 96, 125, -112, 5, 6, 108, 8, 9, 10, 11, 12, 13,
+                14, 15, 16, 17, 18, 19, 20, 21, 22 };
+        byte[] x;
+
+        Assert.assertTrue(BitBufferHelper.getBits(data, 0, 8)[0] == 108);
+        Assert.assertTrue(BitBufferHelper.getBits(data, 8, 8)[0] == 96);
+
+        x = BitBufferHelper.getBits(data, 0, 10);
+        Assert.assertTrue(x[0] == 1);
+        Assert.assertTrue(x[1] == -79);
+
+        x = BitBufferHelper.getBits(data, 3, 8);
+        Assert.assertTrue(x[0] == 99);
+        //Assert.assertTrue(x[1] == 97);
+
+    }
+
+    @Test
+    public void testMSBMask() {
+        int numBits = 1; //MSB
+        int mask = BitBufferHelper.getMSBMask(numBits);
+        Assert.assertTrue(mask == 128);
+
+        numBits = 8;
+        mask = BitBufferHelper.getMSBMask(numBits);
+        Assert.assertTrue(mask == 255);
+
+        numBits = 2;
+        mask = BitBufferHelper.getMSBMask(numBits);
+        Assert.assertTrue(mask == 192);
+    }
+
+    @Test
+    public void testLSBMask() {
+        int numBits = 1; //LSB
+        int mask = BitBufferHelper.getLSBMask(numBits);
+        Assert.assertTrue(mask == 1);
+
+        numBits = 3;
+        mask = BitBufferHelper.getLSBMask(numBits);
+        Assert.assertTrue(mask == 7);
+
+        numBits = 8;
+        mask = BitBufferHelper.getLSBMask(numBits);
+        Assert.assertTrue(mask == 255);
+    }
+
+    @Test
+    public void testToByteArray() {
+        short sh = Short.MAX_VALUE;
+        byte[] data_sh = new byte[Byte.SIZE / 8];
+        data_sh = BitBufferHelper.toByteArray(sh);
+        Assert.assertTrue(data_sh[0] == 127);
+        Assert.assertTrue(data_sh[1] == -1);
+
+        short sh2 = Short.MIN_VALUE;
+        byte[] data_sh2 = new byte[Byte.SIZE / 8];
+        data_sh2 = BitBufferHelper.toByteArray(sh2);
+        Assert.assertTrue(data_sh2[0] == -128);
+        Assert.assertTrue(data_sh2[1] == 0);
+
+        short sh3 = 16384;
+        byte[] data_sh3 = new byte[Byte.SIZE / 8];
+        data_sh3 = BitBufferHelper.toByteArray(sh3);
+        Assert.assertTrue(data_sh3[0] == 64);
+        Assert.assertTrue(data_sh3[1] == 0);
+
+        short sh4 = 146; //TCP headerlenflags - startoffset = 103
+        byte[] data_sh4 = new byte[Byte.SIZE / 8];
+        data_sh4 = BitBufferHelper.toByteArray(sh4);
+        Assert.assertTrue(data_sh4[0] == 0);
+        Assert.assertTrue(data_sh4[1] == -110);
+
+        short sh4_2 = 5000; //IPv4 Offset - startOffset = 51 (to 63)
+        byte[] data_sh4_2 = new byte[Byte.SIZE / 8];
+        data_sh4_2 = BitBufferHelper.toByteArray(sh4_2);
+        Assert.assertTrue(data_sh4_2[0] == 19);
+        Assert.assertTrue(data_sh4_2[1] == -120);
+
+        short sh4_3 = 5312; //numEndRestBits < numBitstoShiftBy
+        byte[] data_sh4_3 = new byte[Byte.SIZE / 8];
+        data_sh4_3 = BitBufferHelper.toByteArray(sh4_3);
+        Assert.assertTrue(data_sh4_3[0] == 20);
+        Assert.assertTrue(data_sh4_3[1] == -64);
+
+        int Int = Integer.MAX_VALUE;
+        byte[] data_Int = new byte[Integer.SIZE / 8];
+        data_Int = BitBufferHelper.toByteArray(Int);
+        Assert.assertTrue(data_Int[0] == 127);
+        Assert.assertTrue(data_Int[1] == -1);
+        Assert.assertTrue(data_Int[2] == -1);
+        Assert.assertTrue(data_Int[3] == -1);
+
+        int Int2 = Integer.MIN_VALUE;
+        byte[] data_Int2 = new byte[Integer.SIZE / 8];
+        data_Int2 = BitBufferHelper.toByteArray(Int2);
+        Assert.assertTrue(data_Int2[0] == -128);
+        Assert.assertTrue(data_Int2[1] == 0);
+        Assert.assertTrue(data_Int2[2] == 0);
+        Assert.assertTrue(data_Int2[3] == 0);
+
+        int Int3 = 1077952576;
+        byte[] data_Int3 = new byte[Integer.SIZE / 8];
+        data_Int3 = BitBufferHelper.toByteArray(Int3);
+        Assert.assertTrue(data_Int3[0] == 64);
+        Assert.assertTrue(data_Int3[1] == 64);
+        Assert.assertTrue(data_Int3[2] == 64);
+        Assert.assertTrue(data_Int3[3] == 64);
+
+        long Lng = Long.MAX_VALUE;
+        byte[] data_lng = new byte[Long.SIZE / 8];
+        data_lng = BitBufferHelper.toByteArray(Lng);
+        Assert.assertTrue(data_lng[0] == 127);
+        Assert.assertTrue(data_lng[1] == -1);
+        Assert.assertTrue(data_lng[2] == -1);
+        Assert.assertTrue(data_lng[3] == -1);
+        Assert.assertTrue(data_lng[4] == -1);
+        Assert.assertTrue(data_lng[5] == -1);
+        Assert.assertTrue(data_lng[6] == -1);
+        Assert.assertTrue(data_lng[7] == -1);
+
+        long Lng2 = Long.MIN_VALUE;
+        byte[] data_lng2 = new byte[Long.SIZE / 8];
+        data_lng2 = BitBufferHelper.toByteArray(Lng2);
+        Assert.assertTrue(data_lng2[0] == -128);
+        Assert.assertTrue(data_lng2[1] == 0);
+        Assert.assertTrue(data_lng2[2] == 0);
+        Assert.assertTrue(data_lng2[3] == 0);
+        Assert.assertTrue(data_lng2[4] == 0);
+        Assert.assertTrue(data_lng2[5] == 0);
+        Assert.assertTrue(data_lng2[6] == 0);
+        Assert.assertTrue(data_lng2[7] == 0);
+
+        byte B = Byte.MAX_VALUE;
+        byte[] data_B = new byte[Byte.SIZE / 8];
+        data_B = BitBufferHelper.toByteArray(B);
+        Assert.assertTrue(data_B[0] == 127);
+
+        byte B1 = Byte.MIN_VALUE;
+        byte[] data_B1 = new byte[Byte.SIZE / 8];
+        data_B1 = BitBufferHelper.toByteArray(B1);
+        Assert.assertTrue(data_B1[0] == -128);
+
+        byte B2 = 64;
+        byte[] data_B2 = new byte[Byte.SIZE / 8];
+        data_B2 = BitBufferHelper.toByteArray(B2);
+        Assert.assertTrue(data_B2[0] == 64);
+
+        byte B3 = 32;
+        byte[] data_B3 = new byte[Byte.SIZE / 8];
+        data_B3 = BitBufferHelper.toByteArray(B3);
+        Assert.assertTrue(data_B3[0] == 32);
+
+    }
+
+    @Test
+    public void testToByteArrayVariable() {
+        int len = 9;
+        byte[] data_sh;
+        data_sh = BitBufferHelper.toByteArray(511, len);
+        Assert.assertTrue(data_sh[0] == (byte) 255);
+        Assert.assertTrue(data_sh[1] == (byte) 128);
+
+        data_sh = BitBufferHelper.toByteArray(511, len);
+        Assert.assertTrue(data_sh[0] == (byte) 255);
+        Assert.assertTrue(data_sh[1] == (byte) 128);
+
+        data_sh = BitBufferHelper.toByteArray((long) 511, len);
+        Assert.assertTrue(data_sh[0] == (byte) 255);
+        Assert.assertTrue(data_sh[1] == (byte) 128);
+    }
+
+    @Test
+    public void testToInt() {
+        byte data[] = { 1 };
+        Assert.assertTrue(BitBufferHelper.toNumber(data) == 1);
+
+        byte data2[] = { 1, 1 };
+        Assert.assertTrue(BitBufferHelper.toNumber(data2) == 257);
+
+        byte data3[] = { 1, 1, 1 };
+        Assert.assertTrue(BitBufferHelper.toNumber(data3) == 65793);
+    }
+
+    @Test
+    public void testToLongGetter() {
+        byte data[] = { 1, 1 };
+        Assert.assertTrue(BitBufferHelper.getLong(data) == 257L);
+    }
+
+    @Test
+    public void testSetByte() throws Exception {
+        byte input;
+        byte[] data = new byte[20];
+
+        input = 125;
+        BitBufferHelper.setByte(data, input, 0, Byte.SIZE);
+        Assert.assertTrue(data[0] == 125);
+
+        input = 109;
+        BitBufferHelper.setByte(data, input, 152, Byte.SIZE);
+        Assert.assertTrue(data[19] == 109);
+    }
+
+    @Test
+    public void testSetBytes() throws Exception {
+        byte[] input = { 0, 1 };
+        byte[] data = { 6, 0 };
+
+        BitBufferHelper.setBytes(data, input, 7, 9);
+        Assert.assertTrue(data[0] == 6);
+        Assert.assertTrue(data[1] == 1);
+    }
+
+    //@Test
+    //INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+    // [01001011] [01101110] [01101011] [10100000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]*/
+    public void testInsertBits() throws Exception {
+        //CASE 1: startOffset%8 == 0 && numBits%8 == 0
+        byte inputdata[] = { 75, 110, 107, 80, 10, 12, 35, 100, 125, 65 };
+        int startOffset = 0;
+        int numBits = 8;
+
+        byte data1[] = new byte[2];
+        startOffset = 0;
+        numBits = 16;
+        BitBufferHelper.insertBits(data1, inputdata, startOffset, numBits);
+        Assert.assertTrue(data1[0] == 75);
+        Assert.assertTrue(data1[1] == 110);
+
+        byte data2[] = new byte[4];
+        startOffset = 0;
+        numBits = 32;
+        BitBufferHelper.insertBits(data2, inputdata, startOffset, numBits);
+        Assert.assertTrue(data2[0] == 75);
+        Assert.assertTrue(data2[1] == 110);
+        Assert.assertTrue(data2[2] == 107);
+        Assert.assertTrue(data2[3] == 80);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [10100000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        // OUTPUT: [01001011] [01101000] = {75, 104}
+        byte data10[] = new byte[2];
+        startOffset = 0;
+        numBits = 13;
+        BitBufferHelper.insertBits(data10, inputdata, startOffset, numBits);
+        Assert.assertTrue(data10[0] == 75);
+        Assert.assertTrue(data10[1] == 104);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [10100000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        // OUTPUT: [01001000] = {72}
+        byte data11[] = new byte[4];
+        startOffset = 8;
+        numBits = 6;
+        BitBufferHelper.insertBits(data11, inputdata, startOffset, numBits);
+        Assert.assertTrue(data11[1] == 72);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [10100000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [01001011] [01101110] [01101000] = {75, 110, 105}
+        byte data12[] = new byte[4];
+        startOffset = 0;
+        numBits = 23;
+        BitBufferHelper.insertBits(data12, inputdata, startOffset, numBits);
+        Assert.assertTrue(data12[0] == 75);
+        Assert.assertTrue(data12[1] == 110);
+        Assert.assertTrue(data12[2] == 106);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [10100000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [01001011] [01101110] [01100000] = {75, 110, 96}
+        byte data13[] = new byte[4];
+        startOffset = 8;
+        numBits = 20;
+        BitBufferHelper.insertBits(data13, inputdata, startOffset, numBits);
+        Assert.assertTrue(data13[1] == 75);
+        Assert.assertTrue(data13[2] == 110);
+        Assert.assertTrue(data13[3] == 96);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [10100000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [01001011] [01101110] [01101011] [10100000]= {75, 110, 107, 80}
+        byte data14[] = new byte[4];
+        startOffset = 0;
+        numBits = 30;
+        BitBufferHelper.insertBits(data14, inputdata, startOffset, numBits);
+        Assert.assertTrue(data14[0] == 75);
+        Assert.assertTrue(data14[1] == 110);
+        Assert.assertTrue(data14[2] == 107);
+        Assert.assertTrue(data14[3] == 80);
+
+        //CASE 3: startOffset%8 != 0, numBits%8 = 0
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [10100000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [00001001] [11000000] = {72, 96}
+        byte data16[] = new byte[5];
+        startOffset = 3;
+        numBits = 8;
+        BitBufferHelper.insertBits(data16, inputdata, startOffset, numBits);
+        Assert.assertTrue(data16[0] == 9);
+        Assert.assertTrue(data16[1] == 96);
+        Assert.assertTrue(data16[2] == 0);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [01010000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [00000000] [00000100] [10110110] [11100000]= {0, 4, -54, -96}
+        // OUTPUT: [00000100] [1011 0110] [1110 0000] = {4, -54, -96}
+
+        startOffset = 3;
+        numBits = 16;
+        byte data17[] = new byte[5];
+        BitBufferHelper.insertBits(data17, inputdata, startOffset, numBits);
+        Assert.assertTrue(data17[0] == 9);
+        Assert.assertTrue(data17[1] == 109);
+        Assert.assertTrue(data17[2] == -64);
+        Assert.assertTrue(data17[3] == 0);
+
+        // INPUT: {79, 110, 111}
+        // = [01001111] [01101110] [01101111]
+        //OUTPUT: [0000 1001] [1110 1101] [110 00000] = {9, -19, -64}
+        byte data18[] = new byte[5];
+        byte inputdata3[] = { 79, 110, 111 };
+        startOffset = 3;
+        numBits = 16;
+        BitBufferHelper.insertBits(data18, inputdata3, startOffset, numBits);
+        Assert.assertTrue(data18[0] == 9);
+        Assert.assertTrue(data18[1] == -19);
+        Assert.assertTrue(data18[2] == -64);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [01010000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [00000000] [00000100] [10110110] [11100000]= {0, 4, -54, -96}
+        // OUTPUT: [0000 1001] [0110 1101] [1100 1101] [0110 1010] [0000 0001] = {9, 109, -51, 106, 0}
+
+        startOffset = 3;
+        numBits = 32;
+        byte data19[] = new byte[5];
+        BitBufferHelper.insertBits(data19, inputdata, startOffset, numBits);
+        Assert.assertTrue(data19[0] == 9);
+        Assert.assertTrue(data19[1] == 109);
+        Assert.assertTrue(data19[2] == -51);
+        Assert.assertTrue(data19[3] == 106);
+        Assert.assertTrue(data19[4] == 0);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [01010000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [00000000] [00000100] [10110110] [11100000]= {0, 4, -54, -96}
+        // OUTPUT: data[4, 5, 6] = [0 010 0101] [1 011 0111] [0 000 0000] = {37, -73, 0}
+        startOffset = 33;
+        numBits = 16;
+        byte data20[] = new byte[7];
+        BitBufferHelper.insertBits(data20, inputdata, startOffset, numBits);
+        Assert.assertTrue(data20[4] == 37);
+        Assert.assertTrue(data20[5] == -73);
+        Assert.assertTrue(data20[6] == 0);
+
+        //CASE 4: extranumBits != 0 AND extraOffsetBits != 0
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [01010000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [00000000] [00000100] [10110110] [11100000]= {0, 4, -54, -96}
+        // OUTPUT: [0000 1001] [0100 0000]  = {9, 96}
+        startOffset = 3;
+        numBits = 7;
+        byte data21[] = new byte[7];
+        BitBufferHelper.insertBits(data21, inputdata, startOffset, numBits);
+        Assert.assertTrue(data21[0] == 9);
+        Assert.assertTrue(data21[1] == 64);
+        Assert.assertTrue(data21[2] == 0);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [01010000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [00000000] [00000100] [10110110] [11100000]= {0, 4, -54, -96}
+        // OUTPUT: data = [00000 010] [01011 011] [01110 000] = {37, -73, 0}
+        startOffset = 5;
+        numBits = 17;
+        byte data22[] = new byte[7];
+        BitBufferHelper.insertBits(data22, inputdata, startOffset, numBits);
+        Assert.assertTrue(data22[0] == 2);
+        Assert.assertTrue(data22[1] == 91);
+        Assert.assertTrue(data22[2] == 112);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [01010000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [00000000] [00000100] [10110110] [11100000]= {0, 4, -54, -96}
+        // OUTPUT: [0000 1001] [0110 1101] [110 01101] [01 00000] = {9, 109, -51, 64}
+        startOffset = 3;
+        numBits = 23;
+        byte data23[] = new byte[7];
+        BitBufferHelper.insertBits(data23, inputdata, startOffset, numBits);
+        Assert.assertTrue(data23[0] == 9);
+        Assert.assertTrue(data23[1] == 109);
+        Assert.assertTrue(data23[2] == -51);
+        Assert.assertTrue(data23[3] == 64);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [01010000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [00000000] [00000100] [10110110] [11100000]= {0, 4, -54, -96}
+        // OUTPUT: [0000 1001] [0110 1101]  = {9, 109}
+        startOffset = 3;
+        numBits = 13;
+        byte data24[] = new byte[7];
+        BitBufferHelper.insertBits(data24, inputdata, startOffset, numBits);
+        Assert.assertTrue(data24[0] == 9);
+        Assert.assertTrue(data24[1] == 109);
+        Assert.assertTrue(data24[2] == 0);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [01010000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [00000000] [00000100] [10110110] [11100000]= {0, 4, -54, -96}
+        // OUTPUT: [0000 0100] [1011 0110] [1110 0110]  = {4, -74, -26}
+        startOffset = 4;
+        numBits = 20;
+        byte data25[] = new byte[7];
+        BitBufferHelper.insertBits(data25, inputdata, startOffset, numBits);
+        Assert.assertTrue(data25[0] == 4);
+        Assert.assertTrue(data25[1] == -74);
+        Assert.assertTrue(data25[2] == -26);
+        Assert.assertTrue(data25[3] == -0);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [01010000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [00000000] [00000100] [10110110] [11100000]= {0, 4, -54, -96}
+        // OUTPUT: [0000 0010] [0101 1011]   = {0, 2, 91, 0}
+        startOffset = 13;
+        numBits = 11;
+        byte data26[] = new byte[7];
+        BitBufferHelper.insertBits(data26, inputdata, startOffset, numBits);
+        Assert.assertTrue(data26[0] == 0);
+        Assert.assertTrue(data26[1] == 2);
+        Assert.assertTrue(data26[2] == 91);
+        Assert.assertTrue(data26[3] == 0);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [01010000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [00000000] [00000100] [10110110] [11100000]= {0, 4, -54, -96}
+        // OUTPUT: [000 01001] [011 01101] [110 0 0000]   = {9, 109, -64, 0}
+        startOffset = 3;
+        numBits = 17;
+        byte data27[] = new byte[7];
+        BitBufferHelper.insertBits(data27, inputdata, startOffset, numBits);
+        Assert.assertTrue(data27[0] == 9);
+        Assert.assertTrue(data27[1] == 109);
+        Assert.assertTrue(data27[2] == -64);
+        Assert.assertTrue(data27[3] == 0);
+
+        // INPUT: {75, 110, 107, 80, 10, 12, 35, 100, 125, 65} =
+        // [01001011] [01101110] [01101011] [01010000] [00001010] [00001100] [00100011] [01100100] [11111101] [01000001]        //OUTPUT: [00000000] [00000100] [10110110] [11100000]= {0, 4, -54, -96}
+        // OUTPUT: [00 000000] [00 000000] [00 010010] [11 011011] [10 011010] [11 010100] [0000 0000] = {0, 0, 18, -37,-102,-44,0}
+        startOffset = 18;
+        numBits = 34;
+        byte data28[] = new byte[7];
+        BitBufferHelper.insertBits(data28, inputdata, startOffset, numBits);
+        Assert.assertTrue(data28[0] == 0);
+        Assert.assertTrue(data28[1] == 0);
+        Assert.assertTrue(data28[2] == 18);
+        Assert.assertTrue(data28[3] == -37);
+        Assert.assertTrue(data28[4] == -102);
+        Assert.assertTrue(data28[5] == -44);
+        Assert.assertTrue(data28[6] == 0);
+
+    }
+
+    @Test
+    public void testGetShort() throws Exception {
+        byte data[] = new byte[2];
+        data[0] = 7;
+        data[1] = 8;
+        int length = 9; // num bits
+        Assert.assertTrue(BitBufferHelper.getShort(data, length) == 264);
+
+        data[0] = 6;
+        data[1] = 8;
+        short result = BitBufferHelper.getShort(data, length);
+        Assert.assertTrue(result == 8);
+
+        data[0] = 8;
+        data[1] = 47;
+        result = BitBufferHelper.getShort(data, length);
+        Assert.assertTrue(result == 47);
+
+        //[0000 0001] [0001 0100] [0110 0100]
+        byte[] data1 = new byte[2];
+        data1[0] = 1;
+        data1[1] = 20; //data1[2] = 100;
+        length = 15;
+        result = BitBufferHelper.getShort(data1, length);
+        Assert.assertTrue(result == 276);
+
+        byte[] data2 = new byte[2];
+        data2[0] = 64;
+        data2[1] = 99; //data2[2] = 100;
+        length = 13;
+        result = BitBufferHelper.getShort(data2, length);
+        Assert.assertTrue(result == 99);
+
+        byte[] data3 = { 100, 50 };
+        result = BitBufferHelper.getShort(data3);
+        Assert.assertTrue(result == 25650);
+    }
+
+    @Test
+    public void testToIntVarLength() throws Exception {
+        byte data[] = { (byte) 255, (byte) 128 };
+        int length = 9; // num bits
+        Assert.assertTrue(BitBufferHelper.getInt(data, length) == 384);
+
+        byte data2[] = { 0, 8 };
+        Assert.assertTrue(BitBufferHelper.getInt(data2, 9) == 8);
+
+        byte data3[] = { 1, 1, 1 };
+        Assert.assertTrue(BitBufferHelper.getInt(data3) == 65793);
+
+        byte data4[] = { 1, 1, 1 };
+        Assert.assertTrue(BitBufferHelper.getInt(data4) == 65793);
+
+        byte data5[] = { 1, 1 };
+        Assert.assertTrue(BitBufferHelper.getInt(data5) == 257);
+
+    }
+
+    @Test
+    public void testShiftBitstoLSB() {
+        byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+
+        byte[] data2 = { 8, 9, 10 };
+        byte[] shiftedBytes2 = BitBufferHelper.shiftBitsToLSB(data2, 11);
+
+        Assert.assertTrue(shiftedBytes2[0] == 0);
+        Assert.assertTrue(shiftedBytes2[1] == 64);
+        Assert.assertTrue(shiftedBytes2[2] == 72);
+
+        byte[] shiftedBytes = BitBufferHelper.shiftBitsToLSB(data, 49);
+
+        Assert.assertTrue(shiftedBytes[0] == 0);
+        Assert.assertTrue(shiftedBytes[1] == 2);
+        Assert.assertTrue(shiftedBytes[2] == 4);
+        Assert.assertTrue(shiftedBytes[3] == 6);
+        Assert.assertTrue(shiftedBytes[4] == 8);
+        Assert.assertTrue(shiftedBytes[5] == 10);
+        Assert.assertTrue(shiftedBytes[6] == 12);
+        Assert.assertTrue(shiftedBytes[7] == 14);
+        Assert.assertTrue(shiftedBytes[8] == 16);
+        Assert.assertTrue(shiftedBytes[9] == 18);
+
+        byte[] data1 = { 1, 2, 3 };
+        byte[] shiftedBytes1 = BitBufferHelper.shiftBitsToLSB(data1, 18);
+        Assert.assertTrue(shiftedBytes1[0] == 0);
+        Assert.assertTrue(shiftedBytes1[1] == 4);
+        Assert.assertTrue(shiftedBytes1[2] == 8);
+
+    }
+
+    @Test
+    public void testShiftBitstoLSBMSB() {
+        byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
+
+        byte[] clone = BitBufferHelper.shiftBitsToMSB(BitBufferHelper
+                .shiftBitsToLSB(data, 72), 72);
+
+        Assert.assertTrue(clone[0] == 1);
+        Assert.assertTrue(clone[1] == 2);
+        Assert.assertTrue(clone[2] == 3);
+        Assert.assertTrue(clone[3] == 4);
+        Assert.assertTrue(clone[4] == 5);
+        Assert.assertTrue(clone[5] == 6);
+        Assert.assertTrue(clone[6] == 7);
+        Assert.assertTrue(clone[7] == 8);
+        Assert.assertTrue(clone[8] == 9);
+        Assert.assertTrue(clone[9] == 0);
+    }
+
+}
diff --git a/libraries/liblldp/src/test/java/org/opendaylight/controller/sal/packet/address/EthernetAddressTest.java b/libraries/liblldp/src/test/java/org/opendaylight/controller/sal/packet/address/EthernetAddressTest.java
new file mode 100644 (file)
index 0000000..5730dc7
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2014, 2015 Cisco Systems, Inc. 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
+ */
+
+/**
+ * @file   EthernetAddressTest.java
+ *
+ * @brief  Unit Tests for EthernetAddress class
+ *
+ * Unit Tests for EthernetAddress class
+ */
+package org.opendaylight.controller.sal.packet.address;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.controller.liblldp.ConstructionException;
+import org.opendaylight.controller.liblldp.EthernetAddress;
+
+public class EthernetAddressTest {
+    @Test
+    public void testNonValidConstructor() {
+        @SuppressWarnings("unused")
+        EthernetAddress ea1;
+        // Null input array
+        try {
+            ea1 = new EthernetAddress((byte[]) null);
+
+            // Exception is expected if NOT raised test will fail
+            Assert.assertTrue(false);
+        } catch (final ConstructionException e) {
+        }
+
+        // Array too short
+        try {
+            ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0 });
+
+            // Exception is expected if NOT raised test will fail
+            Assert.assertTrue(false);
+        } catch (final ConstructionException e) {
+        }
+
+        // Array too long
+        try {
+            ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
+                    (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0,
+                    (byte) 0x0 });
+
+            // Exception is expected if NOT raised test will fail
+            Assert.assertTrue(false);
+        } catch (final ConstructionException e) {
+        }
+    }
+
+    @Test
+    public void testEquality() {
+        EthernetAddress ea1;
+        EthernetAddress ea2;
+        try {
+            ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
+                    (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
+
+            ea2 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
+                    (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
+            Assert.assertTrue(ea1.equals(ea2));
+        } catch (final ConstructionException e) {
+            // Exception is NOT expected if raised test will fail
+            Assert.assertTrue(false);
+        }
+
+        try {
+            ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
+                    (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
+
+            ea2 = ea1.clone();
+            Assert.assertTrue(ea1.equals(ea2));
+        } catch (final ConstructionException e) {
+            // Exception is NOT expected if raised test will fail
+            Assert.assertTrue(false);
+        }
+
+        // Check for well knowns
+        try {
+            ea1 = EthernetAddress.BROADCASTMAC;
+            ea2 = new EthernetAddress(new byte[] { (byte) 0xff, (byte) 0xff,
+                    (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff });
+            Assert.assertTrue(ea1.equals(ea2));
+        } catch (final ConstructionException e) {
+            // Exception is NOT expected if raised test will fail
+            Assert.assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testUnEquality() {
+        EthernetAddress ea1;
+        EthernetAddress ea2;
+        try {
+            ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
+                    (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x2 });
+
+            ea2 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
+                    (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
+            Assert.assertTrue(!ea1.equals(ea2));
+        } catch (final ConstructionException e) {
+            // Exception is NOT expected if raised test will fail
+            Assert.assertTrue(false);
+        }
+    }
+}
diff --git a/libraries/liblldp/src/test/resources/log4j.xml b/libraries/liblldp/src/test/resources/log4j.xml
new file mode 100644 (file)
index 0000000..e47e51a
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+    <appender name="console" class="org.apache.log4j.ConsoleAppender">
+        <layout class="org.apache.log4j.PatternLayout">
+            <param name="ConversionPattern" value="%-6p %d{HH:mm:ss.SSS} [%10.10t] %30.30c %x - %m%n" />
+        </layout>
+    </appender>
+
+    <logger name="org.opendaylight.controller.liblldp" additivity="false">
+        <level value="DEBUG" />
+        <appender-ref ref="console" />
+    </logger>
+
+    <root>
+        <priority value="INFO" />
+        <appender-ref ref="console" />
+    </root>
+</log4j:configuration>
index cfb37d5ee7b6501c9a07cfa7def100cff09edd4f..c66ba751e2865a64f5a808a7bd5e0f3be1e5f89e 100644 (file)
     <module>model-flow-statistics</module>
   </modules>
 
-  <properties>
-    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-  </properties>
-
   <dependencies>
     <dependency>
       <groupId>org.opendaylight.mdsal</groupId>
           </instructions>
         </configuration>
       </plugin>
-      <plugin>
-        <groupId>org.opendaylight.yangtools</groupId>
-        <artifactId>yang-maven-plugin</artifactId>
-        <dependencies>
-          <dependency>
-            <groupId>org.opendaylight.mdsal</groupId>
-            <artifactId>maven-sal-api-gen-plugin</artifactId>
-            <version>${mdsal.model.version}</version>
-            <type>jar</type>
-          </dependency>
-          <dependency>
-            <groupId>org.opendaylight.mdsal</groupId>
-            <artifactId>yang-binding</artifactId>
-            <version>${mdsal.model.version}</version>
-            <type>jar</type>
-          </dependency>
-        </dependencies>
-        <executions>
-          <execution>
-            <goals>
-              <goal>generate-sources</goal>
-            </goals>
-            <configuration>
-              <yangFilesRootDir>src/main/yang</yangFilesRootDir>
-              <codeGenerators>
-                <generator>
-                  <codeGeneratorClass>org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl</codeGeneratorClass>
-                  <outputBaseDir>${salGeneratorPath}</outputBaseDir>
-                </generator>
-                <generator>
-                  <codeGeneratorClass>org.opendaylight.mdsal.binding.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
-                  <outputBaseDir>target/site/models</outputBaseDir>
-                </generator>
-                <generator>
-                  <codeGeneratorClass>org.opendaylight.mdsal.binding.yang.wadl.generator.maven.WadlGenerator</codeGeneratorClass>
-                  <outputBaseDir>target/site/models</outputBaseDir>
-                </generator>
-              </codeGenerators>
-              <inspectDependencies>true</inspectDependencies>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
     </plugins>
   </build>
 
index 9cb2fc7ba4e9d0cac522bd169c76be49fe9bdc96..3cc1b261c42617aeb2e9c0a41a6a9449a1ba1fb4 100644 (file)
@@ -4,7 +4,7 @@
   <parent>
     <groupId>org.opendaylight.odlparent</groupId>
     <artifactId>feature-repo-parent</artifactId>
-    <version>2.0.5</version>
+    <version>3.0.2</version>
     <relativePath/>
   </parent>
 
index c26a8eecfaa693ebaf85bc40e6ceaf61b73690cd..084ffe9b954b9fd9eac241f56713c1995958be70 100644 (file)
@@ -7,7 +7,7 @@
     <parent>
         <groupId>org.opendaylight.odlparent</groupId>
         <artifactId>single-feature-parent</artifactId>
-        <version>2.0.5</version>
+        <version>3.0.2</version>
         <relativePath/>
     </parent>
 
@@ -42,7 +42,7 @@
             <dependency>
                 <groupId>org.opendaylight.odlparent</groupId>
                 <artifactId>odlparent-artifacts</artifactId>
-                <version>2.0.5</version>
+                <version>3.0.2</version>
                 <scope>import</scope>
                 <type>pom</type>
             </dependency>
index 9a1e5d2784763e7cc7352d69a36d98b61da4d69f..8a48d1c8ba12eb94aa295be6be7de133edc7233c 100644 (file)
@@ -4,7 +4,7 @@
   <parent>
     <groupId>org.opendaylight.odlparent</groupId>
     <artifactId>odlparent-lite</artifactId>
-    <version>2.0.5</version>
+    <version>3.0.2</version>
     <relativePath/>
   </parent>
 
index 5a371b70a1b4246d5adcc6d051feb558339c8223..15434be6ab452cf5373cb6322bf11b0f8634624a 100644 (file)
@@ -2,10 +2,10 @@
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <parent>
-        <groupId>org.opendaylight.mdsal</groupId>
-        <artifactId>binding-parent</artifactId>
-        <version>0.12.0-SNAPSHOT</version>
-        <relativePath/>
+        <groupId>org.opendaylight.openflowplugin</groupId>
+        <artifactId>openflowplugin-parent</artifactId>
+        <version>0.6.0-SNAPSHOT</version>
+        <relativePath>../../parent</relativePath>
     </parent>
     <groupId>org.opendaylight.openflowplugin.openflowjava</groupId>
     <artifactId>openflow-protocol-api</artifactId>
         <tag>HEAD</tag>
     </scm>
 
-    <properties>
-      <mdsal.version>2.4.0-SNAPSHOT</mdsal.version>
-      <mdsal.model.version>0.12.0-SNAPSHOT</mdsal.model.version>
-    </properties>
-
-    <dependencyManagement>
-      <dependencies>
-      <!-- MD-SAL -->
-        <dependency>
-          <groupId>org.opendaylight.mdsal</groupId>
-          <artifactId>mdsal-artifacts</artifactId>
-          <version>${mdsal.version}</version>
-          <scope>import</scope>
-          <type>pom</type>
-        </dependency>
-
-        <dependency>
-          <groupId>org.opendaylight.mdsal.model</groupId>
-          <artifactId>mdsal-model-artifacts</artifactId>
-          <version>${mdsal.model.version}</version>
-          <scope>import</scope>
-          <type>pom</type>
-        </dependency>
-      </dependencies>
-    </dependencyManagement>
-
     <dependencies>
         <dependency>
             <groupId>org.opendaylight.mdsal</groupId>
index 578e97b552479f78212bff0fe6935fb7f2e3f063..f66a6979e62f6ccc952b82359907aae6109a4023 100644 (file)
@@ -55,4 +55,10 @@ public interface ConnectionConfiguration {
      * @return boolean value for usability of Barrier
      */
     boolean useBarrier();
+
+    /**
+     * Checks if group add mod messages are enabled.
+     * @return true if group add mod messages are enabled
+     */
+    boolean isGroupAddModEnabled();
 }
index 1ddc48565e6daf2a5ea095161087d02d1d6e8e87..48aa72b95e91b92f91816102620dd6608dfadf38 100644 (file)
@@ -16,7 +16,6 @@ import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
  * @author michal.polkorab
  */
 public interface SerializerRegistry {
-
     /**
      * Serializer registry provisioning
      */
@@ -53,4 +52,16 @@ public interface SerializerRegistry {
      *  false if no serializer was found under specified key
      */
     <K> boolean unregisterSerializer(MessageTypeKey<K> key);
+
+    /**
+     * Checks if group add mod messages are enabled.
+     * @return true if group add mod messages are enabled
+     */
+    boolean isGroupAddModEnabled();
+
+    /**
+     *
+     * @param isGroupAddModEnabled true if group add mod messages are enabled
+     */
+    void setGroupAddModConfig(boolean isGroupAddModEnabled);
 }
index e65e737b066a88700844c50e5ba3d4831222fbe0..65d33581429b50c38fcd24f9f14a91bf837862de 100644 (file)
                 </instructions>
               </configuration>
             </plugin>
-            <plugin>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>generate-sources</goal>
-                        </goals>
-                        <configuration>
-                            <codeGenerators>
-                                <generator>
-                                    <codeGeneratorClass>
-                                        org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl
-                                    </codeGeneratorClass>
-                                    <outputBaseDir>${salGeneratorPath}</outputBaseDir>
-                                </generator>
-                                <generator>
-                                    <codeGeneratorClass>org.opendaylight.mdsal.binding.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/site/models</outputBaseDir>
-                                </generator>
-                            </codeGenerators>
-                            <inspectDependencies>true</inspectDependencies>
-                        </configuration>
-                    </execution>
-                </executions>
-                <dependencies>
-                    <dependency>
-                        <groupId>org.opendaylight.mdsal</groupId>
-                        <artifactId>maven-sal-api-gen-plugin</artifactId>
-                        <version>${mdsal.model.version}</version>
-                        <type>jar</type>
-                    </dependency>
-                </dependencies>
-            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-jar-plugin</artifactId>
index 79ad2665351f043edc2668b9d6342031b60a61ba..bf1dea3e3659df14b8f0d588078426e44e79aecc 100644 (file)
@@ -33,8 +33,8 @@ public class SwitchConnectionProviderFactoryImpl implements SwitchConnectionProv
 
     @Override
     public SwitchConnectionProvider newInstance(SwitchConnectionConfig config) {
-        SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl();
-        switchConnectionProviderImpl.setConfiguration(new ConnectionConfigurationImpl(config));
+        SwitchConnectionProviderImpl switchConnectionProviderImpl =
+                new SwitchConnectionProviderImpl(new ConnectionConfigurationImpl(config));
         return switchConnectionProviderImpl;
     }
 
@@ -174,5 +174,10 @@ public class SwitchConnectionProviderFactoryImpl implements SwitchConnectionProv
         public boolean useBarrier() {
             return config.isUseBarrier();
         }
+
+        @Override
+        public boolean isGroupAddModEnabled() {
+            return config.isGroupAddModEnabled();
+        }
     }
 }
index 612afcb73f036cb61af72abdeb5ed3cfcc7c7c4b..7474a311222e3b532f42dad2df36ec30abe738ec 100755 (executable)
@@ -64,16 +64,19 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C
             .getLogger(SwitchConnectionProviderImpl.class);
     private SwitchConnectionHandler switchConnectionHandler;
     private ServerFacade serverFacade;
-    private ConnectionConfiguration connConfig;
+    private final ConnectionConfiguration connConfig;
     private final SerializationFactory serializationFactory;
     private final SerializerRegistry serializerRegistry;
     private final DeserializerRegistry deserializerRegistry;
     private final DeserializationFactory deserializationFactory;
     private TcpConnectionInitializer connectionInitializer;
 
-    /** Constructor */
-    public SwitchConnectionProviderImpl() {
+    public SwitchConnectionProviderImpl(ConnectionConfiguration connConfig) {
+        this.connConfig = connConfig;
         serializerRegistry = new SerializerRegistryImpl();
+        if (connConfig != null) {
+            serializerRegistry.setGroupAddModConfig(connConfig.isGroupAddModEnabled());
+        }
         serializerRegistry.init();
         serializationFactory = new SerializationFactory();
         serializationFactory.setSerializerTable(serializerRegistry);
@@ -83,11 +86,6 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C
         deserializationFactory.setRegistry(deserializerRegistry);
     }
 
-    @Override
-    public void setConfiguration(final ConnectionConfiguration connConfig) {
-        this.connConfig = connConfig;
-    }
-
     @Override
     public void setSwitchConnectionHandler(final SwitchConnectionHandler switchConnectionHandler) {
         LOG.debug("setSwitchConnectionHandler");
index 23551bb7530ba438c199b2e214b270758ef7991e..401a292727ebcc1751bec9bc1d2986fad09e76e6 100644 (file)
@@ -101,7 +101,8 @@ public final class MessageFactoryInitializer {
         registryHelper.registerSerializer(GetConfigInput.class, new GetConfigInputMessageFactory());
         registryHelper.registerSerializer(GetFeaturesInput.class, new GetFeaturesInputMessageFactory());
         registryHelper.registerSerializer(GetQueueConfigInput.class, new GetQueueConfigInputMessageFactory());
-        registryHelper.registerSerializer(GroupModInput.class, new GroupModInputMessageFactory());
+        registryHelper.registerSerializer(GroupModInput.class,
+                new GroupModInputMessageFactory(serializerRegistry.isGroupAddModEnabled()));
         registryHelper.registerSerializer(HelloInput.class, new HelloInputMessageFactory());
         registryHelper.registerSerializer(MeterModInput.class, new MeterModInputMessageFactory());
         registryHelper.registerSerializer(MultipartRequestInput.class, new MultipartRequestInputFactory());
index 9383187866dfa5608bdffad335ab332c9971356a..4875898ebbdf61859c0a7ff7967984d3e6ac2de1 100644 (file)
@@ -39,6 +39,8 @@ public class SerializerRegistryImpl implements SerializerRegistry {
     private static final short OF13 = EncodeConstants.OF13_VERSION_ID;
     private Map<MessageTypeKey<?>, OFGeneralSerializer> registry;
 
+    private boolean isGroupAddModEnabled = false;
+
     @Override
     public void init() {
         registry = new HashMap<>();
@@ -60,6 +62,15 @@ public class SerializerRegistryImpl implements SerializerRegistry {
         InstructionsInitializer.registerInstructionSerializers(this);
     }
 
+    public void setGroupAddModConfig(boolean isGroupAddModEnabled) {
+        this.isGroupAddModEnabled = isGroupAddModEnabled;
+    }
+
+    @Override
+    public boolean isGroupAddModEnabled() {
+        return isGroupAddModEnabled;
+    }
+
     /**
      * @param msgTypeKey
      * @return encoder for current type of message (msgTypeKey)
index db8142a54f47113f883c5fde737f0e3ea9e43759..2a67c999e09dabdbaca8246d59414d5e486ae043 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.impl.util.ListSerializer;
 import org.opendaylight.openflowjava.protocol.impl.util.TypeKeyMakerFactory;
 import org.opendaylight.openflowjava.util.ByteBufUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupModCommand;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupMod;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList;
 
@@ -30,13 +31,28 @@ public class GroupModInputMessageFactory implements OFSerializer<GroupMod>, Seri
     private static final byte MESSAGE_TYPE = 15;
     private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1;
     private static final byte PADDING_IN_BUCKET = 4;
+    private static final int OFPGC_ADD_OR_MOD = 32768;
     private SerializerRegistry registry;
+    private final boolean isGroupAddModEnaled;
+
+    public GroupModInputMessageFactory(final boolean isGroupAddModEnaled) {
+        this.isGroupAddModEnaled = isGroupAddModEnaled;
+    }
 
     @Override
     public void serialize(GroupMod message, ByteBuf outBuffer) {
         int index = outBuffer.writerIndex();
         ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
-        outBuffer.writeShort(message.getCommand().getIntValue());
+        if (isGroupAddModEnaled) {
+            if (message.getCommand().equals(GroupModCommand.OFPGCADD)
+                    || message.getCommand().equals(GroupModCommand.OFPGCMODIFY)) {
+                outBuffer.writeShort(OFPGC_ADD_OR_MOD);
+            } else {
+                outBuffer.writeShort(message.getCommand().getIntValue());
+            }
+        } else {
+            outBuffer.writeShort(message.getCommand().getIntValue());
+        }
         outBuffer.writeByte(message.getType().getIntValue());
         outBuffer.writeZero(PADDING_IN_GROUP_MOD_MESSAGE);
         outBuffer.writeInt(message.getGroupId().getValue().intValue());
index b4097dda605364d101a23e6c5eddda37a44fd0d0..3efb2504e3d35a398393f97744c0c93cf66251c7 100644 (file)
@@ -27,6 +27,7 @@ public class ConnectionConfigurationImpl implements ConnectionConfiguration {
     private final long switchIdleTimeout;
     private ThreadConfiguration threadConfig;
     private final boolean useBarrier;
+    private final boolean isGroupAddModEnabled;
 
     /**
      * Creates {@link ConnectionConfigurationImpl}
@@ -38,12 +39,13 @@ public class ConnectionConfigurationImpl implements ConnectionConfiguration {
      * @param useBarrier
      */
     public ConnectionConfigurationImpl(final InetAddress address, final int port, final TlsConfiguration tlsConfig,
-            final long switchIdleTimeout, final boolean useBarrier) {
+            final long switchIdleTimeout, final boolean useBarrier, final boolean isGroupAddModEnabled) {
         this.address = address;
         this.port = port;
         this.tlsConfig = tlsConfig;
         this.switchIdleTimeout = switchIdleTimeout;
         this.useBarrier = useBarrier;
+        this.isGroupAddModEnabled = isGroupAddModEnabled;
     }
 
     @Override
@@ -101,4 +103,9 @@ public class ConnectionConfigurationImpl implements ConnectionConfiguration {
     public boolean useBarrier() {
         return useBarrier;
     }
+
+    @Override
+    public boolean isGroupAddModEnabled() {
+        return isGroupAddModEnabled;
+    }
 }
\ No newline at end of file
index 03cc3f990dc3ca3679324cb013b3a2f922154f57..af3b418231dbc6bd0444380ade01daeba9e796f8 100755 (executable)
@@ -68,11 +68,11 @@ public class SwitchConnectionProviderImpl02Test {
     @Mock OFSerializer<ExperimenterDataOfChoice> serializerExperimenterInput;
     @Mock OFSerializer<ExperimenterDataOfChoice> serializerMultipartRequestExpCase;
     @Mock OFSerializer<MeterBandExperimenterCase> serializerMeterBandExpCase;
+    @Mock ConnectionConfigurationImpl config;
     private static final int SWITCH_IDLE_TIMEOUT = 2000;
     private InetAddress startupAddress;
     private TlsConfiguration tlsConfiguration;
     private SwitchConnectionProviderImpl provider;
-    private ConnectionConfigurationImpl config;
 
     /**
      * Creates new {@link SwitchConnectionProvider} instance for each test
@@ -84,7 +84,7 @@ public class SwitchConnectionProviderImpl02Test {
         if (protocol != null) {
             createConfig(protocol);
         }
-        provider = new SwitchConnectionProviderImpl();
+        provider = new SwitchConnectionProviderImpl(config);
     }
 
     private void createConfig(final TransportProtocol protocol) {
@@ -100,7 +100,7 @@ public class SwitchConnectionProviderImpl02Test {
                     "/selfSignedController", PathType.CLASSPATH,
                     Lists.newArrayList("TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_128_CBC_SHA256")) ;
         }
-        config = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT, true);
+        config = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT, true, false);
         config.setTransferProtocol(protocol);
     }
 
@@ -111,7 +111,6 @@ public class SwitchConnectionProviderImpl02Test {
     @Test
     public void testServerFacade(){
         startUp(TransportProtocol.TCP);
-        provider.setConfiguration(config);
         final ListenableFuture<Boolean> future = provider.startup();
         final ServerFacade serverFacade = provider.getServerFacade();
         Assert.assertNotNull("Wrong -- getServerFacade return null",serverFacade);
@@ -131,7 +130,6 @@ public class SwitchConnectionProviderImpl02Test {
     @Test
     public void testUnregisterWrongKeys(){
         startUp(TransportProtocol.TCP);
-        provider.setConfiguration(config);
         final ExperimenterInstructionSerializerKey testSerKey
             = new ExperimenterInstructionSerializerKey(EncodeConstants.OF10_VERSION_ID,42L);
         Assert.assertFalse("Wrong -- unregisterSerializer",provider.unregisterSerializer(testSerKey));
@@ -146,7 +144,6 @@ public class SwitchConnectionProviderImpl02Test {
     @Test
     public void testUnregisterExistingKeys(){
         startUp(TransportProtocol.TCP);
-        provider.setConfiguration(config);
         // -- registerActionSerializer
         final ExperimenterActionSerializerKey key1
             = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType.class);
index 175595157e054c5422ad3745626b05bf98737d4f..7a8add5072e8c44ea7652760784fe3d0347ad9be 100644 (file)
@@ -53,7 +53,7 @@ public class SwitchConnectionProviderImplTest {
         if (protocol != null) {
             createConfig(protocol);
         }
-        provider = new SwitchConnectionProviderImpl();
+        provider = new SwitchConnectionProviderImpl(config);
     }
 
     private void createConfig(final TransportProtocol protocol) {
@@ -69,7 +69,7 @@ public class SwitchConnectionProviderImplTest {
                     "/selfSignedController", PathType.CLASSPATH,
                     Lists.newArrayList("TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_128_CBC_SHA256")) ;
         }
-        config = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT, true);
+        config = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT, true, false);
         config.setTransferProtocol(protocol);
     }
 
@@ -78,7 +78,7 @@ public class SwitchConnectionProviderImplTest {
      */
     @Test
     public void testStartup1() {
-        provider = new SwitchConnectionProviderImpl();
+        provider = new SwitchConnectionProviderImpl(config);
         final ListenableFuture<Boolean> future = provider.startup();
         try {
             future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
@@ -108,7 +108,6 @@ public class SwitchConnectionProviderImplTest {
     @Test
     public void testStartup3() {
         startUp(TransportProtocol.TCP);
-        provider.setConfiguration(config);
         final ListenableFuture<Boolean> future = provider.startup();
         try {
             future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
@@ -124,7 +123,6 @@ public class SwitchConnectionProviderImplTest {
     @Test
     public void testStartup4() {
         startUp(TransportProtocol.TCP);
-        provider.setConfiguration(config);
         provider.setSwitchConnectionHandler(handler);
         try {
             Assert.assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
@@ -139,7 +137,6 @@ public class SwitchConnectionProviderImplTest {
     @Test
     public void testStartup5() {
         startUp(TransportProtocol.TLS);
-        provider.setConfiguration(config);
         provider.setSwitchConnectionHandler(handler);
         try {
             Assert.assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
@@ -154,7 +151,6 @@ public class SwitchConnectionProviderImplTest {
     @Test
     public void testStartup6() {
         startUp(TransportProtocol.UDP);
-        provider.setConfiguration(config);
         provider.setSwitchConnectionHandler(handler);
         try {
             Assert.assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
@@ -169,7 +165,6 @@ public class SwitchConnectionProviderImplTest {
     @Test
     public void testShutdown() {
         startUp(TransportProtocol.TCP);
-        provider.setConfiguration(config);
         provider.setSwitchConnectionHandler(handler);
         try {
             Assert.assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
index 6e75130f9ebe358eaf3b6f56aa7f86940add4e54..bccc198aa8c1616f3e23c1ed7f5ced870e10b543 100644 (file)
@@ -40,7 +40,7 @@ public class GroupModInputMessageFactoryTest {
     private static final byte MESSAGE_TYPE = 15;
     private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1;
     private SerializerRegistry registry;
-    private OFSerializer<GroupModInput> groupModFactory;
+    private GroupModInputMessageFactory groupModFactory;
 
     /**
      * Initializes serializer registry and stores correct factory in field
@@ -49,8 +49,7 @@ public class GroupModInputMessageFactoryTest {
     public void startUp() {
         registry = new SerializerRegistryImpl();
         registry.init();
-        groupModFactory = registry.getSerializer(
-                new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, GroupModInput.class));
+        groupModFactory = new GroupModInputMessageFactory(false);
     }
 
     /**
@@ -76,7 +75,6 @@ public class GroupModInputMessageFactoryTest {
         out.writeShort(3);
 
         groupModFactory.serialize(message, out);
-
         // read parent message
         out.readInt();
         out.skipBytes(2);
index 77e747a96279f793715e110399c08d9e07969e65..a747df745d3141a87a4d8860ba954979f9930133 100644 (file)
@@ -77,13 +77,12 @@ public class IntegrationTest {
                     "/selfSignedController", PathType.CLASSPATH,
                     new ArrayList<String>());
         }
-        connConfig = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT, true);
+        connConfig = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT, true, false);
         connConfig.setTransferProtocol(protocol);
         mockPlugin = new MockPlugin();
 
-        switchConnectionProvider = new SwitchConnectionProviderImpl();
+        switchConnectionProvider = new SwitchConnectionProviderImpl(connConfig);
         switchConnectionProvider.setSwitchConnectionHandler(mockPlugin);
-        switchConnectionProvider.setConfiguration(connConfig);
         switchConnectionProvider.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
         if (protocol.equals(TransportProtocol.TCP) || protocol.equals(TransportProtocol.TLS)) {
             final TcpHandler tcpHandler = (TcpHandler) switchConnectionProvider.getServerFacade();
index 70d0fa947fca6a7c2dcd43f12dc95f437dc8b649..6355b791ffa5102fb12fe543ce0b74e246df214f 100644 (file)
                 </instructions>
               </configuration>
             </plugin>
-            <plugin>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>generate-sources</goal>
-                        </goals>
-                        <configuration>
-                            <codeGenerators>
-                                <generator>
-                                    <codeGeneratorClass>
-                                        org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl
-                                    </codeGeneratorClass>
-                                    <outputBaseDir>${salGeneratorPath}</outputBaseDir>
-                                </generator>
-                                <generator>
-                                    <codeGeneratorClass>org.opendaylight.mdsal.binding.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/site/models</outputBaseDir>
-                                </generator>
-                            </codeGenerators>
-                            <inspectDependencies>true</inspectDependencies>
-                        </configuration>
-                    </execution>
-                </executions>
-                <dependencies>
-                    <dependency>
-                        <groupId>org.opendaylight.mdsal</groupId>
-                        <artifactId>maven-sal-api-gen-plugin</artifactId>
-                        <version>${mdsal.model.version}</version>
-                        <type>jar</type>
-                    </dependency>
-                </dependencies>
-            </plugin>
         </plugins>
     </build>
 
index b013471f3b7388d75bd8099a5eba357ecb333ece..0837399ef41791376b10b81a3094665bcf02fbc3 100644 (file)
@@ -24,11 +24,6 @@ import com.google.common.util.concurrent.ListenableFuture;
 public interface SwitchConnectionProvider extends AutoCloseable,
         SerializerExtensionProvider, DeserializerExtensionProvider {
 
-    /**
-     * @param configuration [protocol, port, address and supported features]
-     */
-    void setConfiguration(ConnectionConfiguration configuration);
-
     /**
      * return the connection configuration
      * @return configuration [protocol, port, address and supported features]
index 1ab7ae851b5324edb2f16721084395eb26907ba9..e6d3927f93ae63785ec764105823ce5068cab371 100644 (file)
@@ -45,6 +45,12 @@ module openflow-switch-connection-config {
             default true;
         }
 
+        leaf group-add-mod-enabled {
+            description "Group Add Mod Enabled";
+            type boolean;
+            default false;
+        }
+
         leaf switch-idle-timeout {
             description "idle timeout in [ms]";
             type uint32;
index 08b8a52ed52badfdd75fddbbf43f0d2fc11b1409..8c91e139564f5232ff9e02e42d1e91b83e507f97 100644 (file)
@@ -2,6 +2,7 @@
   <instance-name>openflow-switch-connection-provider-default-impl</instance-name>
   <port>6653</port>
   <transport-protocol>TCP</transport-protocol>
+  <group-add-mod-enabled>false</group-add-mod-enabled>
   <tls>
      <keystore>configuration/ssl/ctl.jks</keystore>
      <keystore-type>JKS</keystore-type>
@@ -14,4 +15,4 @@
      <certificate-password>opendaylight</certificate-password>
      <cipher-suites></cipher-suites>
   </tls>
-</switch-connection-config>
\ No newline at end of file
+</switch-connection-config>
index 13860139be7e97bea8e1462bdf85ba8d4e70f117..6e8a432779f5fcc3408977f54e3bdffb5b97facd 100644 (file)
@@ -2,6 +2,7 @@
   <instance-name>openflow-switch-connection-provider-legacy-impl</instance-name>
   <port>6633</port>
   <transport-protocol>TCP</transport-protocol>
+  <group-add-mod-enabled>false</group-add-mod-enabled>
   <tls>
      <keystore>configuration/ssl/ctl.jks</keystore>
      <keystore-type>JKS</keystore-type>
index cd9f56bd6800ddc1098354002730b0e0d404e70c..b185f0cf5c1b221113a11102e65796f33ec55a7f 100644 (file)
                     <manifestLocation>${project.build.directory}/META-INF</manifestLocation>
                 </configuration>
             </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>add-yang-sources</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>${salGeneratorPath}</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
         <pluginManagement>
             <plugins>
index ed29520d0f985dc1e62ad12bf8c039ea79398f76..75291dafc61cfdb0f3d067147310da265d8b56c0 100644 (file)
                 <failOnError>true</failOnError>
               </configuration>
             </plugin>
-            <plugin>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>generate-sources</goal>
-                        </goals>
-                        <configuration>
-                            <codeGenerators>
-                                <generator>
-                                    <codeGeneratorClass>
-                                        org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl
-                                    </codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/generated-sources/sal</outputBaseDir>
-                                </generator>
-                                <generator>
-                                    <codeGeneratorClass>org.opendaylight.mdsal.binding.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/site/models</outputBaseDir>
-                                </generator>
-                            </codeGenerators>
-                            <inspectDependencies>true</inspectDependencies>
-                        </configuration>
-                    </execution>
-                </executions>
-                <dependencies>
-                    <dependency>
-                        <groupId>org.opendaylight.mdsal</groupId>
-                        <artifactId>maven-sal-api-gen-plugin</artifactId>
-                        <version>${mdsal.model.version}</version>
-                        <type>jar</type>
-                    </dependency>
-                </dependencies>
-            </plugin>
         </plugins>
     </build>
 
index 88d3fedd2b446d885d5e56b9726f83d4526c4141..60e5af3c1d9a93d2a38e5105e82885da7d6e5104 100644 (file)
@@ -158,7 +158,8 @@ public class OpenFlowPluginProviderImpl implements
         Futures.addCallback(Futures.allAsList(switchConnectionProviders.stream().map(switchConnectionProvider -> {
             // Inject OpenFlowPlugin custom serializers and deserializers into OpenFlowJava
             if (config.isUseSingleLayerSerialization()) {
-                SerializerInjector.injectSerializers(switchConnectionProvider);
+                SerializerInjector.injectSerializers(switchConnectionProvider,
+                        switchConnectionProvider.getConfiguration().isGroupAddModEnabled());
                 DeserializerInjector.injectDeserializers(switchConnectionProvider);
             } else {
                 DeserializerInjector.revertDeserializers(switchConnectionProvider);
index 88bae2285d77d5eb567a63d4e26f4993dce6020d..8b58e5b475adebc5373c1dcaa6addee43e476d7c 100644 (file)
@@ -101,8 +101,8 @@ public class ConnectionContextImpl implements ConnectionContext {
     }
 
     @Override
-    public void setFeatures(final FeaturesReply featuresReply) {
-        this.featuresReply = featuresReply;
+    public void setFeatures(final FeaturesReply newFeaturesReply) {
+        this.featuresReply = newFeaturesReply;
     }
 
     @Override
@@ -186,9 +186,9 @@ public class ConnectionContextImpl implements ConnectionContext {
     }
 
     @Override
-    public void setOutboundQueueHandleRegistration(OutboundQueueHandlerRegistration<OutboundQueueProvider>
-                                                               outboundQueueHandlerRegistration) {
-        this.outboundQueueHandlerRegistration = outboundQueueHandlerRegistration;
+    public void setOutboundQueueHandleRegistration(
+            OutboundQueueHandlerRegistration<OutboundQueueProvider> newRegistration) {
+        this.outboundQueueHandlerRegistration = newRegistration;
     }
 
     private void unregisterOutboundQueue() {
index ecdd45b3a208060878c81be9c7d892f40eab7f87..4c553f5cfe092b2d87bef093322e7e9dfb1ac77e 100644 (file)
@@ -143,7 +143,7 @@ public class HandshakeManagerImpl implements HandshakeManager {
                 @Override
                 public void onSuccess(Void result) {
                     try {
-                        stepByStepVersionSubStep(remoteVersion, lastProposedVersion);
+                        stepByStepVersionSubStep(remoteVersion);
                     } catch (Exception e) {
                         errorHandler.handleException(e);
                         handshakeListener.onHandshakeFailure();
@@ -157,18 +157,18 @@ public class HandshakeManagerImpl implements HandshakeManager {
                 }
             }, MoreExecutors.directExecutor());
         } else {
-            stepByStepVersionSubStep(remoteVersion, lastProposedVersion);
+            stepByStepVersionSubStep(remoteVersion);
         }
     }
 
-    private void stepByStepVersionSubStep(Short remoteVersion, Short lastProposedVersion) throws Exception {
+    private void stepByStepVersionSubStep(Short remoteVersion) throws Exception {
         if (remoteVersion.equals(lastProposedVersion)) {
             postHandshake(lastProposedVersion, getNextXid());
             LOG.trace("ret - OK - switch answered with lastProposedVersion");
         } else {
             checkNegotiationStalling(remoteVersion);
 
-            if (remoteVersion > (lastProposedVersion == null ? highestVersion : this.lastProposedVersion)) {
+            if (remoteVersion > (lastProposedVersion == null ? highestVersion : lastProposedVersion)) {
                 // wait for next version
                 LOG.trace("ret - wait");
             } else {
index 36dcdf323851fef3b080fdbd1b8fb7464e5cb652..872a0df1fa5de427253b3f6303068f655ff17639 100644 (file)
@@ -276,7 +276,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     public void processReply(final OfHeader ofHeader) {
         messageSpy.spyMessage(
                 ofHeader.getImplementedInterface(),
-                (ofHeader instanceof Error)
+                ofHeader instanceof Error
                         ? MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_FAILURE
                         : MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_SUCCESS);
     }
@@ -285,7 +285,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     public void processReply(final Xid xid, final List<? extends OfHeader> ofHeaderList) {
         ofHeaderList.forEach(header -> messageSpy.spyMessage(
                 header.getImplementedInterface(),
-                (header instanceof Error)
+                header instanceof Error
                         ? MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_FAILURE
                         : MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_SUCCESS));
     }
@@ -541,8 +541,8 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     }
 
     @Override
-    public void registerMastershipWatcher(@Nonnull final ContextChainMastershipWatcher contextChainMastershipWatcher) {
-        this.contextChainMastershipWatcher = contextChainMastershipWatcher;
+    public void registerMastershipWatcher(@Nonnull final ContextChainMastershipWatcher newWatcher) {
+        this.contextChainMastershipWatcher = newWatcher;
     }
 
     @Nonnull
@@ -588,7 +588,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
 
     // TODO: exception handling should be fixed by using custom checked exception, never RuntimeExceptions
     @Override
-    @SuppressWarnings({"checkstyle:IllegalCatch", "checkstyle:AvoidHidingCauseExceptionCheck"})
+    @SuppressWarnings({"checkstyle:IllegalCatch"})
     public void instantiateServiceInstance() {
         lazyTransactionManagerInitialization();
 
@@ -600,8 +600,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
             submitTransaction();
         } catch (final Exception ex) {
             throw new RuntimeException(String.format("Error processing port status messages from device %s: %s",
-                    deviceInfo.toString(),
-                    ex.toString()));
+                    deviceInfo.toString(), ex.toString()), ex);
         }
 
         final Optional<AbstractDeviceInitializer> initializer = deviceInitializerProvider
@@ -617,13 +616,10 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
             } catch (TimeoutException ex) {
                 initialize.cancel(true);
                 throw new RuntimeException(String.format("Failed to initialize device %s in %ss: %s",
-                        deviceInfo.toString(),
-                        String.valueOf(DEVICE_INIT_TIMEOUT / 1000),
-                        ex.toString()));
+                        deviceInfo.toString(), String.valueOf(DEVICE_INIT_TIMEOUT / 1000), ex.toString()), ex);
             } catch (ExecutionException | InterruptedException ex) {
-                throw new RuntimeException(String.format("Device %s cannot be initialized: %s",
-                        deviceInfo.toString(),
-                        ex.toString()));
+                throw new RuntimeException(
+                        String.format("Device %s cannot be initialized: %s", deviceInfo.toString(), ex.toString()), ex);
             }
         } else {
             throw new RuntimeException(String.format("Unsupported version %s for device %s",
index 24870569bbf65e8466d55ba2c80695554e0c6da3..3702c9e2a10f61c2638da7c2a287e7dc4796caf5 100644 (file)
@@ -232,18 +232,18 @@ public class ContextChainImpl implements ContextChain {
         deviceRemovedHandlers.add(deviceRemovedHandler);
     }
 
-    private void changeMastershipState(final ContextChainState contextChainState) {
+    private void changeMastershipState(final ContextChainState newContextChainState) {
         if (ContextChainState.CLOSED.equals(this.contextChainState.get())) {
             return;
         }
 
         boolean propagate = ContextChainState.UNDEFINED.equals(this.contextChainState.get());
-        this.contextChainState.set(contextChainState);
+        this.contextChainState.set(newContextChainState);
 
         if (propagate) {
             contexts.forEach(context -> {
                 if (context.map(ContextChainStateListener.class::isInstance)) {
-                    context.map(ContextChainStateListener.class::cast).onStateAcquired(contextChainState);
+                    context.map(ContextChainStateListener.class::cast).onStateAcquired(newContextChainState);
                 }
             });
         }
index 58c7b35a5357f50a913a297a6d20aad9211cca03..3805d4cdd1ad22745de11798dabf856c72e06ac2 100644 (file)
@@ -40,10 +40,10 @@ final class MessageSerializerInjector {
     /**
      * Injects message serializers into provided
      * {@link org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtensionProvider}.
-     *
      * @param provider OpenflowJava serializer extension provider
+     * @param isGroupAddModEnabled config to enale/disable GroupAddMod Message
      */
-    static void injectSerializers(final SerializerExtensionProvider provider) {
+    static void injectSerializers(final SerializerExtensionProvider provider, final boolean isGroupAddModEnabled) {
         // Inject new message serializers here using injector created by createInjector method
         final Function<Class<?>, Consumer<OFSerializer<? extends OfHeader>>> injector =
                 createInjector(provider, EncodeConstants.OF13_VERSION_ID);
@@ -51,7 +51,7 @@ final class MessageSerializerInjector {
         injector.apply(FlowMessage.class).accept(new FlowMessageSerializer());
         injector.apply(MeterMessage.class).accept(new MeterMessageSerializer());
         injector.apply(PortMessage.class).accept(new PortMessageSerializer());
-        injector.apply(GroupMessage.class).accept(new GroupMessageSerializer());
+        injector.apply(GroupMessage.class).accept(new GroupMessageSerializer(isGroupAddModEnabled));
         injector.apply(MultipartRequest.class).accept(new MultipartRequestMessageSerializer());
         injector.apply(AsyncConfigMessage.class).accept(new AsyncConfigMessageSerializer());
     }
index a740ac0ab6cf87174512bab503e94e0c7f003b03..6df805ce3df80c91e2466282adadeb2fcc0929a0 100644 (file)
@@ -21,15 +21,16 @@ public final class SerializerInjector {
     /**
      * Injects serializers into provided
      * {@link org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtensionProvider}.
-     *
      * @param provider OpenflowJava serializer extension provider
+     * @param isGroupAddModEnabled config to enale/disable GroupAddMod Message
      */
-    public static void injectSerializers(final SerializerExtensionProvider provider) {
+    public static void injectSerializers(final SerializerExtensionProvider provider,
+            final boolean isGroupAddModEnabled) {
         // Inject new serializers here
         MatchSerializerInjector.injectSerializers(provider);
         ActionSerializerInjector.injectSerializers(provider);
         InstructionSerializerInjector.injectSerializers(provider);
         MultipartSerializerInjector.injectSerializers(provider);
-        MessageSerializerInjector.injectSerializers(provider);
+        MessageSerializerInjector.injectSerializers(provider, isGroupAddModEnabled);
     }
 }
index a0286c77fe8d04e8481e5890d8419dcf7e510432..d05129b9992e5f1e1ebff9652d74c48e99c0ea69 100644 (file)
@@ -27,9 +27,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13
  * OF protocol versions: 1.3.
  */
 public class GroupMessageSerializer extends AbstractMessageSerializer<GroupMessage> implements
-        SerializerRegistryInjector {
+    SerializerRegistryInjector {
     private static final byte PADDING_IN_GROUP_MOD_MESSAGE = 1;
     private static final byte PADDING_IN_BUCKET = 4;
+    private static final int OFPGC_ADD_OR_MOD = 32768;
+    private final boolean isGroupAddModEnabled;
 
     private static final Comparator<Bucket> COMPARATOR = (bucket1, bucket2) -> {
         if (bucket1.getBucketId() == null || bucket2.getBucketId() == null) {
@@ -40,11 +42,24 @@ public class GroupMessageSerializer extends AbstractMessageSerializer<GroupMessa
 
     private SerializerRegistry registry;
 
+    public GroupMessageSerializer(boolean isGroupAddModEnabled) {
+        this.isGroupAddModEnabled =  isGroupAddModEnabled;
+    }
+
     @Override
     public void serialize(GroupMessage message, ByteBuf outBuffer) {
         final int index = outBuffer.writerIndex();
         super.serialize(message, outBuffer);
-        outBuffer.writeShort(message.getCommand().getIntValue());
+        if (isGroupAddModEnabled) {
+            if (message.getCommand().equals(GroupModCommand.OFPGCADD)
+                    || message.getCommand().equals(GroupModCommand.OFPGCMODIFY)) {
+                outBuffer.writeShort(OFPGC_ADD_OR_MOD);
+            } else {
+                outBuffer.writeShort(message.getCommand().getIntValue());
+            }
+        } else {
+            outBuffer.writeShort(message.getCommand().getIntValue());
+        }
         outBuffer.writeByte(message.getGroupType().getIntValue());
         outBuffer.writeZero(PADDING_IN_GROUP_MOD_MESSAGE);
         outBuffer.writeInt(message.getGroupId().getValue().intValue());
@@ -75,7 +90,6 @@ public class GroupMessageSerializer extends AbstractMessageSerializer<GroupMessa
 
                     outBuffer.setShort(bucketIndex, outBuffer.writerIndex() - bucketIndex);
                 }));
-
         outBuffer.setShort(index + 2, outBuffer.writerIndex() - index);
     }
 
index 88b87527d84546ada3637fe08d413c00e22ddab8..af1fa140aed34f605cc5f9a3187e410161803082 100644 (file)
@@ -81,8 +81,8 @@ public class RoleContextImpl implements RoleContext {
     }
 
     @Override
-    public void registerMastershipWatcher(@Nonnull final ContextChainMastershipWatcher contextChainMastershipWatcher) {
-        this.contextChainMastershipWatcher = contextChainMastershipWatcher;
+    public void registerMastershipWatcher(@Nonnull final ContextChainMastershipWatcher newWatcher) {
+        this.contextChainMastershipWatcher = newWatcher;
     }
 
     @Override
index d293d42d542bfa6ca4427538b2276e62dd54380c..d7e2bb8c52cbb663a4da76694aa158e9f3257abe 100644 (file)
@@ -174,8 +174,8 @@ class RpcContextImpl implements RpcContext {
     }
 
     @Override
-    public void registerMastershipWatcher(@Nonnull final ContextChainMastershipWatcher contextChainMastershipWatcher) {
-        this.contextChainMastershipWatcher = contextChainMastershipWatcher;
+    public void registerMastershipWatcher(@Nonnull final ContextChainMastershipWatcher newWatcher) {
+        this.contextChainMastershipWatcher = newWatcher;
     }
 
     @Override
index 145e51d9a71f701ae983d220edd307ad7f3f02eb..61fd206c2fbe4f0ea7474cadfe3bdb6b10f5aac1 100644 (file)
@@ -66,8 +66,8 @@ class StatisticsContextImpl<T extends OfHeader> implements StatisticsContext {
     private final long maximumPollingDelay;
     private final boolean isUsingReconciliationFramework;
     private final AtomicBoolean schedulingEnabled = new AtomicBoolean(true);
-    private final AtomicReference<ListenableFuture<Boolean>> lastDataGathering = new AtomicReference<>();
-    private final AtomicReference<StatisticsPollingService> statisticsPollingService = new AtomicReference<>();
+    private final AtomicReference<ListenableFuture<Boolean>> lastDataGatheringRef = new AtomicReference<>();
+    private final AtomicReference<StatisticsPollingService> statisticsPollingServiceRef = new AtomicReference<>();
     private List<MultipartType> collectingStatType;
     private StatisticsGatheringService<T> statisticsGatheringService;
     private StatisticsGatheringOnTheFlyService<T> statisticsGatheringOnTheFlyService;
@@ -108,8 +108,8 @@ class StatisticsContextImpl<T extends OfHeader> implements StatisticsContext {
     }
 
     @Override
-    public void registerMastershipWatcher(@Nonnull final ContextChainMastershipWatcher contextChainMastershipWatcher) {
-        this.contextChainMastershipWatcher = contextChainMastershipWatcher;
+    public void registerMastershipWatcher(@Nonnull final ContextChainMastershipWatcher newWatcher) {
+        this.contextChainMastershipWatcher = newWatcher;
     }
 
     @Override
@@ -209,7 +209,7 @@ class StatisticsContextImpl<T extends OfHeader> implements StatisticsContext {
             return Futures.immediateFuture(Boolean.TRUE);
         }
 
-        return this.lastDataGathering.updateAndGet(future -> {
+        return this.lastDataGatheringRef.updateAndGet(future -> {
             // write start timestamp to state snapshot container
             StatisticsGatheringUtils.markDeviceStateSnapshotStart(deviceInfo, deviceContext);
 
@@ -284,19 +284,19 @@ class StatisticsContextImpl<T extends OfHeader> implements StatisticsContext {
 
         schedulingEnabled.set(true);
         statisticsPollingService.startAsync();
-        this.statisticsPollingService.set(statisticsPollingService);
+        this.statisticsPollingServiceRef.set(statisticsPollingService);
     }
 
     private ListenableFuture<Void> stopGatheringData() {
         LOG.info("Stopping running statistics gathering for node {}", deviceInfo);
         cancelLastDataGathering();
 
-        return Optional.ofNullable(statisticsPollingService.getAndSet(null)).map(StatisticsPollingService::stop)
+        return Optional.ofNullable(statisticsPollingServiceRef.getAndSet(null)).map(StatisticsPollingService::stop)
                 .orElseGet(() -> Futures.immediateFuture(null));
     }
 
     private void cancelLastDataGathering() {
-        final ListenableFuture<Boolean> future = lastDataGathering.getAndSet(null);
+        final ListenableFuture<Boolean> future = lastDataGatheringRef.getAndSet(null);
 
         if (Objects.nonNull(future) && !future.isDone() && !future.isCancelled()) {
             future.cancel(true);
index 6b1578b96d2a53f23a3af429f3bd3ca6da1f2eea..fa304791a092fc6b21b83a4796c3576f635c0a1f 100644 (file)
@@ -43,7 +43,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  */
 public class MultipartRequestInputFactoryTest {
 
-    private long xid = 42L;
+    private final long xid = 42L;
     private short ofVersion;
 
     @Before
@@ -57,7 +57,7 @@ public class MultipartRequestInputFactoryTest {
         MultipartType mpType = MultipartType.OFPMPDESC;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         checkEmptyBody(mpRqInput.getMultipartRequestBody(), MultipartRequestDescCase.class);
     }
 
@@ -66,7 +66,7 @@ public class MultipartRequestInputFactoryTest {
         final MultipartType mpType = MultipartType.OFPMPFLOW;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         final MultipartRequestBody mpRqBody = mpRqInput.getMultipartRequestBody();
         Assert.assertTrue(mpRqBody instanceof MultipartRequestFlowCase);
 
@@ -91,7 +91,7 @@ public class MultipartRequestInputFactoryTest {
         ofVersion = OFConstants.OFP_VERSION_1_0;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         final MultipartRequestBody mpRqBody = mpRqInput.getMultipartRequestBody();
         Assert.assertTrue(mpRqBody instanceof MultipartRequestFlowCase);
 
@@ -110,7 +110,7 @@ public class MultipartRequestInputFactoryTest {
         MultipartType mpType = MultipartType.OFPMPAGGREGATE;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         checkEmptyBody(mpRqInput.getMultipartRequestBody(), MultipartRequestAggregateCase.class);
     }
 
@@ -119,7 +119,7 @@ public class MultipartRequestInputFactoryTest {
         MultipartType mpType = MultipartType.OFPMPTABLE;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         checkEmptyBody(mpRqInput.getMultipartRequestBody(), MultipartRequestTableCase.class);
     }
 
@@ -128,7 +128,7 @@ public class MultipartRequestInputFactoryTest {
         final MultipartType mpType = MultipartType.OFPMPPORTSTATS;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         final MultipartRequestBody mpRqBody = mpRqInput.getMultipartRequestBody();
         Assert.assertTrue(mpRqBody instanceof MultipartRequestPortStatsCase);
 
@@ -141,7 +141,7 @@ public class MultipartRequestInputFactoryTest {
         final MultipartType mpType = MultipartType.OFPMPQUEUE;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         final MultipartRequestBody mpRqBody = mpRqInput.getMultipartRequestBody();
         Assert.assertTrue(mpRqBody instanceof MultipartRequestQueueCase);
 
@@ -155,7 +155,7 @@ public class MultipartRequestInputFactoryTest {
         final MultipartType mpType = MultipartType.OFPMPGROUP;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         final MultipartRequestBody mpRqBody = mpRqInput.getMultipartRequestBody();
         Assert.assertTrue(mpRqBody instanceof MultipartRequestGroupCase);
 
@@ -168,7 +168,7 @@ public class MultipartRequestInputFactoryTest {
         MultipartType mpType = MultipartType.OFPMPGROUPDESC;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         checkEmptyBody(mpRqInput.getMultipartRequestBody(), MultipartRequestGroupDescCase.class);
     }
 
@@ -177,7 +177,7 @@ public class MultipartRequestInputFactoryTest {
         MultipartType mpType = MultipartType.OFPMPGROUPFEATURES;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         checkEmptyBody(mpRqInput.getMultipartRequestBody(), MultipartRequestGroupFeaturesCase.class);
     }
 
@@ -186,7 +186,7 @@ public class MultipartRequestInputFactoryTest {
         final MultipartType mpType = MultipartType.OFPMPMETER;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         final MultipartRequestBody mpRqBody = mpRqInput.getMultipartRequestBody();
         Assert.assertTrue(mpRqBody instanceof MultipartRequestMeterCase);
 
@@ -199,7 +199,7 @@ public class MultipartRequestInputFactoryTest {
         final MultipartType mpType = MultipartType.OFPMPMETERCONFIG;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         final MultipartRequestBody mpRqBody = mpRqInput.getMultipartRequestBody();
         Assert.assertTrue(mpRqBody instanceof MultipartRequestMeterConfigCase);
 
@@ -213,7 +213,7 @@ public class MultipartRequestInputFactoryTest {
         MultipartType mpType = MultipartType.OFPMPMETERFEATURES;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         checkEmptyBody(mpRqInput.getMultipartRequestBody(), MultipartRequestMeterFeaturesCase.class);
     }
 
@@ -222,7 +222,7 @@ public class MultipartRequestInputFactoryTest {
         final MultipartType mpType = MultipartType.OFPMPTABLEFEATURES;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         final MultipartRequestBody mpRqBody = mpRqInput.getMultipartRequestBody();
         Assert.assertTrue(mpRqBody instanceof MultipartRequestTableFeaturesCase);
 
@@ -236,7 +236,7 @@ public class MultipartRequestInputFactoryTest {
         MultipartType mpType = MultipartType.OFPMPPORTDESC;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         checkEmptyBody(mpRqInput.getMultipartRequestBody(), MultipartRequestPortDescCase.class);
     }
 
@@ -245,11 +245,11 @@ public class MultipartRequestInputFactoryTest {
         MultipartType mpType = MultipartType.OFPMPEXPERIMENTER;
         final MultipartRequestInput mpRqInput =
             (MultipartRequestInput) MultipartRequestInputFactory.makeMultipartRequest(xid, ofVersion, mpType, false);
-        checkHeader(mpRqInput, mpType, ofVersion);
+        checkHeader(mpRqInput, mpType);
         checkEmptyBody(mpRqInput.getMultipartRequestBody(), MultipartRequestExperimenterCase.class);
     }
 
-    private void checkHeader(MultipartRequestInput mpRqInput, MultipartType mpType, short ofVersion) {
+    private void checkHeader(MultipartRequestInput mpRqInput, MultipartType mpType) {
         Assert.assertFalse(mpRqInput.getFlags().isOFPMPFREQMORE());
         Assert.assertEquals(ofVersion, mpRqInput.getVersion().shortValue());
         Assert.assertEquals(mpType, mpRqInput.getType());
index 6b2e76408ad10ad15667bb05246b6ea739fd140c..bbcc12ea4e0ab4672e4238b61c28b29c339d948c 100644 (file)
@@ -37,7 +37,6 @@ import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
@@ -145,8 +144,9 @@ public class DeviceContextImplTest {
     private OutboundQueueProvider outboundQueueProvider;
     @Mock
     private ConnectionAdapter connectionAdapter;
-    private NodeId nodeId = new NodeId("h2g2:42");
-    private KeyedInstanceIdentifier<Node, NodeKey> nodeKeyIdent = DeviceStateUtil.createNodeInstanceIdentifier(nodeId);
+    private final NodeId nodeId = new NodeId("h2g2:42");
+    private final KeyedInstanceIdentifier<Node, NodeKey> nodeKeyIdent =
+            DeviceStateUtil.createNodeInstanceIdentifier(nodeId);
     @Mock
     private TranslatorLibrary translatorLibrary;
     @Mock
@@ -258,7 +258,7 @@ public class DeviceContextImplTest {
 
     @Test
     public void testGetReadTransaction() {
-        final ReadTransaction readTx = deviceContext.getReadTransaction();
+        readTx = deviceContext.getReadTransaction();
         assertNotNull(readTx);
         assertEquals(this.readTx, readTx);
     }
index 152031c1ac7b87b11c15b1705724395b8de66e20..8b016e982a7272a7477c6c111bc222c34b6ba59d 100644 (file)
@@ -35,6 +35,7 @@ public class ClearStatsCommandProviderTest extends AbstractKarafTest {
     };
     private MessageIntelligenceAgency mi5;
 
+    @Override
     public void doSetUp() {
         clearStatsCommandProvider = new ClearStatsCommandProvider();
         mi5 = OpenFlowPluginProviderImpl.getMessageIntelligenceAgency();
@@ -64,7 +65,7 @@ public class ClearStatsCommandProviderTest extends AbstractKarafTest {
      */
     @Test
     public void testDoExecute_dirty() throws Exception {
-        final MessageIntelligenceAgency mi5 = OpenFlowPluginProviderImpl.getMessageIntelligenceAgency();
+        mi5 = OpenFlowPluginProviderImpl.getMessageIntelligenceAgency();
         Assert.assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
         mi5.spyMessage(OfHeader.class, MessageSpy.StatisticsGroup.FROM_SWITCH);
         Assert.assertFalse(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
@@ -72,4 +73,4 @@ public class ClearStatsCommandProviderTest extends AbstractKarafTest {
         clearStatsCommandProvider.execute(cmdSession);
         Assert.assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
     }
-}
\ No newline at end of file
+}
index b7e8412aeb45e1cd46aa0738102d79ebf8129cd5..5a367880e5f224106e36d5b124a3157daea33eac 100644 (file)
@@ -36,7 +36,7 @@ public abstract class AbstractSerializerTest {
         registry = new SerializerRegistryImpl();
         registry.init();
         provider = new SerializerExtensionProviderImpl(registry);
-        SerializerInjector.injectSerializers(provider);
+        SerializerInjector.injectSerializers(provider, false);
         init();
     }
 
index 9a6c2c141cfa09099da09a5f67759b2298e7b064..b9be54d89420ed90961601e35de37e8f015d5698 100644 (file)
@@ -107,7 +107,7 @@ public class DeviceFlowRegistryImplTest {
                 .build();
 
         final Map<FlowRegistryKey, FlowDescriptor> allFlowDescriptors = fillRegistry(path, flowCapableNode);
-        final FlowRegistryKey key = FlowRegistryKeyFactory.create(OFConstants.OFP_VERSION_1_3, flow);
+        key = FlowRegistryKeyFactory.create(OFConstants.OFP_VERSION_1_3, flow);
 
         InOrder order = inOrder(dataBroker, readOnlyTransaction);
         order.verify(dataBroker).newReadOnlyTransaction();
@@ -240,7 +240,7 @@ public class DeviceFlowRegistryImplTest {
     @Test
     public void testForEach() throws Exception {
         final AtomicInteger counter = new AtomicInteger(0);
-        deviceFlowRegistry.forEach(key -> counter.incrementAndGet());
+        deviceFlowRegistry.forEach(k -> counter.incrementAndGet());
         Assert.assertEquals(1, counter.get());
     }
 
index cebe9bfb2c0cbccbeaeab6b7c13a0b29c69ce0d6..5e0b46f567dacb1e39bc7edf24f310e0450b42a0 100644 (file)
@@ -78,7 +78,7 @@ public class StatisticsContextImplTest extends StatisticsContextImpMockInitiatio
     @Test
     @SuppressWarnings("checkstyle:IllegalCatch")
     public void testClose() throws Exception {
-        final StatisticsContextImpl<MultipartReply> statisticsContext =
+        statisticsContext =
                 new StatisticsContextImpl<>(mockedDeviceContext,
                                             convertorManager,
                                             MultipartWriterProviderFactory
index edf9b715cdba9e9245796075c12bcb467e60afd9..359217c3a368c17ebab4f02937bbc8a4645955f8 100644 (file)
@@ -131,12 +131,11 @@ public class StatisticsManagerImplTest {
             .thenReturn(new DeviceFlowRegistryImpl(OFConstants.OFP_VERSION_1_3, dataBroker, nodePath));
         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
         when(mockedDeviceContext.getMultiMsgCollector(
-                Matchers.<RequestContext<List<MultipartReply>>>any())).thenAnswer(
+            Matchers.<RequestContext<List<MultipartReply>>>any())).thenAnswer(
                 invocation -> {
                     currentRequestContext = (RequestContext<List<MultipartReply>>) invocation.getArguments()[0];
                     return multiMagCollector;
-                }
-        );
+                });
         when(rpcProviderRegistry.addRpcImplementation(
                 Matchers.eq(StatisticsManagerControlService.class),
                 Matchers.<StatisticsManagerControlService>any())).thenReturn(serviceControlRegistration);
index cca27841a850b274406c2c2c9712bb0cc99e491d..8d6092cdc6ea816c7b9edee32b250fcc21bbe67b 100644 (file)
@@ -148,8 +148,8 @@ public class AbstractCompatibleStatServiceTest extends AbstractStatsServiceTest
                 service.handleAndNotify(input, notificationPublishService);
 
         Assert.assertTrue(resultFuture.isDone());
-        final RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> rpcResult = resultFuture.get();
-        Assert.assertTrue(rpcResult.isSuccessful());
+        final RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> result = resultFuture.get();
+        Assert.assertTrue(result.isSuccessful());
         Assert.assertEquals(MultipartType.OFPMPAGGREGATE, requestInput.getValue().getType());
         Mockito.verify(notificationPublishService, Mockito.timeout(500))
                 .offerNotification(Matchers.any(AggregateFlowStatisticsUpdate.class));
index 0e614d7d40904b2ee6df43d423423b5193327a56..53c372d1275912560e7986e33daead6f1ea6ff4f 100644 (file)
@@ -69,8 +69,6 @@ public class PacketReceivedTranslatorTest {
     @Mock
     DeviceInfo deviceInfo;
     @Mock
-    List<PhyPort> phyPorts;
-    @Mock
     PhyPort phyPort;
 
     ConvertorManager convertorManager;
index 113180f8160e415bb0c085889ccb4174e5c7cd4a..c28bd917d0bce9654d3fc2bb7a0d8005ad98cb70 100644 (file)
@@ -9,11 +9,11 @@ package org.opendaylight.openflowplugin.openflow.md.core.extension;
 
 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
 import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey;
+import org.opendaylight.openflowplugin.extension.api.ConverterMessageToOFJava;
 import org.opendaylight.openflowplugin.extension.api.ConvertorActionFromOFJava;
 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
 import org.opendaylight.openflowplugin.extension.api.ConvertorFromOFJava;
 import org.opendaylight.openflowplugin.extension.api.ConvertorMessageFromOFJava;
-import org.opendaylight.openflowplugin.extension.api.ConverterMessageToOFJava;
 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
 import org.opendaylight.openflowplugin.extension.api.TypeVersionKey;
 import org.opendaylight.openflowplugin.extension.api.path.AugmentationPath;
@@ -83,7 +83,7 @@ public abstract class RegistrationCloser<KEY, CONVERTER> implements ObjectRegist
             RegistrationCloser<ConverterExtensionKey<? extends ExtensionKey>, ConvertorToOFJava<TO>> {
 
         @Override
-        public void close() throws Exception {
+        public void close() {
             getRegistrator().unregister(getKey(), getConverter());
         }
     }
@@ -96,7 +96,7 @@ public abstract class RegistrationCloser<KEY, CONVERTER> implements ObjectRegist
     public static class RegistrationCloserFromOFJava<FROM extends DataContainer, PATH extends AugmentationPath> extends RegistrationCloser<MessageTypeKey<?>, ConvertorFromOFJava<FROM, PATH>> {
 
         @Override
-        public void close() throws Exception {
+        public void close() {
             getRegistrator().unregister(getKey(), getConverter());
         }
     }
@@ -109,7 +109,7 @@ public abstract class RegistrationCloser<KEY, CONVERTER> implements ObjectRegist
             RegistrationCloser<TypeVersionKey<? extends Action>, ConvertorActionToOFJava<Action, TO>> {
 
         @Override
-        public void close() throws Exception {
+        public void close() {
             getRegistrator().unregister(getKey(), getConverter());
         }
     }
@@ -123,7 +123,7 @@ public abstract class RegistrationCloser<KEY, CONVERTER> implements ObjectRegist
             RegistrationCloser<MessageTypeKey<?>, ConvertorActionFromOFJava<FROM, PATH>> {
 
         @Override
-        public void close() throws Exception {
+        public void close() {
             getRegistrator().unregister(getKey(), getConverter());
         }
     }
@@ -137,7 +137,7 @@ public abstract class RegistrationCloser<KEY, CONVERTER> implements ObjectRegist
             RegistrationCloser<TypeVersionKey<K>, ConverterMessageToOFJava<K, TO>> {
 
         @Override
-        public void close() throws Exception {
+        public void close() {
             getRegistrator().unregister(getKey(), getConverter());
         }
     }
@@ -152,7 +152,7 @@ public abstract class RegistrationCloser<KEY, CONVERTER> implements ObjectRegist
             RegistrationCloser<MessageTypeKey<?>, ConvertorMessageFromOFJava<FROM, PATH>> {
 
         @Override
-        public void close() throws Exception {
+        public void close() {
             getRegistrator().unregister(getKey(), getConverter());
         }
     }
index 1a7cd144e9f4fc4e7def02accfd6e03594ed0fd6..85f4cf0c87ab1d8252d0d9b2691c97954c079a56 100644 (file)
@@ -10,9 +10,9 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
     <parent>
-        <groupId>org.opendaylight.odlparent</groupId>
-        <artifactId>odlparent</artifactId>
-        <version>2.0.5</version>
+        <groupId>org.opendaylight.mdsal</groupId>
+        <artifactId>binding-parent</artifactId>
+        <version>0.12.0-SNAPSHOT</version>
         <relativePath/>
     </parent>
 
 
     <properties>
         <project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
-        <sal.api.version>0.14.0-SNAPSHOT</sal.api.version>
-        <salGeneratorPath>${project.build.directory}/generated-sources/sal</salGeneratorPath>
-        <controller.distribution.version>0.7.0-SNAPSHOT</controller.distribution.version>
-        <mdsal.version>1.7.0-SNAPSHOT</mdsal.version>
-        <mdsal.model.version>0.12.0-SNAPSHOT</mdsal.model.version>
-        <yangtools.version>1.2.0</yangtools.version>
-        <argparse4j.version>0.7.0</argparse4j.version>
         <exi.nagasena.version>0000.0002.0053.0</exi.nagasena.version>
         <infrautils.version>1.3.0-SNAPSHOT</infrautils.version>
     </properties>
                 <scope>import</scope>
                 <type>pom</type>
             </dependency>
-            <dependency>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yangtools-artifacts</artifactId>
-                <version>${yangtools.version}</version>
-                <scope>import</scope>
-                <type>pom</type>
-            </dependency>
-            <dependency>
-                <groupId>org.opendaylight.mdsal</groupId>
-                <artifactId>mdsal-artifacts</artifactId>
-                <version>2.4.0-SNAPSHOT</version>
-                <scope>import</scope>
-                <type>pom</type>
-            </dependency>
-            <dependency>
-                <groupId>org.opendaylight.mdsal.model</groupId>
-                <artifactId>mdsal-model-artifacts</artifactId>
-                <version>${mdsal.model.version}</version>
-                <scope>import</scope>
-                <type>pom</type>
-            </dependency>
             <dependency>
                 <groupId>org.opendaylight.controller</groupId>
                 <artifactId>mdsal-artifacts</artifactId>
-                <version>${mdsal.version}</version>
-                <scope>import</scope>
+                <version>1.7.0-SNAPSHOT</version>
                 <type>pom</type>
+                <scope>import</scope>
             </dependency>
             <dependency>
                 <groupId>org.opendaylight.controller</groupId>
                 <artifactId>liblldp</artifactId>
-                <version>${sal.api.version}</version>
+                <version>0.14.0-SNAPSHOT</version>
             </dependency>
             <!-- thirdparty -->
             <dependency>
@@ -98,7 +70,7 @@
             <dependency>
                 <groupId>net.sourceforge.argparse4j</groupId>
                 <artifactId>argparse4j</artifactId>
-                <version>${argparse4j.version}</version>
+                <version>0.7.0</version>
             </dependency>
         </dependencies>
     </dependencyManagement>
         </plugins>
         <pluginManagement>
             <plugins>
-                <plugin>
-                    <artifactId>maven-clean-plugin</artifactId>
-                    <configuration>
-                        <filesets>
-                            <fileset>
-                                <directory>${salGeneratorPath}</directory>
-                                <includes>
-                                    <include>**</include>
-                                </includes>
-                            </fileset>
-                        </filesets>
-                    </configuration>
-                </plugin>
-                <plugin>
-                    <groupId>org.codehaus.mojo</groupId>
-                    <artifactId>build-helper-maven-plugin</artifactId>
-                    <executions>
-                        <execution>
-                            <id>add-source</id>
-                            <phase>generate-sources</phase>
-                            <goals>
-                                <goal>add-source</goal>
-                            </goals>
-                            <configuration>
-                                <sources>
-                                    <source>${salGeneratorPath}</source>
-                                </sources>
-                            </configuration>
-                        </execution>
-                    </executions>
-                </plugin>
-                <plugin>
-                    <groupId>org.opendaylight.yangtools</groupId>
-                    <artifactId>yang-maven-plugin</artifactId>
-                    <version>${yangtools.version}</version>
-                </plugin>
                 <plugin>
                     <groupId>org.apache.felix</groupId>
                     <artifactId>maven-bundle-plugin</artifactId>
index d674b537704d0fe5314edbbc931df1a2234561f9..e1faadf09c2d0be293f19965880715b7d7a7f02f 100644 (file)
@@ -40,6 +40,7 @@
         <dependency>
             <groupId>org.eclipse.tycho</groupId>
             <artifactId>org.eclipse.osgi</artifactId>
+            <version>3.10.101.v20150820-1432</version>
         </dependency>
         <dependency>
             <groupId>commons-lang</groupId>