Initial implementation of XMPP Publish/Subscribe

Change-Id: I9930056b83004fa7a085f72f63ba973f9ec2d95b
diff --git a/protocols/xmpp/pubsub/api/BUCK b/protocols/xmpp/pubsub/api/BUCK
new file mode 100644
index 0000000..d856754
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/BUCK
@@ -0,0 +1,9 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//core/api:onos-api',
+    '//lib:tinder-xmpp',
+]
+
+osgi_jar_with_tests (
+    deps = COMPILE_DEPS,
+)
\ No newline at end of file
diff --git a/protocols/xmpp/pubsub/api/pom.xml b/protocols/xmpp/pubsub/api/pom.xml
new file mode 100644
index 0000000..5357060
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/pom.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2018-present Open Networking Foundation
+  ~
+  ~ 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-protocols-xmpp-pubsub</artifactId>
+        <groupId>org.onosproject</groupId>
+        <version>1.13.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>onos-protocols-xmpp-pubsub-api</artifactId>
+    <dependencies>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-api</artifactId>
+        </dependency>
+    </dependencies>
+
+
+</project>
\ No newline at end of file
diff --git a/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppPubSubConstants.java b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppPubSubConstants.java
new file mode 100644
index 0000000..a705263
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppPubSubConstants.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.xmpp.pubsub;
+
+import com.google.common.collect.ImmutableMap;
+import org.xmpp.packet.PacketError;
+
+/**
+ * Constant values used across PubSub extension.
+ */
+public final class XmppPubSubConstants {
+
+    public static final String PUBSUB_NAMESPACE = "http://jabber.org/protocol/pubsub";
+    public static final String PUBSUB_EVENT_NS = "http://jabber.org/protocol/pubsub#event";
+    public static final String PUBSUB_ERROR_NS = "http://jabber.org/protocol/pubsub#errors";
+    public static final String PUBSUB_ELEMENT = "pubsub";
+    public static final ImmutableMap<PubSubApplicationCondition, PacketError.Condition>
+            APP_BASE_CONDITION_MAP = new ImmutableMap.Builder<PubSubApplicationCondition, PacketError.Condition>()
+            .put(PubSubApplicationCondition.ITEM_NOT_FOUND, PacketError.Condition.item_not_found)
+            .put(PubSubApplicationCondition.NOT_SUBSCRIBED, PacketError.Condition.unexpected_request)
+            .build();
+
+    public enum PubSubApplicationCondition {
+        NOT_SUBSCRIBED,
+        ITEM_NOT_FOUND
+    }
+
+    private XmppPubSubConstants() {
+    }
+
+    public enum Method {
+        SUBSCRIBE,
+        UNSUBSCRIBE,
+        PUBLISH,
+        RETRACT
+    }
+
+}
diff --git a/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppPubSubController.java b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppPubSubController.java
new file mode 100644
index 0000000..ee6e340
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppPubSubController.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.xmpp.pubsub;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.xmpp.pubsub.model.XmppEventNotification;
+import org.onosproject.xmpp.pubsub.model.XmppPubSubError;
+
+/**
+ * Responsible for controlling Publish/Subscribe functionality of XMPP.
+ */
+public interface XmppPubSubController {
+
+    /**
+     * Method allows to send event notification to XMPP device.
+     *
+     * @param deviceId identifier of underlaying device
+     * @param eventNotification payload of event notification
+     */
+    void notify(DeviceId deviceId, XmppEventNotification eventNotification);
+
+    /**
+     * Method allows to send error notification to XMPP device.
+     *
+     * @param deviceId identifier of underlaying device
+     * @param error payload of error notification
+     */
+    void notifyError(DeviceId deviceId, XmppPubSubError error);
+
+    /**
+     * Register listener for Publish/Retract events.
+     *
+     * @param xmppPublishEventsListener listener to notify
+     */
+    void addXmppPublishEventsListener(XmppPublishEventsListener xmppPublishEventsListener);
+
+    /**
+     * Unregister listener for Publish/Retract events.
+     *
+     * @param xmppPublishEventsListener listener to unregister
+     */
+    void removeXmppPublishEventsListener(XmppPublishEventsListener xmppPublishEventsListener);
+
+    /**
+     * Register listener for Subscribe/Unsubscribe events.
+     *
+     * @param xmppSubscribeEventsListener listener to notify
+     */
+    void addXmppSubscribeEventsListener(XmppSubscribeEventsListener xmppSubscribeEventsListener);
+
+    /**
+     * Unregister listener for Subscribe/Unsubscribe events.
+     *
+     * @param xmppSubscribeEventsListener listener to unregister
+     */
+    void removeXmppSubscribeEventsListener(XmppSubscribeEventsListener xmppSubscribeEventsListener);
+
+}
diff --git a/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppPubSubEvent.java b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppPubSubEvent.java
new file mode 100644
index 0000000..d4c3b76
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppPubSubEvent.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.xmpp.pubsub;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Abstracts event of XMPP Publish/Subscribe.
+ */
+public final class XmppPubSubEvent<S> {
+
+    /**
+     * Types of XMPP Publish/Subscribe messages.
+     */
+    public enum Type {
+        SUBSCRIBE,
+        UNSUBSCRIBE,
+        PUBLISH,
+        RETRACT
+    }
+
+    private final Type type;
+    private final S subject;
+
+    public XmppPubSubEvent(Type type, S subject) {
+        this.type = type;
+        this.subject = subject;
+    }
+
+    /**
+     * Returns the type of event.
+     *
+     * @return event type
+     */
+    public Type type() {
+        return type;
+    }
+
+    /**
+     * Returns the subject of event.
+     *
+     * @return subject to which this event pertains
+     */
+    public S subject() {
+        return subject;
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper(this).add("type", type())
+                .add("subject", subject()).toString();
+    }
+
+}
diff --git a/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppPublishEventsListener.java b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppPublishEventsListener.java
new file mode 100644
index 0000000..406b1d6
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppPublishEventsListener.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.xmpp.pubsub;
+
+import org.onosproject.xmpp.pubsub.model.XmppPublish;
+import org.onosproject.xmpp.pubsub.model.XmppRetract;
+
+/**
+ * Allows for providers interested in XMPP Publish/Retract events to be notified.
+ */
+public interface XmppPublishEventsListener {
+
+    /**
+     * Method for handling incoming XMPP Publish message.
+     *
+     * @param publishEvent event related to incoming XMPP Publish message
+     */
+    void handlePublish(XmppPublish publishEvent);
+
+    /**
+     * Method for handling incoming XMPP Retract message.
+     *
+     * @param retractEvent event related to incoming XMPP Retract message
+     */
+    void handleRetract(XmppRetract retractEvent);
+
+}
diff --git a/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppSubscribeEventsListener.java b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppSubscribeEventsListener.java
new file mode 100644
index 0000000..4a5d42d
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/XmppSubscribeEventsListener.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.xmpp.pubsub;
+
+import org.onosproject.xmpp.pubsub.model.XmppSubscribe;
+import org.onosproject.xmpp.pubsub.model.XmppUnsubscribe;
+
+/**
+ * Allows for providers interested in XMPP Subscribe/Unsubscribe events to be notified.
+ */
+public interface XmppSubscribeEventsListener {
+
+    /**
+     * Method for handling incoming XMPP Subscribe message.
+     *
+     * @param subscribeEvent event related to incoming XMPP Subscribe message
+     */
+    void handleSubscribe(XmppSubscribe subscribeEvent);
+
+    /**
+     * Method for handling incoming XMPP Unsubscribe message.
+     *
+     * @param unsubscribeEvent event related to incoming XMPP Unsubscribe message
+     */
+    void handleUnsubscribe(XmppUnsubscribe unsubscribeEvent);
+
+}
diff --git a/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppEventNotification.java b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppEventNotification.java
new file mode 100644
index 0000000..a4e64b7
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppEventNotification.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.xmpp.pubsub.model;
+
+import org.dom4j.Element;
+import org.xmpp.packet.Message;
+
+import static org.onosproject.xmpp.pubsub.XmppPubSubConstants.PUBSUB_EVENT_NS;
+
+/**
+ * Abstracts Event Notification message of XMPP PubSub protocol.
+ */
+public class XmppEventNotification extends Message {
+
+    /**
+     * Constructor for XmppEventNotification class. It generates representation
+     * of XMPP NOTIFY message.
+     *
+     * @param node node attribute of PubSub extension
+     * @param payload XML payload for XMPP NOTIFY message
+     */
+    public XmppEventNotification(String node, Element payload) {
+        super(docFactory.createDocument().addElement("message"));
+        this.addChildElement("event", PUBSUB_EVENT_NS);
+        Element items = docFactory.createElement("items");
+        items.addAttribute("node", node);
+        items.add(payload);
+        this.getElement().element("event").add(items);
+    }
+
+}
diff --git a/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppPubSubError.java b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppPubSubError.java
new file mode 100644
index 0000000..dcf60d2
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppPubSubError.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.xmpp.pubsub.model;
+
+import org.xmpp.packet.PacketError;
+import static org.onosproject.xmpp.pubsub.XmppPubSubConstants.APP_BASE_CONDITION_MAP;
+import static org.onosproject.xmpp.pubsub.XmppPubSubConstants.PUBSUB_ERROR_NS;
+import static org.onosproject.xmpp.pubsub.XmppPubSubConstants.PubSubApplicationCondition;
+
+/**
+ * Abstracts Publish/Subscribe error message of XMPP PubSub protocol.
+ */
+public class XmppPubSubError {
+
+    private PacketError.Condition baseCondition;
+    private PubSubApplicationCondition applicationCondition;
+
+    public XmppPubSubError(PubSubApplicationCondition applicationCondition) {
+        this.applicationCondition = applicationCondition;
+        this.baseCondition = setBasedOnAppCondition();
+    }
+
+    private PacketError.Condition setBasedOnAppCondition() {
+        return APP_BASE_CONDITION_MAP.getOrDefault(this.applicationCondition,
+                                                   PacketError.Condition.undefined_condition);
+    }
+
+    public PacketError asPacketError() {
+        PacketError packetError = new PacketError(this.baseCondition);
+        if (applicationCondition != null) {
+            packetError.setApplicationCondition(applicationCondition.toString().toLowerCase(),
+                                                PUBSUB_ERROR_NS);
+        }
+        return packetError;
+    }
+
+}
diff --git a/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppPublish.java b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppPublish.java
new file mode 100644
index 0000000..97dc2a7
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppPublish.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.xmpp.pubsub.model;
+
+import org.dom4j.Element;
+import org.xmpp.packet.IQ;
+
+/**
+ * Abstracts Publish message of XMPP PubSub protocol.
+ */
+public class XmppPublish extends IQ {
+
+    private String jabberId;
+    private String nodeID;
+    private Element item;
+    private String itemID;
+    private Element itemEntry;
+    private String itemEntryNamespace;
+
+    /**
+     * Constructor for XmppPublish class.
+     * @param iq XMPP IQ stanza, which XmppPublish is based on.
+     */
+    public XmppPublish(IQ iq) {
+        super(iq.getElement());
+        this.jabberId = this.fromJID.toString();
+        this.nodeID = this.getChildElement().element("publish").attribute("node").getValue();
+        this.item = this.getChildElement().element("publish").element("item");
+        this.itemID = this.item.attribute("id").getValue();
+        this.itemEntry = this.item.element("entry");
+        this.itemEntryNamespace = this.itemEntry.getNamespaceURI();
+    }
+
+    public String getJabberId() {
+        return this.jabberId;
+    }
+
+    public String getNodeID() {
+        return this.nodeID;
+    }
+
+    public Element getItem() {
+        return this.item;
+    }
+
+    public String getItemID() {
+        return this.itemID;
+    }
+
+    public Element getItemEntry() {
+        return this.itemEntry;
+    }
+
+    public String getItemEntryNamespace() {
+        return this.itemEntryNamespace;
+    }
+
+    @Override
+    public String toString() {
+        return "Publish{" +
+                "JID=" + fromJID +
+                "NodeID=" + this.getNodeID() +
+                "Item=\n" + this.getItem().asXML() +
+                '}';
+    }
+
+}
diff --git a/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppRetract.java b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppRetract.java
new file mode 100644
index 0000000..83308dd
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppRetract.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.xmpp.pubsub.model;
+
+import org.xmpp.packet.IQ;
+
+/**
+ * Abstracts Retract message of XMPP PubSub protocol.
+ */
+public class XmppRetract extends IQ {
+
+    private String jabberId;
+    private String nodeID;
+    private String itemID;
+
+    /**
+     * Constructor for XmppRetract class.
+     *
+     * @param iq XMPP IQ stanza, which XmppRetract is based on.
+     */
+    public XmppRetract(IQ iq)  {
+        super(iq.getElement());
+        this.jabberId = this.fromJID.toString();
+        this.nodeID = this.getChildElement().element("retract").attribute("node").getValue();
+        this.itemID = this.getChildElement().element("retract").element("item").attribute("id").getValue();
+    }
+
+    public String getJabberId() {
+        return this.jabberId;
+    }
+
+    public String getNodeID() {
+        return this.nodeID;
+    }
+
+    public String getItemID() {
+        return this.itemID;
+    }
+
+}
diff --git a/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppSubscribe.java b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppSubscribe.java
new file mode 100644
index 0000000..c3040d5
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppSubscribe.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.xmpp.pubsub.model;
+
+import org.xmpp.packet.IQ;
+
+/**
+ * Abstracts Subscribe message of XMPP PubSub protocol.
+ */
+public class XmppSubscribe extends IQ {
+
+    private String jabberId;
+    private String nodeID;
+
+    /**
+     * Constructor for XmppSubscribe class.
+     *
+     * @param iq XMPP IQ stanza, which XmppSubscribe is based on.
+     */
+    public XmppSubscribe(IQ iq)  {
+        super(iq.getElement());
+        this.jabberId = this.fromJID.toString();
+        this.nodeID = this.getChildElement().element("subscribe").attribute("node").getValue();
+    }
+
+    public String getJabberId() {
+        return this.jabberId;
+    }
+
+    public String getNodeID() {
+        return this.nodeID;
+    }
+
+}
diff --git a/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppUnsubscribe.java b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppUnsubscribe.java
new file mode 100644
index 0000000..a256c61
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/XmppUnsubscribe.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.xmpp.pubsub.model;
+
+import org.xmpp.packet.IQ;
+
+/**
+ * Abstracts Unsubscribe message of XMPP PubSub protocol.
+ */
+public class XmppUnsubscribe extends IQ {
+
+    private String jabberId;
+    private String nodeID;
+
+    /**
+     * Constructor for XmppUnsubscribe class.
+     *
+     * @param iq XMPP IQ stanza, which XmppUnsubscribe is based on.
+     */
+    public XmppUnsubscribe(IQ iq)  {
+        super(iq.getElement());
+        this.jabberId = this.fromJID.toString();
+        this.nodeID = this.getChildElement().element("unsubscribe").attribute("node").getValue();
+    }
+
+    public String getJabberId() {
+        return this.jabberId;
+    }
+
+    public String getNodeID() {
+        return this.nodeID;
+    }
+
+}
diff --git a/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/package-info.java b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/package-info.java
new file mode 100644
index 0000000..4196048
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/model/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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 for implementation of XMPP Publish/Subscribe abstractions.
+ */
+package org.onosproject.xmpp.pubsub.model;
\ No newline at end of file
diff --git a/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/package-info.java b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/package-info.java
new file mode 100644
index 0000000..4021f65
--- /dev/null
+++ b/protocols/xmpp/pubsub/api/src/main/java/org/onosproject/xmpp/pubsub/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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 for implementation of XMPP Publish/Subscribe APIs.
+ */
+package org.onosproject.xmpp.pubsub;
\ No newline at end of file