ONOS-4086 to ONOS-4091, ONOS-4098 to ONOS-4100:ISIS controller implementation

Change-Id: I7be52805652fe762baf808515401d6b5042b2aa5
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisConfig.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisConfig.java
deleted file mode 100644
index 9b37cbd..0000000
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisConfig.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.isis.io.util;
-
-import com.fasterxml.jackson.databind.JsonNode;
-
-/**
- * Representation of ISIS config.
- */
-public enum IsisConfig {
-    INSTANCE;
-    private JsonNode jsonNodes = null;
-
-    /**
-     * Returns the config value.
-     *
-     * @return jsonNodes json node
-     */
-    public JsonNode config() {
-        return jsonNodes;
-    }
-
-    /**
-     * Sets the config value for jsonNode.
-     *
-     * @param jsonNodes json node
-     */
-    public void setConfig(JsonNode jsonNodes) {
-        this.jsonNodes = jsonNodes;
-    }
-}
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisConstants.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisConstants.java
index fe84218..cf5871a 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisConstants.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisConstants.java
@@ -16,21 +16,25 @@
 
 package org.onosproject.isis.io.util;
 
+import org.onlab.packet.Ip4Address;
+
 /**
  * Representation of ISIS Constants.
  */
 public final class IsisConstants {
-    public static final char PDU_LENGTH = 1497; // mtu (1500) - (3) LLC
+    public static final char PDU_LENGTH = 1497;
+    public static final char CONFIG_LENGTH = 1498;
     public static final int MINIMUM_FRAME_LEN = 1521;
     public static final int METADATA_LEN = 7;
     public static final String SHOST = "127.0.0.1";
+    public static final Ip4Address DEFAULTIP = Ip4Address.valueOf("0.0.0.0");
     public static final int SPORT = 3000;
     public static final byte L2 = 1;
     public static final int IRPDISCRIMINATOR = 131;
     public static final int ISISVERSION = 1;
     public static final int RESERVED = 0;
     public static final int MAXAREAADDRESS = 0;
-    public static final int IDLENGTH = 0;
+    public static final int SYSTEMIDLENGTH = 0;
     public static final int PROTOCOLSUPPORTED = 204;
     public static final int LOCALCIRCUITIDFORP2P = 130;
     public static final int P2PHELLOHEADERLENGTH = 20;
@@ -48,6 +52,27 @@
     public static final int CHECKSUMPOSITION = 24;
     public static final String REFRESHLSP = "refreshLsp";
     public static final String MAXAGELSP = "maxAgeLsp";
+    public static final String DEFAULTLANID = "0000.0000.0000.00";
+    public static final String PROCESSESID = "processId";
+    public static final String INTERFACE = "interface";
+    public static final String INTERFACEIP = "interfaceIp";
+    public static final String NETWORKMASK = "networkMask";
+    public static final String INTERFACEINDEX = "interfaceIndex";
+    public static final String INTERMEDIATESYSTEMNAME = "intermediateSystemName";
+    public static final String SYSTEMID = "systemId";
+    public static final String LANID = "lanId";
+    public static final String IDLENGTH = "idLength";
+    public static final String MAXAREAADDRESSES = "maxAreaAddresses";
+    public static final String RESERVEDPACKETCIRCUITTYPE = "reservedPacketCircuitType";
+    public static final String CIRCUITID = "circuitId";
+    public static final String NETWORKTYPE = "networkType";
+    public static final String AREAADDRESS = "areaAddress";
+    public static final String AREALENGTH = "areaLength";
+    public static final String LSPID = "lspId";
+    public static final String HOLDINGTIME = "holdingTime";
+    public static final String HELLOINTERVAL = "helloInterval";
+    public static final String PRIORITY = "priority";
+    public static final String MACADDRESS = "macAddress";
 
     /**
      * Non parameterized constructor.
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisUtil.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisUtil.java
index 44ad9e0..c21a93b 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisUtil.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/IsisUtil.java
@@ -391,7 +391,7 @@
         isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR);
         isisHeader.setPduHeaderLength((byte) IsisConstants.P2PHELLOHEADERLENGTH);
         isisHeader.setVersion((byte) IsisConstants.ISISVERSION);
-        isisHeader.setIdLength((byte) IsisConstants.IDLENGTH);
+        isisHeader.setIdLength((byte) IsisConstants.SYSTEMIDLENGTH);
         isisHeader.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
         isisHeader.setVersion2((byte) IsisConstants.ISISVERSION);
         //isisHeader.setReserved((byte) IsisConstants.RESERVED);
@@ -484,7 +484,7 @@
         isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR);
         isisHeader.setPduHeaderLength((byte) IsisConstants.HELLOHEADERLENGTH);
         isisHeader.setVersion((byte) IsisConstants.ISISVERSION);
-        isisHeader.setIdLength((byte) IsisConstants.IDLENGTH);
+        isisHeader.setIdLength((byte) IsisConstants.SYSTEMIDLENGTH);
         if (isisPduType == IsisPduType.L1HELLOPDU) {
             isisHeader.setIsisPduType(IsisPduType.L1HELLOPDU.value());
             lanId = isisInterface.l1LanId();
@@ -693,4 +693,19 @@
         }
         return prefix;
     }
+
+    /**
+     * Converts the prefix to bytes.
+     *
+     * @param prefix prefix
+     * @return prefix to bytes
+     */
+    public static byte[] prefixToBytes(String prefix) {
+        List<Byte> byteList = new ArrayList<>();
+        StringTokenizer tokenizer = new StringTokenizer(prefix, ".");
+        while (tokenizer.hasMoreTokens()) {
+            byteList.add((byte) Integer.parseInt(tokenizer.nextToken()));
+        }
+        return Bytes.toArray(byteList);
+    }
 }
\ No newline at end of file
diff --git a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/LspGenerator.java b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/LspGenerator.java
index 1dfb1a4..c6ae962 100644
--- a/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/LspGenerator.java
+++ b/protocols/isis/isisio/src/main/java/org/onosproject/isis/io/util/LspGenerator.java
@@ -26,6 +26,7 @@
 import org.onosproject.isis.io.isispacket.pdu.LsPdu;
 import org.onosproject.isis.io.isispacket.tlv.AreaAddressTlv;
 import org.onosproject.isis.io.isispacket.tlv.HostNameTlv;
+import org.onosproject.isis.io.isispacket.tlv.IpExtendedReachabilityTlv;
 import org.onosproject.isis.io.isispacket.tlv.IpInterfaceAddressTlv;
 import org.onosproject.isis.io.isispacket.tlv.IpInternalReachabilityTlv;
 import org.onosproject.isis.io.isispacket.tlv.IsReachabilityTlv;
@@ -115,7 +116,7 @@
         } else if (isisInterface.networkType() == IsisNetworkType.P2P) {
             MacAddress neighborMac = isisInterface.neighbors().iterator().next();
             IsisNeighbor neighbor = isisInterface.lookup(neighborMac);
-            metricsOfReachability.setNeighborId(neighbor.neighborSystemId());
+            metricsOfReachability.setNeighborId(neighbor.neighborSystemId() + ".00");
         }
 
         isReachabilityTlv.addMeticsOfReachability(metricsOfReachability);
@@ -137,10 +138,25 @@
         metricOfIntRea.setErrorMetric((byte) 0);
         metricOfIntRea.setErrorMetricSupported(false);
         metricOfIntRea.setExpenseIsInternal(true);
-        metricOfIntRea.setIpAddress(isisInterface.interfaceIpAddress());
+        Ip4Address ip4Address = isisInterface.interfaceIpAddress();
+        byte[] ipAddress = ip4Address.toOctets();
+        ipAddress[ipAddress.length - 1] = 0;
+        metricOfIntRea.setIpAddress(Ip4Address.valueOf(ipAddress));
         metricOfIntRea.setSubnetAddres(Ip4Address.valueOf(isisInterface.networkMask()));
         ipInterReacTlv.addInternalReachabilityMetric(metricOfIntRea);
         lsp.addTlv(ipInterReacTlv);
+
+        tlvHeader.setTlvType(TlvType.IPEXTENDEDREACHABILITY.value());
+        tlvHeader.setTlvLength(0);
+        IpExtendedReachabilityTlv extendedTlv = new IpExtendedReachabilityTlv(tlvHeader);
+        extendedTlv.setDown(false);
+        extendedTlv.setMetric(10);
+        extendedTlv.setPrefix("192.168.7");
+        extendedTlv.setPrefixLength(24);
+        extendedTlv.setSubTlvLength((byte) 0);
+        extendedTlv.setSubTlvPresence(false);
+        lsp.addTlv(extendedTlv);
+
         return lsp;
     }
 
@@ -149,7 +165,7 @@
         isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR);
         isisHeader.setPduHeaderLength((byte) IsisUtil.getPduHeaderLength(pduType.value()));
         isisHeader.setVersion((byte) IsisConstants.ISISVERSION);
-        isisHeader.setIdLength((byte) IsisConstants.IDLENGTH);
+        isisHeader.setIdLength((byte) IsisConstants.SYSTEMIDLENGTH);
         isisHeader.setIsisPduType(pduType.value());
         isisHeader.setVersion2((byte) IsisConstants.ISISVERSION);
         isisHeader.setReserved((byte) IsisConstants.RESERVED);