Search in sources :

Example 1 with XmppDeviceId

use of org.onosproject.xmpp.core.XmppDeviceId in project onos by opennetworkinglab.

the class XmppControllerImplTest method setUp.

/**
 * Sets up devices to use as data, mocks and launches a controller instance.
 */
@Before
public void setUp() {
    device1 = new XmppDeviceAdapter();
    jid1 = new XmppDeviceId(new JID("agent1@testxmpp.org"));
    device2 = new XmppDeviceAdapter();
    jid2 = new XmppDeviceId(new JID("agent2@testxmpp.org"));
    device3 = new XmppDeviceAdapter();
    jid3 = new XmppDeviceId(new JID("agent3@testxmpp.org"));
    controller = new XmppControllerImpl();
    agent = controller.agent;
    testXmppDeviceListener = new TestXmppDeviceListener();
    controller.addXmppDeviceListener(testXmppDeviceListener);
    testXmppIqListener = new TestXmppIqListener();
    controller.addXmppIqListener(testXmppIqListener, testNamespace);
    testXmppMessageListener = new TestXmppMessageListener();
    controller.addXmppMessageListener(testXmppMessageListener);
    testXmppPresenceListener = new TestXmppPresenceListener();
    controller.addXmppPresenceListener(testXmppPresenceListener);
    CoreService mockCoreService = EasyMock.createMock(CoreService.class);
    controller.coreService = mockCoreService;
    ComponentConfigService mockCfgService = EasyMock.createMock(ComponentConfigService.class);
    expect(mockCfgService.getProperties(anyObject())).andReturn(ImmutableSet.of());
    mockCfgService.registerProperties(controller.getClass());
    expectLastCall();
    mockCfgService.unregisterProperties(controller.getClass(), false);
    expectLastCall();
    expect(mockCfgService.getProperties(anyObject())).andReturn(ImmutableSet.of());
    controller.cfgService = mockCfgService;
    replay(mockCfgService);
    ComponentContext mockContext = EasyMock.createMock(ComponentContext.class);
    Dictionary<String, Object> properties = new Hashtable<>();
    properties.put("xmppPort", "5269");
    expect(mockContext.getProperties()).andReturn(properties);
    replay(mockContext);
    controller.activate(mockContext);
}
Also used : ComponentConfigService(org.onosproject.cfg.ComponentConfigService) JID(org.xmpp.packet.JID) ComponentContext(org.osgi.service.component.ComponentContext) Hashtable(java.util.Hashtable) CoreService(org.onosproject.core.CoreService) XmppDeviceId(org.onosproject.xmpp.core.XmppDeviceId) Before(org.junit.Before)

Example 2 with XmppDeviceId

use of org.onosproject.xmpp.core.XmppDeviceId in project onos by opennetworkinglab.

the class XmppPubSubControllerImpl method asXmppDeviceId.

private XmppDeviceId asXmppDeviceId(DeviceId deviceId) {
    String[] parts = deviceId.toString().split(":");
    JID jid = new JID(parts[1]);
    return new XmppDeviceId(jid);
}
Also used : JID(org.xmpp.packet.JID) XmppDeviceId(org.onosproject.xmpp.core.XmppDeviceId)

Example 3 with XmppDeviceId

use of org.onosproject.xmpp.core.XmppDeviceId in project onos by opennetworkinglab.

the class XmppDeviceProvider method disconnectDevice.

private void disconnectDevice(XmppDeviceId xmppDeviceId) {
    Preconditions.checkNotNull(xmppDeviceId, IS_NULL_MSG);
    DeviceId deviceId = DeviceId.deviceId(xmppDeviceId.id());
    if (deviceService.getDevice(deviceId) != null) {
        providerService.deviceDisconnected(deviceId);
        logger.info("XMPP device {} removed from XMPP controller", deviceId);
    } else {
        logger.warn("XMPP device {} does not exist in the store, " + "or it may already have been removed", deviceId);
    }
}
Also used : XmppDeviceId(org.onosproject.xmpp.core.XmppDeviceId) DeviceId(org.onosproject.net.DeviceId)

Example 4 with XmppDeviceId

use of org.onosproject.xmpp.core.XmppDeviceId in project onos by opennetworkinglab.

the class XmppDeviceProvider method connectDevice.

private void connectDevice(XmppDeviceId xmppDeviceId) {
    DeviceId deviceId = DeviceId.deviceId(xmppDeviceId.id());
    String ipAddress = controller.getDevice(xmppDeviceId).getIpAddress().getAddress().getHostAddress();
    // Assumption: manufacturer is uniquely identified by domain part of JID
    String manufacturer = xmppDeviceId.getJid().getDomain();
    ChassisId cid = new ChassisId();
    SparseAnnotations annotations = DefaultAnnotations.builder().set(AnnotationKeys.PROTOCOL, XMPP.toUpperCase()).set("IpAddress", ipAddress).build();
    DeviceDescription deviceDescription = new DefaultDeviceDescription(deviceId.uri(), Device.Type.OTHER, manufacturer, HARDWARE_VERSION, SOFTWARE_VERSION, SERIAL_NUMBER, cid, true, annotations);
    if (deviceService.getDevice(deviceId) == null) {
        providerService.deviceConnected(deviceId, deviceDescription);
    }
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) ChassisId(org.onlab.packet.ChassisId) XmppDeviceId(org.onosproject.xmpp.core.XmppDeviceId) DeviceId(org.onosproject.net.DeviceId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 5 with XmppDeviceId

use of org.onosproject.xmpp.core.XmppDeviceId in project onos by opennetworkinglab.

the class XmppDeviceProvider method isReachable.

@Override
public boolean isReachable(DeviceId deviceId) {
    String id = deviceId.uri().getSchemeSpecificPart();
    JID jid = new JID(id);
    XmppDeviceId xmppDeviceId = new XmppDeviceId(jid);
    return controller.getDevice(xmppDeviceId) != null;
}
Also used : JID(org.xmpp.packet.JID) XmppDeviceId(org.onosproject.xmpp.core.XmppDeviceId)

Aggregations

XmppDeviceId (org.onosproject.xmpp.core.XmppDeviceId)7 JID (org.xmpp.packet.JID)3 DeviceId (org.onosproject.net.DeviceId)2 Hashtable (java.util.Hashtable)1 Before (org.junit.Before)1 ChassisId (org.onlab.packet.ChassisId)1 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)1 CoreService (org.onosproject.core.CoreService)1 SparseAnnotations (org.onosproject.net.SparseAnnotations)1 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)1 DeviceDescription (org.onosproject.net.device.DeviceDescription)1 ComponentContext (org.osgi.service.component.ComponentContext)1