Patch Panel Application with Ui

Change-Id: I0906983cf494ce82de233e8bfbd66b60d0792c89
diff --git a/apps/patchpanel/pom.xml b/apps/patchpanel/pom.xml
new file mode 100644
index 0000000..2666e72
--- /dev/null
+++ b/apps/patchpanel/pom.xml
@@ -0,0 +1,188 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2016 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.
+  -->
+<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>
+        <artifactId>onos-apps</artifactId>
+        <groupId>org.onosproject</groupId>
+        <version>1.7.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.onosproject</groupId>
+    <artifactId>patchPanel</artifactId>
+    <version>1.0</version>
+    <packaging>bundle</packaging>
+
+    <description>ONOS OSGi bundle archetype</description>
+    <url>http://onosproject.org</url>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <onos.version>1.7.0-SNAPSHOT</onos.version>
+        <onos.app.name>org.onosproject.patchPanel</onos.app.name>
+        <onos.app.title>Patch Panel</onos.app.title>
+        <onos.app.origin>Foo, Inc.</onos.app.origin>
+        <onos.app.category>default</onos.app.category>
+        <onos.app.url>http://onosproject.org</onos.app.url>
+        <onos.app.readme>ONOS OSGi bundle archetype.</onos.app.readme>
+       
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-api</artifactId>
+            <version>1.7.0-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-misc</artifactId>
+            <version>1.7.0-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-osgi</artifactId>
+            <version>${onos.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.12</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-api</artifactId>
+            <version>${onos.version}</version>
+            <scope>test</scope>
+            <classifier>tests</classifier>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+            <version>1.9.12</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-incubator-api</artifactId>
+            <version>1.7.0-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-core-common</artifactId>
+            <version>1.7.0-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+          <groupId>org.onosproject</groupId>
+          <artifactId>onos-cli</artifactId>
+          <version>1.7.0-SNAPSHOT</version>
+          <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+          <groupId>org.osgi</groupId>
+          <artifactId>org.osgi.core</artifactId>
+          <version>5.0.0</version>
+          <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+          <groupId>org.apache.karaf.shell</groupId>
+          <artifactId>org.apache.karaf.shell.console</artifactId>
+          <version>3.0.5</version>
+          <scope>provided</scope>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>3.0.1</version>
+                <extensions>true</extensions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.5.1</version>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+                <version>1.21.0</version>
+                <executions>
+                    <execution>
+                        <id>generate-scr-srcdescriptor</id>
+                        <goals>
+                            <goal>scr</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <supportedProjectTypes>
+                        <supportedProjectType>bundle</supportedProjectType>
+                        <supportedProjectType>war</supportedProjectType>
+                    </supportedProjectTypes>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.onosproject</groupId>
+                <artifactId>onos-maven-plugin</artifactId>
+                <version>1.9</version>
+                <executions>
+                    <execution>
+                        <id>cfg</id>
+                        <phase>generate-resources</phase>
+                        <goals>
+                            <goal>cfg</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>swagger</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>swagger</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>app</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>app</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/PatchPanelCommand.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/PatchPanelCommand.java
new file mode 100644
index 0000000..bac3221
--- /dev/null
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/PatchPanelCommand.java
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+/**
+ * This class defines the cli command for the PatchPanel class. It creates
+ * an instance of the PatchPanelService class to call it's method addPatch().
+ * The command takes 2 parameters, 2 connectPoints.
+ */
+package org.onosproject.patchpanel.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.patchpanel.impl.PatchPanelService;
+
+//name of command and description
+@Command(scope = "onos", name = "patch",
+         description = "Gets the 2 ports of one ConnectPoint that will be patched")
+
+public class PatchPanelCommand extends AbstractShellCommand {
+    //the 2 arguments, both connect points
+    @Argument(index = 0, name = "switch/portNumber", description = "ConnectPoint and first port number",
+            required = true, multiValued = false)
+    String port1 = null;
+    @Argument (index = 1, name = "switch/portNumber2", description = "ConnectPoint and second port number",
+            required = true, multiValued = false)
+    String port2 = null;
+
+    private ConnectPoint cp1, cp2;
+    private PatchPanelService patchPanelService;
+    private DeviceId deviceId, deviceId2;
+
+    /**
+     * This method creates an instance of the Service class and then uses the user
+     * input to call the addPatch method in PatchPanel. It also
+     * @throws IllegalArgumentException if the 2 connectpoints are of different devices
+     */
+    @Override
+    protected void execute() {
+        patchPanelService = get(PatchPanelService.class);
+        boolean done = false;
+        cp1 = ConnectPoint.deviceConnectPoint(port1);
+        cp2 = ConnectPoint.deviceConnectPoint(port2);
+        deviceId = cp1.deviceId();
+        deviceId2 = cp2.deviceId();
+        if (!(deviceId.equals(deviceId2))) {
+            throw new IllegalArgumentException("ERROR: Two Different Device Id's");
+        } else {
+            done = patchPanelService.addPatch(cp1, cp2);
+        }
+        if (done) {
+            log.info("This patch has been created");
+        } else {
+            log.info("This patch was NOT created");
+        }
+
+    }
+
+}
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/package-info.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/package-info.java
new file mode 100644
index 0000000..85a7842
--- /dev/null
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/cli/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * patch panel-related CLI commands(in cli folder).
+ */
+package org.onosproject.patchpanel.cli;
+
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/AppUiComponent.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/AppUiComponent.java
new file mode 100644
index 0000000..8402cb1
--- /dev/null
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/AppUiComponent.java
@@ -0,0 +1,75 @@
+/*
+ * 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.patchpanel.impl;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onosproject.ui.UiExtension;
+import org.onosproject.ui.UiExtensionService;
+import org.onosproject.ui.UiMessageHandlerFactory;
+import org.onosproject.ui.UiView;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+/**
+ *  ONOS UI Custom-View application component for the Patch Panel Application.
+ */
+@Component(immediate = true)
+public class AppUiComponent {
+
+    private static final String VIEW_ID = "sampleCustom";
+    private static final String VIEW_TEXT = "Patch Panel Application";
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected UiExtensionService uiExtensionService;
+
+    // List of application views
+    private final List<UiView> uiViews = ImmutableList.of(
+            new UiView(UiView.Category.OTHER, VIEW_ID, VIEW_TEXT)
+    );
+
+    // Factory for UI message handlers
+    private final UiMessageHandlerFactory messageHandlerFactory =
+            () -> ImmutableList.of(new AppUiMessageHandler());
+
+    // Application UI extension
+    protected UiExtension extension =
+            new UiExtension.Builder(getClass().getClassLoader(), uiViews)
+                    .resourcePath(VIEW_ID)
+                    .messageHandlerFactory(messageHandlerFactory)
+                    .build();
+
+    @Activate
+    protected void activate() {
+        uiExtensionService.register(extension);
+        log.info("Started");
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        uiExtensionService.unregister(extension);
+        log.info("Stopped");
+    }
+
+}
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/AppUiMessageHandler.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/AppUiMessageHandler.java
new file mode 100644
index 0000000..431f4d0
--- /dev/null
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/AppUiMessageHandler.java
@@ -0,0 +1,139 @@
+/*
+ * 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.patchpanel.impl;
+
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.ImmutableSet;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.ui.RequestHandler;
+import org.onosproject.ui.UiMessageHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.onosproject.net.Device;
+import org.onosproject.net.Port;
+import org.onosproject.net.device.DeviceService;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ *  ONOS UI Custom-View message handler.
+ *
+ *  This class contains the request handlers that handle the response
+ *  to each event. In this particular implementation the second message
+ *  handler creates the patch and the first message handler loads the data
+ */
+public class AppUiMessageHandler extends UiMessageHandler {
+
+    private static final String SAMPLE_CUSTOM_DATA_REQ = "sampleCustomDataRequest";
+    private static final String SAMPLE_CUSTOM_DATA_RESP = "sampleCustomDataResponse";
+    private static final String SAMPLE_CUSTOM_DATA_REQ2 = "sampleCustomDataRequest2";
+    private static final String SAMPLE_CUSTOM_DATA_RESP2 = "sampleCustomDataResponse2";
+    private static final String SAMPLE_CUSTOM_DATA_REQ3 = "sampleCustomDataRequest3";
+    private static final String SAMPLE_CUSTOM_DATA_RESP3 = "sampleCustomDataResponse3";
+    private String message = "";
+    private String cpoints = "";
+    private List<ConnectPoint> previous = new ArrayList<>();
+    private static ConnectPoint cp1;
+    private static ConnectPoint cp2;
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Override
+    protected Collection<RequestHandler> createRequestHandlers() {
+        return ImmutableSet.of(new DataRequestHandler(), new SecondDataRequestHandler(), new ThirdDataRequestHandler());
+    }
+
+    // handler for data requests/events
+    private final class DataRequestHandler extends RequestHandler {
+
+        private DataRequestHandler() {
+            super(SAMPLE_CUSTOM_DATA_REQ);
+        }
+
+        @Override
+        public void process(long sid, ObjectNode payload) {
+            DeviceService service = get(DeviceService.class);
+            ObjectNode result = objectNode();
+            ArrayNode cps = arrayNode();
+            result.set("cps", cps);
+
+            for (Device device : service.getDevices()) {
+                cps.add(device.id().toString());
+                for (Port port : service.getPorts(device.id())) {
+                    if (!port.number().isLogical()) {
+                        cps.add(port.number().toString());
+                        log.info(device.id().toString() + "/" + port.number());
+                    }
+                }
+            }
+            sendMessage(SAMPLE_CUSTOM_DATA_RESP, 0, result);
+        }
+    }
+
+    private final class SecondDataRequestHandler extends RequestHandler {
+
+        private SecondDataRequestHandler() {
+            super(SAMPLE_CUSTOM_DATA_REQ2);
+        }
+
+        @Override
+        public void process(long sid, ObjectNode payload) {
+            boolean done;
+            String deviceId = payload.get("result").get(0).asText();
+            cp1 = ConnectPoint.deviceConnectPoint(deviceId + "/" + payload.get("result").get(1).asText());
+            cp2 = ConnectPoint.deviceConnectPoint(deviceId + "/" + payload.get("result").get(2).asText());
+            PatchPanelService patchPanelService;
+            patchPanelService = get(PatchPanelService.class);
+            done = patchPanelService.addPatch(cp1, cp2);
+            if (done) {
+                message = "Patch has been created";
+                previous.add(cp1);
+                previous.add(cp2);
+            } else {
+                message = "One or both of these ports are already in use";
+                if (cp1.port().equals(cp2.port())) {
+                    message = "Both ports can not be the same";
+                }
+            }
+            payload.put("message", message);
+            sendMessage(SAMPLE_CUSTOM_DATA_RESP2, sid, payload);
+
+        }
+    }
+    private final class ThirdDataRequestHandler extends RequestHandler {
+        private ThirdDataRequestHandler() {
+            super(SAMPLE_CUSTOM_DATA_REQ3);
+        }
+
+        @Override
+        public void process(long sid, ObjectNode payload) {
+            cpoints = "";
+            for (int i = 0; i < previous.size(); i++) {
+                if (i % 2 == 1) {
+                    cpoints += previous.get(i) + "\n";
+                } else {
+                    cpoints += previous.get(i) + " with ";
+                }
+            }
+            payload.put("cpoints", cpoints);
+            sendMessage(SAMPLE_CUSTOM_DATA_RESP3, sid, payload);
+        }
+    }
+}
\ No newline at end of file
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanel.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanel.java
new file mode 100644
index 0000000..068ae00
--- /dev/null
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanel.java
@@ -0,0 +1,111 @@
+/*
+ * 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.
+ */
+
+/**
+ * This class acts as a software patch panel application.
+ * The user specifies 2 connectpoint on the same device that he/she would like to patch.
+ * Using a flow rule, the 2 connectpoints are patched.
+ *
+ * @author Parvahti Meyyappan
+ * @version %I%, %G%
+ */
+
+package org.onosproject.patchpanel.impl;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.flow.DefaultFlowRule;
+import org.onosproject.net.flow.FlowRuleService;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.packet.PacketPriority;
+import org.onosproject.net.ConnectPoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
+import java.util.List;
+
+
+@Component(immediate = true)
+@Service
+public class PatchPanel implements PatchPanelService {
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected FlowRuleService flowRuleService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected CoreService coreService;
+
+    private List<ConnectPoint> previous = new ArrayList<>();
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    private ApplicationId appId;
+    private ConnectPoint cp1, cp2;
+
+
+    @Activate
+    protected void activate() throws NullPointerException {
+        log.info("Started");
+        try {
+            appId = coreService.getAppId("org.onosproject.patchPanel");
+        } catch (NullPointerException e) {
+            throw new NullPointerException("ERROR:App Id is null");
+        }
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        log.info("Stopped");
+    }
+
+    @Override
+    public boolean addPatch(ConnectPoint num, ConnectPoint num2) {
+        cp1 = num;
+        cp2 = num2;
+        if ((cp1.port().equals(cp2.port())) || (previous.contains(cp1) || previous.contains(cp2))) {
+            log.info("One or both of these ports are already in use, NO FLOW");
+            return false;
+        } else {
+            previous.add(cp1);
+            previous.add(cp2);
+            setFlowRuleService();
+            return true;
+        }
+    }
+
+    public void setFlowRuleService() {
+        PortNumber outPort = cp2.port();
+        PortNumber inPort = cp1.port();
+        FlowRule fr = DefaultFlowRule.builder()
+                .forDevice(cp1.deviceId())
+                .withSelector(DefaultTrafficSelector.builder().matchInPort(inPort).build())
+                .withTreatment(DefaultTrafficTreatment.builder().setOutput(outPort).build())
+                .withPriority(PacketPriority.REACTIVE.priorityValue())
+                .makeTemporary(5)
+                .fromApp(appId).build();
+
+        flowRuleService.applyFlowRules(fr);
+
+    }
+
+}
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanelService.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanelService.java
new file mode 100644
index 0000000..64754c0
--- /dev/null
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/PatchPanelService.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2014 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.patchpanel.impl;
+import org.onosproject.net.ConnectPoint;
+
+/**
+ * A service for the patch panel application to
+ * export and use with the cli .
+ */
+public interface PatchPanelService {
+
+    /**
+     * Get the connectPoints that need to be patched.
+     * @param cp    the first connect point
+     * @param cp2   the second connect point
+     * @return void
+     */
+    public boolean addPatch(ConnectPoint cp, ConnectPoint cp2);
+
+}
\ No newline at end of file
diff --git a/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/package-info.java b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/package-info.java
new file mode 100644
index 0000000..6bee0e2
--- /dev/null
+++ b/apps/patchpanel/src/main/java/org/onosproject/patchpanel/impl/package-info.java
@@ -0,0 +1,21 @@
+
+/*
+ * 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.
+ */
+
+/**
+ * patch panel-related CLI commands(in implementation folder).
+ */
+package org.onosproject.patchpanel.impl;
diff --git a/apps/patchpanel/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/apps/patchpanel/src/main/resources/OSGI-INF/blueprint/shell-config.xml
new file mode 100644
index 0000000..b881168
--- /dev/null
+++ b/apps/patchpanel/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -0,0 +1,26 @@
+<!--
+  ~ 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.
+  -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+        <command>
+            <action class="org.onosproject.patchpanel.cli.PatchPanelCommand"/>
+            <completers>
+                <ref component-id="ConnectPointCompleter"/>
+            </completers>
+        </command>
+    </command-bundle>
+    <bean id="ConnectPointCompleter" class="org.onosproject.cli.net.ConnectPointCompleter"/>
+</blueprint>
diff --git a/apps/patchpanel/src/main/resources/app/view/sampleCustom/sampleCustom.css b/apps/patchpanel/src/main/resources/app/view/sampleCustom/sampleCustom.css
new file mode 100644
index 0000000..ffeac0a
--- /dev/null
+++ b/apps/patchpanel/src/main/resources/app/view/sampleCustom/sampleCustom.css
@@ -0,0 +1,48 @@
+/* css for sample app custom view */
+
+#ov-sample-custom {
+    padding: 20px;
+}
+.light #ov-sample-custom {
+    color: navy;
+}
+.dark #ov-sample-custom {
+    color: #88f;
+}
+
+#ov-sample-custom .button-panel {
+    margin: 10px;
+    width: 200px;
+}
+
+.light #ov-sample-custom .button-panel {
+    background-color: #ccf;
+}
+.dark #ov-sample-custom .button-panel {
+    background-color: #444;
+}
+
+#ov-sample-custom .my-button {
+    cursor: pointer;
+    padding: 4px;
+    text-align: center;
+}
+
+.light #ov-sample-custom .my-button {
+    color: white;
+    background-color: #99d;
+}
+.dark #ov-sample-custom .my-button {
+    color: black;
+    background-color: #aaa;
+}
+
+#ov-sample-custom .number {
+    font-size: 140%;
+    text-align: right;
+}
+
+#ov-sample-custom .quote {
+    margin: 10px 20px;
+    font-style: italic;
+}
\ No newline at end of file
diff --git a/apps/patchpanel/src/main/resources/app/view/sampleCustom/sampleCustom.html b/apps/patchpanel/src/main/resources/app/view/sampleCustom/sampleCustom.html
new file mode 100644
index 0000000..34204b4
--- /dev/null
+++ b/apps/patchpanel/src/main/resources/app/view/sampleCustom/sampleCustom.html
@@ -0,0 +1,54 @@
+<!-- partial HTML of patch panel app -->
+<div id="ov-sample-custom" ng-controller="OvSampleCustomCtrl">
+    <div class="button-panel">
+        <div class="my-button" ng-click="getData()">
+            Load Devices
+        </div>
+
+    </div>
+    <div class="data-panel">
+        <div>
+            <label>Devices:
+                <select ng-model="myDev" ng-options="dev.name for dev in devices"></select>
+            </label>
+
+        </div>
+    </div>
+    <div class="button-panel">
+        <div class="my-button" ng-click="loadPorts()">
+            Load Ports
+        </div>
+    </div>
+    <div class="data-panel2">
+        <label>First Port:
+            <select ng-model="myPort1" ng-options="port.name for port in ports"></select>
+        </label>
+        <label>Second Port:
+            <select ng-model="myPort2" ng-options="port.name for port in ports"></select>
+        </label>
+    </div>
+    <div class="button-panel">
+        <div class="my-button" ng-click="done()">
+            Patch!
+        </div>
+    </div>
+    <div class="data-panel3">
+        <p>
+            <span class="quote">{{data.message}} </span>
+        </p>
+         <pre>
+
+
+        </pre>
+    </div>
+    <div class="button-panel">
+        <div class="my-button" ng-click="used()">
+            ConnectPoints in use
+        </div>
+    </div>
+    <div class="data-panel4">
+        <p>
+            <span class="quote">{{data.cpoints}} </span>
+        </p>
+    </div>
+</div>
\ No newline at end of file
diff --git a/apps/patchpanel/src/main/resources/app/view/sampleCustom/sampleCustom.js b/apps/patchpanel/src/main/resources/app/view/sampleCustom/sampleCustom.js
new file mode 100644
index 0000000..08902e3
--- /dev/null
+++ b/apps/patchpanel/src/main/resources/app/view/sampleCustom/sampleCustom.js
@@ -0,0 +1,122 @@
+// js for patch panel app custom view
+(function () {
+    'use strict';
+
+    // injected refs
+    var $log, $scope, wss, ks;
+
+    // constants
+    var dataReq = 'sampleCustomDataRequest',
+        dataResp = 'sampleCustomDataResponse';
+    var dataReq2 = 'sampleCustomDataRequest2',
+        dataResp2 = 'sampleCustomDataResponse2';
+    var dataReq3 = 'sampleCustomDataRequest3',
+        dataResp3 = 'sampleCustomDataResponse3';
+
+
+    function addKeyBindings() {
+        var map = {space: [getData, 'Fetch data from server'], _helpFormat: [['space']]};
+        ks.keyBindings(map);
+
+    }
+
+    function getData() {
+       wss.sendEvent(dataReq);
+    }
+    function used() {
+        wss.sendEvent(dataReq3);
+    }
+    function loadPorts(){
+        $scope.ports = [];
+        var i;
+        var index;
+        for(i = 0; i < $scope.cps.length ; i++){
+            if($scope.cps[i] == $scope.myDev){
+                index = i;
+            }
+        }
+        var j = index+1;
+        while( $scope.data.cps[j].indexOf("o") != 0){
+            var tempi = {name : $scope.data.cps[j]};
+            $scope.ports.push(tempi);
+            j++;
+        }
+    }
+    function done(){
+        var temp = [$scope.myDev.name, $scope.myPort1.name, $scope.myPort2.name];
+        var temp1 = {result : temp};
+        wss.sendEvent(dataReq2, temp1);
+
+    }
+    function respDataCb(data) {
+        $scope.data = data;
+        $scope.cps = [];
+        $scope.devices = [];
+        var i;
+        for(i = 0; i < $scope.data.cps.length; i++){
+            $scope.cps.push(temp);
+            if($scope.data.cps[i].indexOf("o") == 0){
+                var temp = {name : $scope.data.cps[i]};
+                $scope.devices.push(temp);
+            }
+        }
+        $scope.$apply();
+    }
+    function respDataCb2(data) {
+        $scope.data = data;
+        $scope.$apply();
+    }
+    function respDataCb3(data) {
+        $scope.data = data;
+        $scope.$apply();
+    }
+
+    var app = angular.module('ovSampleCustom', [])
+        .controller('OvSampleCustomCtrl',
+        ['$log', '$scope', 'WebSocketService', 'KeyService',
+
+        function (_$log_, _$scope_, _wss_, _ks_) {
+            $log = _$log_;
+            $scope = _$scope_;
+            wss = _wss_;
+            ks = _ks_;
+
+            $scope.cps = [];
+            $scope.devices = [];
+            $scope.ports = [];
+            $scope.myDev = $scope.devices[0];
+            $scope.myPort1 = $scope.ports[0];
+            $scope.myPort2 = $scope.ports[0];
+
+
+            var handlers = {};
+            $scope.data = {};
+            
+            // data response handler
+            handlers[dataResp] = respDataCb;
+            handlers[dataResp2] = respDataCb2;
+            handlers[dataResp3] = respDataCb3;
+            wss.bindHandlers(handlers);
+
+            addKeyBindings();
+
+            // custom click handler
+            $scope.getData = getData;
+            $scope.loadPorts = loadPorts;
+            $scope.used = used;
+            $scope.done = done;
+
+            // cleanup
+            $scope.$on('$destroy', function () {
+                wss.unbindHandlers(handlers);
+                ks.unbindKeys();
+                $log.log('OvSampleCustomCtrl has been destroyed');
+            });
+
+            $log.log('OvSampleCustomCtrl has been created');
+        }]);
+
+
+
+}());
+
diff --git a/apps/patchpanel/src/main/resources/sampleCustom/css.html b/apps/patchpanel/src/main/resources/sampleCustom/css.html
new file mode 100644
index 0000000..4e7b709
--- /dev/null
+++ b/apps/patchpanel/src/main/resources/sampleCustom/css.html
@@ -0,0 +1 @@
+<link rel="stylesheet" href="app/view/sampleCustom/sampleCustom.css">
\ No newline at end of file
diff --git a/apps/patchpanel/src/main/resources/sampleCustom/js.html b/apps/patchpanel/src/main/resources/sampleCustom/js.html
new file mode 100644
index 0000000..6550b85
--- /dev/null
+++ b/apps/patchpanel/src/main/resources/sampleCustom/js.html
@@ -0,0 +1 @@
+<script src="app/view/sampleCustom/sampleCustom.js"></script>
\ No newline at end of file
diff --git a/apps/pom.xml b/apps/pom.xml
index 1978f9d..13c2b39 100644
--- a/apps/pom.xml
+++ b/apps/pom.xml
@@ -60,6 +60,7 @@
         <module>pim</module>
         <module>mlb</module>
         <module>pathpainter</module>
+        <module>patchpanel</module>
         <module>drivermatrix</module>
         <module>cpman</module>
         <module>events</module>