XMPP as SBI support: implementation of core XMPP and Xmpp Device Provider
State machine handled by XmppSession interface, most of tests implemented
XmppDeviceFactory re-designed, tests updated
pom and BUCK files updated
Change-Id: I4c6955e091169c945415084cbb000c61b474c0fc
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppConstants.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppConstants.java
new file mode 100644
index 0000000..0904299
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppConstants.java
@@ -0,0 +1,32 @@
+/*
+ * 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.core;
+
+/*
+ * Stores XMPP protocol constant parameters.
+ */
+public final class XmppConstants {
+
+ private XmppConstants() {}
+
+ public static final String IQ_QNAME = "iq";
+ public static final String PRESENCE_QNAME = "presence";
+ public static final String MESSAGE_QNAME = "message";
+ public static final String STREAM_QNAME = "stream";
+ public static final String SERVER_JID = "xmpp.onosproject.org";
+
+}
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppController.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppController.java
new file mode 100644
index 0000000..8b500a3
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppController.java
@@ -0,0 +1,90 @@
+/*
+ * 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.core;
+
+/**
+ * Abstraction of a XMPP controller. Serves as a one stop
+ * shop for obtaining XMPP devices and (un)register listeners
+ * on XMPP events
+ */
+public interface XmppController {
+
+ /**
+ * Method allows to retrieve XMPP device for given XmppDeviceId, if one exists.
+ *
+ * @param xmppDeviceId the device to retrieve
+ * @return the interface to XMPP Device
+ */
+ XmppDevice getDevice(XmppDeviceId xmppDeviceId);
+
+ /**
+ * Register a listener for device events.
+ *
+ * @param deviceListener the listener to notify
+ */
+ void addXmppDeviceListener(XmppDeviceListener deviceListener);
+
+ /**
+ * Unregister a listener for device events.
+ *
+ * @param deviceListener the listener to unregister
+ */
+ void removeXmppDeviceListener(XmppDeviceListener deviceListener);
+
+ /**
+ * Register a listener for IQ stanza of XMPP protocol.
+ *
+ * @param iqListener the listener to notify
+ */
+ void addXmppIqListener(XmppIqListener iqListener);
+
+ /**
+ * Unregister a listener for IQ stanza of XMPP protocol.
+ *
+ * @param iqListener the listener to unregister
+ */
+ void removeXmppIqListener(XmppIqListener iqListener);
+
+ /**
+ * Register a listener for Message stanza of XMPP protocol.
+ *
+ * @param messageListener the listener to notify
+ */
+ void addXmppMessageListener(XmppMessageListener messageListener);
+
+ /**
+ * Unregister a listener for Message stanza of XMPP protocol.
+ *
+ * @param messageListener the listener to unregister
+ */
+ void removeXmppMessageListener(XmppMessageListener messageListener);
+
+ /**
+ * Register a listener for Presence stanza of XMPP protocol.
+ *
+ * @param presenceListener the listener to notify
+ */
+ void addXmppPresenceListener(XmppPresenceListener presenceListener);
+
+ /**
+ * Unregister a listener for Presence stanza of XMPP protocol.
+ *
+ * @param presenceListener the listener to unregister
+ */
+ void removeXmppPresenceListener(XmppPresenceListener presenceListener);
+
+}
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDevice.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDevice.java
new file mode 100644
index 0000000..93a6cd7
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDevice.java
@@ -0,0 +1,85 @@
+/*
+ * 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.core;
+
+import org.dom4j.Document;
+import org.xmpp.packet.Packet;
+import org.xmpp.packet.PacketError;
+
+import java.net.InetSocketAddress;
+
+
+/**
+ * Abstracts XMPP device.
+ */
+public interface XmppDevice {
+
+ /**
+ * Returns an associated Netty channel for device.
+ *
+ * @return Netty Socket Channel
+ */
+ XmppSession getSession();
+
+ /**
+ * Returns an IP address of underlaying XMPP device/client.
+ *
+ * @return IP address
+ */
+ InetSocketAddress getIpAddress();
+
+ /**
+ * Register a device that has just connected to the system.
+ *
+ */
+ void registerConnectedDevice();
+
+ /**
+ * Disconnects the device by closing the TCP connection and unregistering device.
+ *
+ */
+ void disconnectDevice();
+
+
+ /**
+ * Sends a XMPP packet to the client.
+ *
+ * @param packet the XMPP packet to send
+ */
+ void sendPacket(Packet packet);
+
+ /**
+ * Method for sending raw XML data as XMPP packet.
+ *
+ * @param document the XML data
+ */
+ void writeRawXml(Document document);
+
+ /**
+ * Handle a XMPP packet from device.
+ *
+ * @param packet the XMPP packet
+ */
+ void handlePacket(Packet packet);
+
+ /**
+ * Sends a XMPP error to client.
+ *
+ * @param packetError XMPP error message
+ */
+ void sendError(PacketError packetError);
+}
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDeviceAgent.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDeviceAgent.java
new file mode 100644
index 0000000..fa4fcfd
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDeviceAgent.java
@@ -0,0 +1,59 @@
+/*
+ * 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.core;
+
+import org.xmpp.packet.Packet;
+
+/**
+ * Responsible for keeping track of the current set of devices
+ * connected to the system. As well as notifying Xmpp Stanza listeners.
+ *
+ */
+public interface XmppDeviceAgent {
+
+ /**
+ * Add a device that has just connected to the system.
+ * @param deviceId the identifier of device to add.
+ * @param device the actual device object.
+ * @return true if added, false otherwise.
+ */
+ boolean addConnectedDevice(XmppDeviceId deviceId, XmppDevice device);
+
+ /**
+ * Remove a device from a local repository that has been disconnected
+ * from the local controller. Notify device listeners.
+ * @param deviceId the identifier of device to remove.
+ */
+ void removeConnectedDevice(XmppDeviceId deviceId);
+
+ /**
+ * Returns XMPP device object that is stored in the local repository
+ * containing already connected devices.
+ * @param deviceId the identifier of device
+ * @return the XMPP device object
+ */
+ XmppDevice getDevice(XmppDeviceId deviceId);
+
+ /**
+ * Process an event (incoming Packet) coming from a device.
+ * @param deviceId the identifier of device the packet came on.
+ * @param packet the packet to process
+ */
+ void processUpstreamEvent(XmppDeviceId deviceId, Packet packet);
+
+}
+
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDeviceFactory.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDeviceFactory.java
new file mode 100644
index 0000000..42ebd20
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDeviceFactory.java
@@ -0,0 +1,36 @@
+/*
+ * 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.core;
+
+import org.xmpp.packet.JID;
+
+/**
+ * Interface for creating new XMPP devices.
+ */
+public interface XmppDeviceFactory {
+
+
+ /**
+ * Creates instance of XMPP device.
+ *
+ * @param jabberId Jabber ID identifying XMPP device
+ * @param session session associated with XMPP device
+ * @return XMPP device
+ */
+ public XmppDevice getXmppDevice(JID jabberId, XmppSession session);
+
+}
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDeviceId.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDeviceId.java
new file mode 100644
index 0000000..41225ea
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDeviceId.java
@@ -0,0 +1,71 @@
+/*
+ * 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.core;
+
+import org.onlab.util.Identifier;
+import org.onosproject.net.DeviceId;
+import org.xmpp.packet.JID;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+/**
+ * The class representing a network device identifier.
+ * This class is immutable.
+ */
+public final class XmppDeviceId extends Identifier<String> {
+
+ private static final String SCHEME = "xmpp";
+
+ private JID jid;
+
+ public XmppDeviceId(JID jid) {
+ super(uri(jid.toString()).toString());
+ this.jid = jid;
+ }
+
+ @Override
+ public String toString() {
+ return identifier.toString();
+ }
+
+ public JID getJid() {
+ return jid;
+ }
+
+ public static URI uri(String string) {
+ try {
+ return new URI(SCHEME, string, null);
+ } catch (URISyntaxException e) {
+ return null;
+ }
+ }
+
+ public static DeviceId asDeviceId(JID jid) {
+ return DeviceId.deviceId(XmppDeviceId.uri(jid));
+ }
+
+ public static URI uri(JID jid) {
+ try {
+ return new URI(SCHEME, jid.toString(), null);
+ } catch (URISyntaxException e) {
+ return null;
+ }
+ }
+
+
+}
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDeviceListener.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDeviceListener.java
new file mode 100644
index 0000000..7fa6eda
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppDeviceListener.java
@@ -0,0 +1,38 @@
+/*
+ * 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.core;
+
+/**
+ * Allows for providers interested in XMPP device events to be notified.
+ */
+public interface XmppDeviceListener {
+
+ /**
+ * Notify that the device was added.
+ *
+ * @param deviceId identifier of the device where the event occurred
+ */
+ void deviceConnected(XmppDeviceId deviceId);
+
+ /**
+ * Notify that the device was removed.
+ *
+ * @param deviceId identifier of the device where the event occurred
+ */
+ void deviceDisconnected(XmppDeviceId deviceId);
+
+}
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppIqListener.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppIqListener.java
new file mode 100644
index 0000000..046bfb1
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppIqListener.java
@@ -0,0 +1,33 @@
+/*
+ * 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.core;
+
+import org.xmpp.packet.IQ;
+
+/**
+ * Allows for Providers interested in XMPP IQ stanzas to be notified.
+ */
+public interface XmppIqListener {
+
+ /**
+ * Handles incoming IQ stanzas.
+ *
+ * @param iq IQ stanza to handle
+ */
+ void handleIqStanza(IQ iq);
+
+}
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppMessageListener.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppMessageListener.java
new file mode 100644
index 0000000..67aa245
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppMessageListener.java
@@ -0,0 +1,34 @@
+/*
+ * 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.core;
+
+import org.xmpp.packet.Message;
+
+
+/**
+ * Allows for providers interested in XMPP Message stanzas to be notified.
+ */
+public interface XmppMessageListener {
+
+ /**
+ * Handles incoming Message stanzas.
+ *
+ * @param message Message stanza to handle
+ */
+ void handleMessageStanza(Message message);
+
+}
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppPresenceListener.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppPresenceListener.java
new file mode 100644
index 0000000..3c1ae3d
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppPresenceListener.java
@@ -0,0 +1,33 @@
+/*
+ * 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.core;
+
+import org.xmpp.packet.Presence;
+
+/**
+ * Allows for providers interested in XMPP Presence stanzas to be notified.
+ */
+public interface XmppPresenceListener {
+
+ /**
+ * Handles incoming Presence stanzas.
+ *
+ * @param presence Presence stanza to handle
+ */
+ void handlePresenceStanza(Presence presence);
+
+}
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppSession.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppSession.java
new file mode 100644
index 0000000..1d4a714
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/XmppSession.java
@@ -0,0 +1,55 @@
+/*
+ * 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.core;
+
+import org.xmpp.packet.Packet;
+
+import java.net.InetSocketAddress;
+
+/**
+ * Represents XMPP session.
+ */
+public interface XmppSession {
+
+ /**
+ * Returns session state.
+ *
+ * @return true if active.
+ */
+ boolean isActive();
+
+ /**
+ * Returns address of remote client.
+ *
+ * @return socket address
+ */
+ InetSocketAddress remoteAddress();
+
+ /**
+ * Requests to close this XMPP session.
+ */
+ void closeSession();
+
+ /**
+ * Sends XMPP packet over the session.
+ *
+ * @param xmppPacket to send
+ * @return true if packet was sent
+ */
+ boolean sendPacket(Packet xmppPacket);
+
+}
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/package-info.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/package-info.java
new file mode 100644
index 0000000..fcd5910
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/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 APIs.
+ */
+package org.onosproject.xmpp.core;
\ No newline at end of file
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/XmppStreamClose.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/XmppStreamClose.java
new file mode 100644
index 0000000..38fc451
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/XmppStreamClose.java
@@ -0,0 +1,28 @@
+/*
+ * 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.core.stream;
+
+/**
+ * Abstracts XMPP stream close event.
+ */
+public class XmppStreamClose implements XmppStreamEvent {
+
+ @Override
+ public String toXml() {
+ return "</stream:stream>";
+ }
+}
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/XmppStreamError.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/XmppStreamError.java
new file mode 100644
index 0000000..c96e8f1
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/XmppStreamError.java
@@ -0,0 +1,35 @@
+/*
+ * 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.core.stream;
+
+import org.xmpp.packet.StreamError;
+
+/**
+ * Abstracts XMPP stream error event.
+ */
+public class XmppStreamError extends StreamError implements XmppStreamEvent {
+
+ public XmppStreamError(Condition condition) {
+ super(condition);
+ }
+
+ @Override
+ public String toXml() {
+ return super.toXML();
+ }
+
+}
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/XmppStreamEvent.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/XmppStreamEvent.java
new file mode 100644
index 0000000..5fc67d3
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/XmppStreamEvent.java
@@ -0,0 +1,30 @@
+/*
+ * 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.core.stream;
+
+/**
+ * Abstracts XMPP Stream events such as Close, Open or Error event.
+ */
+public interface XmppStreamEvent {
+
+ /**
+ * Represent XMPP Stream Event as XML element.
+ * @return the XML element.
+ */
+ String toXml();
+
+}
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/XmppStreamOpen.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/XmppStreamOpen.java
new file mode 100644
index 0000000..967296b
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/XmppStreamOpen.java
@@ -0,0 +1,75 @@
+/*
+ * 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.core.stream;
+
+import org.dom4j.Attribute;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.XMLWriter;
+import org.xmpp.packet.JID;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.List;
+
+/**
+ * Abstracts XMPP stream open event.
+ */
+public class XmppStreamOpen implements XmppStreamEvent {
+
+ public static final String QNAME = "stream";
+
+ private Element element;
+
+ public XmppStreamOpen(Element element) {
+ this.element = element;
+ }
+
+ @Override
+ public String toXml() {
+ StringWriter out = new StringWriter();
+ XMLWriter writer = new XMLWriter(out, OutputFormat.createCompactFormat());
+ try {
+ out.write("<");
+ writer.write(element.getQualifiedName());
+ for (Attribute attr : (List<Attribute>) element.attributes()) {
+ writer.write(attr);
+ }
+ writer.write(Namespace.get(this.element.getNamespacePrefix(), this.element.getNamespaceURI()));
+ writer.write(Namespace.get("jabber:client"));
+ out.write(">");
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ return out.toString();
+ }
+
+ public JID getFromJid() {
+ String jid = this.element.attribute("from").getValue();
+ return new JID(jid);
+ }
+
+ public Element getElement() {
+ return this.element;
+ }
+
+ public JID getToJid() {
+ String jid = this.element.attribute("to").getValue();
+ return new JID(jid);
+ }
+}
diff --git a/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/package-info.java b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/package-info.java
new file mode 100644
index 0000000..38510fa
--- /dev/null
+++ b/protocols/xmpp/core/api/src/main/java/org/onosproject/xmpp/core/stream/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 fo XMPP Stream abstractions.
+ */
+package org.onosproject.xmpp.core.stream;
\ No newline at end of file