Refactor: resolve code smells of openstacknetworking impl pkgs #3

Change-Id: I825e23cd16917abd4512d35222d695b268064ff7
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DefaultInstancePort.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DefaultInstancePort.java
index 23dc684..f4569d5 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DefaultInstancePort.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DefaultInstancePort.java
@@ -82,6 +82,13 @@
         this.oldPortNumber = oldPortNumber;
     }
 
+    /**
+     * A constructor fed by host and state.
+     *
+     * @param host  host object
+     * @param state instance port state
+     * @return instance port
+     */
     public static DefaultInstancePort from(Host host, State state) {
         checkNotNull(host);
         checkArgument(!Strings.isNullOrEmpty(
@@ -94,6 +101,15 @@
         return new DefaultInstancePort(host, state, null, null);
     }
 
+    /**
+     * A constructor fed by host, state, device ID and port number.
+     *
+     * @param host  host object
+     * @param state instance port state
+     * @param oldDeviceId device identifier
+     * @param oldPortNumber port number
+     * @return instance port
+     */
     public static DefaultInstancePort from(Host host,
                                            State state,
                                            DeviceId oldDeviceId,
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedInstancePortStore.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedInstancePortStore.java
index 3ad00b5..e34ddbe 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedInstancePortStore.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedInstancePortStore.java
@@ -160,24 +160,13 @@
         public void event(MapEvent<String, InstancePort> event) {
             switch (event.type()) {
                 case INSERT:
-                    log.debug("Instance port created");
-                    eventExecutor.execute(() ->
-                            notifyDelegate(new InstancePortEvent(
-                                    OPENSTACK_INSTANCE_PORT_DETECTED,
-                                    event.newValue().value()))
-                    );
+                    eventExecutor.execute(() -> processInstancePortMapInsertion(event));
                     break;
                 case UPDATE:
-                    log.debug("Instance port updated");
-                    eventExecutor.execute(() -> processInstancePortUpdate(event));
+                    eventExecutor.execute(() -> processInstancePortMapUpdate(event));
                     break;
                 case REMOVE:
-                    log.debug("Instance port removed");
-                    eventExecutor.execute(() ->
-                            notifyDelegate(new InstancePortEvent(
-                                    OPENSTACK_INSTANCE_PORT_VANISHED,
-                                    event.oldValue().value()))
-                    );
+                    eventExecutor.execute(() -> processInstancePortMapRemoval(event));
                     break;
                 default:
                     log.error("Unsupported instance port event type");
@@ -185,6 +174,25 @@
             }
         }
 
+        private void processInstancePortMapUpdate(MapEvent<String, InstancePort> event) {
+            log.debug("Instance port updated");
+            processInstancePortUpdate(event);
+        }
+
+        private void processInstancePortMapInsertion(MapEvent<String, InstancePort> event) {
+            log.debug("Instance port created");
+            notifyDelegate(new InstancePortEvent(
+                    OPENSTACK_INSTANCE_PORT_DETECTED,
+                    event.newValue().value()));
+        }
+
+        private void processInstancePortMapRemoval(MapEvent<String, InstancePort> event) {
+            log.debug("Instance port removed");
+            notifyDelegate(new InstancePortEvent(
+                    OPENSTACK_INSTANCE_PORT_VANISHED,
+                    event.oldValue().value()));
+        }
+
         private void processInstancePortUpdate(MapEvent<String, InstancePort> event) {
             InstancePort.State oldState = event.oldValue().value().state();
             InstancePort.State newState = event.newValue().value().state();
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackNetworkStore.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackNetworkStore.java
index fba1599..fe91af1 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackNetworkStore.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackNetworkStore.java
@@ -282,34 +282,40 @@
         public void event(MapEvent<String, Network> event) {
             switch (event.type()) {
                 case UPDATE:
-                    log.debug("OpenStack network updated");
-                    eventExecutor.execute(() ->
-                        notifyDelegate(new OpenstackNetworkEvent(
-                                OPENSTACK_NETWORK_UPDATED,
-                                event.newValue().value()))
-                    );
+                    eventExecutor.execute(() -> processNetworkMapUpdate(event));
                     break;
                 case INSERT:
-                    log.debug("OpenStack network created");
-                    eventExecutor.execute(() ->
-                        notifyDelegate(new OpenstackNetworkEvent(
-                                OPENSTACK_NETWORK_CREATED,
-                                event.newValue().value()))
-                    );
+                    eventExecutor.execute(() -> processNetworkMapInsertion(event));
                     break;
                 case REMOVE:
-                    log.debug("OpenStack network removed");
-                    eventExecutor.execute(() ->
-                        notifyDelegate(new OpenstackNetworkEvent(
-                                OPENSTACK_NETWORK_REMOVED,
-                                event.oldValue().value()))
-                    );
+                    eventExecutor.execute(() -> processNetworkMapRemoval(event));
                     break;
                 default:
                     log.error("Unsupported openstack network event type");
                     break;
             }
         }
+
+        private void processNetworkMapUpdate(MapEvent<String, Network> event) {
+            log.debug("OpenStack network updated");
+            notifyDelegate(new OpenstackNetworkEvent(
+                    OPENSTACK_NETWORK_UPDATED,
+                    event.newValue().value()));
+        }
+
+        private void processNetworkMapInsertion(MapEvent<String, Network> event) {
+            log.debug("OpenStack network created");
+            notifyDelegate(new OpenstackNetworkEvent(
+                    OPENSTACK_NETWORK_CREATED,
+                    event.newValue().value()));
+        }
+
+        private void processNetworkMapRemoval(MapEvent<String, Network> event) {
+            log.debug("OpenStack network removed");
+            notifyDelegate(new OpenstackNetworkEvent(
+                    OPENSTACK_NETWORK_REMOVED,
+                    event.oldValue().value()));
+        }
     }
 
     private class OpenstackSubnetMapListener implements MapEventListener<String, Subnet> {
@@ -318,37 +324,43 @@
         public void event(MapEvent<String, Subnet> event) {
             switch (event.type()) {
                 case UPDATE:
-                    log.debug("OpenStack subnet updated");
-                    eventExecutor.execute(() ->
-                        notifyDelegate(new OpenstackNetworkEvent(
-                                OPENSTACK_SUBNET_UPDATED,
-                                network(event.newValue().value().getNetworkId()),
-                                event.newValue().value()))
-                    );
+                    eventExecutor.execute(() -> processSubnetMapUpdate(event));
                     break;
                 case INSERT:
-                    log.debug("OpenStack subnet created");
-                    eventExecutor.execute(() ->
-                        notifyDelegate(new OpenstackNetworkEvent(
-                                OPENSTACK_SUBNET_CREATED,
-                                network(event.newValue().value().getNetworkId()),
-                                event.newValue().value()))
-                    );
+                    eventExecutor.execute(() -> processSubnetMapInsertion(event));
                     break;
                 case REMOVE:
-                    log.debug("OpenStack subnet removed");
-                    eventExecutor.execute(() ->
-                        notifyDelegate(new OpenstackNetworkEvent(
-                                OPENSTACK_SUBNET_REMOVED,
-                                network(event.oldValue().value().getNetworkId()),
-                                event.oldValue().value()))
-                    );
+                    eventExecutor.execute(() -> processSubnetMapRemoval(event));
                     break;
                 default:
                     log.error("Unsupported openstack subnet event type");
                     break;
             }
         }
+
+        private void processSubnetMapUpdate(MapEvent<String, Subnet> event) {
+            log.debug("OpenStack subnet updated");
+            notifyDelegate(new OpenstackNetworkEvent(
+                    OPENSTACK_SUBNET_UPDATED,
+                    network(event.newValue().value().getNetworkId()),
+                    event.newValue().value()));
+        }
+
+        private void processSubnetMapInsertion(MapEvent<String, Subnet> event) {
+            log.debug("OpenStack subnet created");
+            notifyDelegate(new OpenstackNetworkEvent(
+                    OPENSTACK_SUBNET_CREATED,
+                    network(event.newValue().value().getNetworkId()),
+                    event.newValue().value()));
+        }
+
+        private void processSubnetMapRemoval(MapEvent<String, Subnet> event) {
+            log.debug("OpenStack subnet removed");
+            notifyDelegate(new OpenstackNetworkEvent(
+                    OPENSTACK_SUBNET_REMOVED,
+                    network(event.oldValue().value().getNetworkId()),
+                    event.oldValue().value()));
+        }
     }
 
     private class OpenstackPortMapListener implements MapEventListener<String, Port> {
@@ -357,40 +369,13 @@
         public void event(MapEvent<String, Port> event) {
             switch (event.type()) {
                 case UPDATE:
-                    eventExecutor.execute(() -> {
-                        Port oldPort = event.oldValue().value();
-                        Port newPort = event.newValue().value();
-                        notifyDelegate(new OpenstackNetworkEvent(
-                                OPENSTACK_PORT_UPDATED,
-                                network(event.newValue().value().getNetworkId()), newPort));
-                        processSecurityGroupUpdate(oldPort, newPort);
-                    });
+                    eventExecutor.execute(() -> processPortMapUpdate(event));
                     break;
                 case INSERT:
-                    log.debug("OpenStack port created");
-                    eventExecutor.execute(() ->
-                        notifyDelegate(new OpenstackNetworkEvent(
-                                OPENSTACK_PORT_CREATED,
-                                network(event.newValue().value().getNetworkId()),
-                                event.newValue().value()))
-                    );
+                    eventExecutor.execute(() -> processPortMapInsertion(event));
                     break;
                 case REMOVE:
-                    log.debug("OpenStack port removed");
-
-                    eventExecutor.execute(() ->
-                            notifyDelegate(new OpenstackNetworkEvent(
-                                    OPENSTACK_PORT_PRE_REMOVE,
-                                    network(event.oldValue().value().getNetworkId()),
-                                    event.oldValue().value()))
-                    );
-
-                    eventExecutor.execute(() ->
-                        notifyDelegate(new OpenstackNetworkEvent(
-                                OPENSTACK_PORT_REMOVED,
-                                network(event.oldValue().value().getNetworkId()),
-                                event.oldValue().value()))
-                    );
+                    eventExecutor.execute(() -> processPortMapRemoval(event));
                     break;
                 default:
                     log.error("Unsupported openstack port event type");
@@ -398,6 +383,37 @@
             }
         }
 
+        private void processPortMapUpdate(MapEvent<String, Port> event) {
+            log.debug("OpenStack port updated");
+            Port oldPort = event.oldValue().value();
+            Port newPort = event.newValue().value();
+            notifyDelegate(new OpenstackNetworkEvent(
+                    OPENSTACK_PORT_UPDATED,
+                    network(event.newValue().value().getNetworkId()), newPort));
+            processSecurityGroupUpdate(oldPort, newPort);
+        }
+
+        private void processPortMapInsertion(MapEvent<String, Port> event) {
+            log.debug("OpenStack port created");
+            notifyDelegate(new OpenstackNetworkEvent(
+                    OPENSTACK_PORT_CREATED,
+                    network(event.newValue().value().getNetworkId()),
+                    event.newValue().value()));
+        }
+
+        private void processPortMapRemoval(MapEvent<String, Port> event) {
+            log.debug("OpenStack port removed");
+            notifyDelegate(new OpenstackNetworkEvent(
+                    OPENSTACK_PORT_PRE_REMOVE,
+                    network(event.oldValue().value().getNetworkId()),
+                    event.oldValue().value()));
+
+            notifyDelegate(new OpenstackNetworkEvent(
+                    OPENSTACK_PORT_REMOVED,
+                    network(event.oldValue().value().getNetworkId()),
+                    event.oldValue().value()));
+        }
+
         private void processSecurityGroupUpdate(Port oldPort, Port newPort) {
             List<String> oldSecurityGroups = oldPort.getSecurityGroups() == null ?
                     ImmutableList.of() : oldPort.getSecurityGroups();
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackRouterStore.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackRouterStore.java
index c8bd925..03e86bf 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackRouterStore.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackRouterStore.java
@@ -272,29 +272,13 @@
         public void event(MapEvent<String, Router> event) {
             switch (event.type()) {
                 case UPDATE:
-                    log.debug("OpenStack router updated");
-                    eventExecutor.execute(() -> {
-                        notifyDelegate(new OpenstackRouterEvent(
-                                OPENSTACK_ROUTER_UPDATED,
-                                event.newValue().value()));
-                        processGatewayUpdate(event);
-                    });
+                    eventExecutor.execute(() -> processRouterMapUpdate(event));
                     break;
                 case INSERT:
-                    log.debug("OpenStack router created");
-                    eventExecutor.execute(() ->
-                        notifyDelegate(new OpenstackRouterEvent(
-                                OPENSTACK_ROUTER_CREATED,
-                                event.newValue().value()))
-                    );
+                    eventExecutor.execute(() -> processRouterMapInsertion(event));
                     break;
                 case REMOVE:
-                    log.debug("OpenStack router removed");
-                    eventExecutor.execute(() ->
-                        notifyDelegate(new OpenstackRouterEvent(
-                                OPENSTACK_ROUTER_REMOVED,
-                                event.oldValue().value()))
-                    );
+                    eventExecutor.execute(() -> processRouterMapRemoval(event));
                     break;
                 default:
                     log.error("Unsupported openstack router event type");
@@ -302,6 +286,28 @@
             }
         }
 
+        private void processRouterMapUpdate(MapEvent<String, Router> event) {
+            log.debug("OpenStack router updated");
+            notifyDelegate(new OpenstackRouterEvent(
+                    OPENSTACK_ROUTER_UPDATED,
+                    event.newValue().value()));
+            processGatewayUpdate(event);
+        }
+
+        private void processRouterMapInsertion(MapEvent<String, Router> event) {
+            log.debug("OpenStack router created");
+            notifyDelegate(new OpenstackRouterEvent(
+                    OPENSTACK_ROUTER_CREATED,
+                    event.newValue().value()));
+        }
+
+        private void processRouterMapRemoval(MapEvent<String, Router> event) {
+            log.debug("OpenStack router removed");
+            notifyDelegate(new OpenstackRouterEvent(
+                    OPENSTACK_ROUTER_REMOVED,
+                    event.oldValue().value()));
+        }
+
         private void processGatewayUpdate(MapEvent<String, Router> event) {
             ExternalGateway oldGateway = event.oldValue().value().getExternalGatewayInfo();
             ExternalGateway newGateway = event.newValue().value().getExternalGatewayInfo();
@@ -326,37 +332,43 @@
         public void event(MapEvent<String, RouterInterface> event) {
             switch (event.type()) {
                 case UPDATE:
-                    log.debug("OpenStack router interface updated");
-                    eventExecutor.execute(() ->
-                        notifyDelegate(new OpenstackRouterEvent(
-                                OPENSTACK_ROUTER_INTERFACE_UPDATED,
-                                router(event.newValue().value().getId()),
-                                event.newValue().value()))
-                    );
+                    eventExecutor.execute(() -> processRouterIntfUpdate(event));
                     break;
                 case INSERT:
-                    log.debug("OpenStack router interface created");
-                    eventExecutor.execute(() ->
-                        notifyDelegate(new OpenstackRouterEvent(
-                                OPENSTACK_ROUTER_INTERFACE_ADDED,
-                                router(event.newValue().value().getId()),
-                                event.newValue().value()))
-                    );
+                    eventExecutor.execute(() -> processRouterIntfInsertion(event));
                     break;
                 case REMOVE:
-                    log.debug("OpenStack router interface removed");
-                    eventExecutor.execute(() ->
-                        notifyDelegate(new OpenstackRouterEvent(
-                                OPENSTACK_ROUTER_INTERFACE_REMOVED,
-                                router(event.oldValue().value().getId()),
-                                event.oldValue().value()))
-                    );
+                    eventExecutor.execute(() -> processRouterIntfRemoval(event));
                     break;
                 default:
                     log.error("Unsupported openstack router interface event type");
                     break;
             }
         }
+
+        private void processRouterIntfUpdate(MapEvent<String, RouterInterface> event) {
+            log.debug("OpenStack router interface updated");
+            notifyDelegate(new OpenstackRouterEvent(
+                    OPENSTACK_ROUTER_INTERFACE_UPDATED,
+                    router(event.newValue().value().getId()),
+                    event.newValue().value()));
+        }
+
+        private void processRouterIntfInsertion(MapEvent<String, RouterInterface> event) {
+            log.debug("OpenStack router interface created");
+            notifyDelegate(new OpenstackRouterEvent(
+                    OPENSTACK_ROUTER_INTERFACE_ADDED,
+                    router(event.newValue().value().getId()),
+                    event.newValue().value()));
+        }
+
+        private void processRouterIntfRemoval(MapEvent<String, RouterInterface> event) {
+            log.debug("OpenStack router interface removed");
+            notifyDelegate(new OpenstackRouterEvent(
+                    OPENSTACK_ROUTER_INTERFACE_REMOVED,
+                    router(event.oldValue().value().getId()),
+                    event.oldValue().value()));
+        }
     }
 
     private class OpenstackFloatingIpMapListener
@@ -366,44 +378,13 @@
         public void event(MapEvent<String, NetFloatingIP> event) {
             switch (event.type()) {
                 case UPDATE:
-                    log.debug("OpenStack floating IP updated");
-                    eventExecutor.execute(() -> {
-                        Router osRouter = Strings.isNullOrEmpty(
-                                event.newValue().value().getRouterId()) ?
-                                null :
-                                router(event.newValue().value().getRouterId());
-                        notifyDelegate(new OpenstackRouterEvent(
-                                OPENSTACK_FLOATING_IP_UPDATED,
-                                osRouter,
-                                event.newValue().value()));
-                        processFloatingIpUpdate(event, osRouter);
-                    });
+                    eventExecutor.execute(() -> processFloatingIpMapUpdate(event));
                     break;
                 case INSERT:
-                    log.debug("OpenStack floating IP created");
-                    eventExecutor.execute(() -> {
-                        Router osRouter = Strings.isNullOrEmpty(
-                                event.newValue().value().getRouterId()) ?
-                                null :
-                                router(event.newValue().value().getRouterId());
-                        notifyDelegate(new OpenstackRouterEvent(
-                                OPENSTACK_FLOATING_IP_CREATED,
-                                osRouter,
-                                event.newValue().value()));
-                    });
+                    eventExecutor.execute(() -> processFloatingIpMapInsertion(event));
                     break;
                 case REMOVE:
-                    log.debug("OpenStack floating IP removed");
-                    eventExecutor.execute(() -> {
-                        Router osRouter = Strings.isNullOrEmpty(
-                                event.oldValue().value().getRouterId()) ?
-                                null :
-                                router(event.oldValue().value().getRouterId());
-                        notifyDelegate(new OpenstackRouterEvent(
-                                OPENSTACK_FLOATING_IP_REMOVED,
-                                osRouter,
-                                event.oldValue().value()));
-                    });
+                    eventExecutor.execute(() -> processFloatingIpMapRemoval(event));
                     break;
                 default:
                     log.error("Unsupported openstack floating IP event type");
@@ -411,6 +392,43 @@
             }
         }
 
+        private void processFloatingIpMapUpdate(MapEvent<String, NetFloatingIP> event) {
+            log.debug("OpenStack floating IP updated");
+            Router osRouter = Strings.isNullOrEmpty(
+                    event.newValue().value().getRouterId()) ?
+                    null :
+                    router(event.newValue().value().getRouterId());
+            notifyDelegate(new OpenstackRouterEvent(
+                    OPENSTACK_FLOATING_IP_UPDATED,
+                    osRouter,
+                    event.newValue().value()));
+            processFloatingIpUpdate(event, osRouter);
+        }
+
+        private void processFloatingIpMapInsertion(MapEvent<String, NetFloatingIP> event) {
+            log.debug("OpenStack floating IP created");
+            Router osRouter = Strings.isNullOrEmpty(
+                    event.newValue().value().getRouterId()) ?
+                    null :
+                    router(event.newValue().value().getRouterId());
+            notifyDelegate(new OpenstackRouterEvent(
+                    OPENSTACK_FLOATING_IP_CREATED,
+                    osRouter,
+                    event.newValue().value()));
+        }
+
+        private void processFloatingIpMapRemoval(MapEvent<String, NetFloatingIP> event) {
+            log.debug("OpenStack floating IP removed");
+            Router osRouter = Strings.isNullOrEmpty(
+                    event.oldValue().value().getRouterId()) ?
+                    null :
+                    router(event.oldValue().value().getRouterId());
+            notifyDelegate(new OpenstackRouterEvent(
+                    OPENSTACK_FLOATING_IP_REMOVED,
+                    osRouter,
+                    event.oldValue().value()));
+        }
+
         private void processFloatingIpUpdate(MapEvent<String, NetFloatingIP> event,
                                              Router osRouter) {
             String oldPortId = event.oldValue().value().getPortId();
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackMetadataProxyHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackMetadataProxyHandler.java
index 66250e0..011768d 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackMetadataProxyHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackMetadataProxyHandler.java
@@ -634,6 +634,9 @@
      */
     protected static class Http extends BasePacket {
 
+        /**
+         * HTTP packet type.
+         */
         public enum Type {
 
             /**
@@ -650,6 +653,9 @@
         private Type type;
         private HttpMessage message;
 
+        Http() {
+        }
+
         /**
          * Obtains the Http type.
          *
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingDhcpHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingDhcpHandler.java
index 6111395..4e3dbbb 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingDhcpHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingDhcpHandler.java
@@ -120,6 +120,11 @@
     private static final int V4_CIDR_UPPER_BOUND = 33;
     private static final int PADDING_SIZE = 4;
 
+    private static final byte HARDWARE_ADDR_LENGTH = (byte) 6;
+    private static final byte DHCP_OPTION_DATA_LENGTH = (byte) 4;
+    private static final int DHCP_OPTION_DNS_LENGTH = 8;
+    private static final int DHCP_OPTION_MTU_LENGTH = 2;
+
     @Reference(cardinality = ReferenceCardinality.MANDATORY)
     protected CoreService coreService;
 
@@ -361,7 +366,7 @@
             DHCP dhcpReply = new DHCP();
             dhcpReply.setOpCode(DHCP.OPCODE_REPLY);
             dhcpReply.setHardwareType(DHCP.HWTYPE_ETHERNET);
-            dhcpReply.setHardwareAddressLength((byte) 6);
+            dhcpReply.setHardwareAddressLength(HARDWARE_ADDR_LENGTH);
             dhcpReply.setTransactionId(request.getTransactionId());
             dhcpReply.setFlags(request.getFlags());
             dhcpReply.setYourIPAddress(yourIp.toInt());
@@ -422,7 +427,7 @@
         private DhcpOption doServerId(IpAddress gatewayIp) {
             DhcpOption option = new DhcpOption();
             option.setCode(OptionCode_DHCPServerIp.getValue());
-            option.setLength((byte) 4);
+            option.setLength(DHCP_OPTION_DATA_LENGTH);
             option.setData(gatewayIp.toOctets());
             return option;
         }
@@ -430,7 +435,7 @@
         private DhcpOption doLeaseTime() {
             DhcpOption option = new DhcpOption();
             option.setCode(OptionCode_LeaseTime.getValue());
-            option.setLength((byte) 4);
+            option.setLength(DHCP_OPTION_DATA_LENGTH);
             option.setData(DHCP_DATA_LEASE_INFINITE);
             return option;
         }
@@ -439,7 +444,7 @@
             Ip4Address subnetMask = Ip4Address.makeMaskPrefix(subnetPrefixLen);
             DhcpOption option = new DhcpOption();
             option.setCode(OptionCode_SubnetMask.getValue());
-            option.setLength((byte) 4);
+            option.setLength(DHCP_OPTION_DATA_LENGTH);
             option.setData(subnetMask.toOctets());
             return option;
         }
@@ -448,7 +453,7 @@
             Ip4Address broadcast = Ip4Address.makeMaskedAddress(yourIp, subnetPrefixLen);
             DhcpOption option = new DhcpOption();
             option.setCode(OptionCode_BroadcastAddress.getValue());
-            option.setLength((byte) 4);
+            option.setLength(DHCP_OPTION_DATA_LENGTH);
             option.setData(broadcast.toOctets());
             return option;
         }
@@ -460,8 +465,8 @@
             option.setCode(OptionCode_DomainServer.getValue());
 
             if (dnsServers.isEmpty()) {
-                option.setLength((byte) 8);
-                ByteBuffer dnsByteBuf = ByteBuffer.allocate(8);
+                option.setLength((byte) DHCP_OPTION_DNS_LENGTH);
+                ByteBuffer dnsByteBuf = ByteBuffer.allocate(DHCP_OPTION_DNS_LENGTH);
                 dnsByteBuf.put(DEFAULT_PRIMARY_DNS.toOctets());
                 dnsByteBuf.put(DEFAULT_SECONDARY_DNS.toOctets());
 
@@ -471,7 +476,7 @@
 
                 option.setLength((byte) dnsLength);
 
-                ByteBuffer dnsByteBuf = ByteBuffer.allocate(8);
+                ByteBuffer dnsByteBuf = ByteBuffer.allocate(DHCP_OPTION_DNS_LENGTH);
 
                 for (String dnsServer : dnsServers) {
                     dnsByteBuf.put(IpAddress.valueOf(dnsServer).toOctets());
@@ -485,12 +490,13 @@
         private DhcpOption doMtu(Subnet osSubnet) {
             DhcpOption option = new DhcpOption();
             option.setCode(DHCP_OPTION_MTU);
-            option.setLength((byte) 2);
+            option.setLength((byte) DHCP_OPTION_MTU_LENGTH);
             Network osNetwork = osNetworkService.network(osSubnet.getNetworkId());
             checkNotNull(osNetwork);
             checkNotNull(osNetwork.getMTU());
 
-            option.setData(ByteBuffer.allocate(2).putShort(osNetwork.getMTU().shortValue()).array());
+            option.setData(ByteBuffer.allocate(DHCP_OPTION_MTU_LENGTH)
+                            .putShort(osNetwork.getMTU().shortValue()).array());
 
             return option;
         }
@@ -526,7 +532,7 @@
         private DhcpOption doRouterAddr(Subnet osSubnet) {
             DhcpOption option = new DhcpOption();
             option.setCode(OptionCode_RouterAddress.getValue());
-            option.setLength((byte) 4);
+            option.setLength(DHCP_OPTION_DATA_LENGTH);
             option.setData(Ip4Address.valueOf(osSubnet.getGateway()).toOctets());
             return option;
         }