messages.py 65.2 KB
Newer Older
1 2 3
# -*- coding: utf-8 -*-

"""
4 5 6 7

About the library:
-----------------

8 9 10 11 12 13 14 15 16
This module provides the API message formats used in F-Interop.

The idea is to be able to have an
- organized and centralized way of dealing with the big amount of messages formats used in the platform;
- to be able to import (or just copy/paste) these messages formats from any component in the F-Interop platform,
- re-use this also for the integration testing;
- to have version control the messages e.g. messages_testcase_start API v1 and API v2;
- to have a direct way of exporting this as doc.

17 18 19 20 21 22 23 24

F-Interop conventions:
---------------------
- if event is a service request then the routing key (r_key) is control.someFunctionality.service
- a reply to a service will be on topic/r_key : control.someFunctionality.service.reply
- reply.correlation_id = request.correlation_id


25 26
Usage:
------
27
>>> from messages import * # doctest: +SKIP
Federico Sismondi's avatar
Federico Sismondi committed
28
>>> m = MsgTestCaseSkip(testcase_id = 'some_testcase_id')
29
>>> m
30
MsgTestCaseSkip(_api_version = 0.1.48, _type = testcoordination.testcase.skip, description = Skip testcase, node = someNode, testcase_id = some_testcase_id, )
31 32
>>> m.routing_key
'control.testcoordination'
33 34
>>> m.message_id # doctest: +SKIP
'802012eb-24e3-45c4-9dcc-dc293c584f63'
35
>>> m.testcase_id
Federico Sismondi's avatar
Federico Sismondi committed
36
'some_testcase_id'
37

38
# also we can modify some of the fields (rewrite the default ones)
Federico Sismondi's avatar
Federico Sismondi committed
39
>>> m = MsgTestCaseSkip(testcase_id = 'TD_COAP_CORE_03')
40
>>> m
41
MsgTestCaseSkip(_api_version = 0.1.48, _type = testcoordination.testcase.skip, description = Skip testcase, node = someNode, testcase_id = TD_COAP_CORE_03, )
42
>>> m.testcase_id
Federico Sismondi's avatar
Federico Sismondi committed
43
'TD_COAP_CORE_03'
44

45 46
# and even export the message in json format (for example for sending the message though the amqp event bus)
>>> m.to_json()
47
'{"_api_version": "0.1.48", "_type": "testcoordination.testcase.skip", "description": "Skip testcase", "node": "someNode", "testcase_id": "TD_COAP_CORE_03"}'
Federico Sismondi's avatar
Federico Sismondi committed
48

49
# We can use the Message class to import json into Message objects:
Federico Sismondi's avatar
Federico Sismondi committed
50 51
>>> m=MsgTestSuiteStart()
>>> m.to_json()
52
'{"_api_version": "0.1.48", "_type": "testcoordination.testsuite.start", "description": "Event test suite START"}'
Federico Sismondi's avatar
Federico Sismondi committed
53 54 55
>>> json_message = m.to_json()
>>> obj=Message.from_json(json_message)
>>> type(obj)
56
<class 'messages.MsgTestSuiteStart'>
57

58
# We can use the library for generating error responses:
59 60 61 62 63 64
# the request:
>>> m = MsgSniffingStart()
>>>
# the error reply (note that we pass the message of the request to build the reply):
>>> err = MsgErrorReply(m)
>>> err
65
MsgErrorReply(_api_version = 0.1.48, _type = sniffing.start, error_code = Some error code TBD, error_message = Some error message TBD, ok = False, )
66 67 68 69 70 71 72 73 74
>>> m.reply_to
'control.sniffing.service.reply'
>>> err.routing_key
'control.sniffing.service.reply'

>>> m.correlation_id # doctest: +SKIP
'360b0f67-4455-43e3-a00f-eca91f2e84da'
>>> err.correlation_id # doctest: +SKIP
'360b0f67-4455-43e3-a00f-eca91f2e84da'
Federico Sismondi's avatar
Federico Sismondi committed
75

76 77 78
"""

from collections import OrderedDict
79
import time
80 81 82
import json
import uuid

83
API_VERSION = '0.1.48'
84

85 86 87 88 89 90 91 92 93 94

# TODO use metaclasses instead?
class NonCompliantMessageFormatError(Exception):
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return repr(self.value)


95 96
class Message:
    def __init__(self, **kwargs):
97 98 99
        global API_VERSION

        # hard copy the message template
100
        self._msg_data = {k: v for k, v in self._msg_data_template.items()}
101

102 103
        # init properties
        self._properties = dict(
104 105 106
            content_type="application/json",
            message_id=str(uuid.uuid4()),
            timestamp=int(time.time())
107 108
        )

109
        try:
110 111 112
            if self.routing_key.endswith(".service"):
                self._properties["reply_to"] = "%s.%s" % (self.routing_key, "reply")
                self._properties["correlation_id"] = self._properties["message_id"]
113
        except AttributeError:
114
            pass
115

116
        # rewrite default data fields with the passed args
117 118 119
        self._msg_data.update(kwargs)

        # add API's version
120 121
        if not "_api_version" in self._msg_data:
            self._msg_data["_api_version"] = API_VERSION
122 123 124 125 126

        # add values as objects attributes
        for key in self._msg_data:
            setattr(self, key, self._msg_data[key])

127 128 129 130
        # add props as objects attributes
        for key in self._properties:
            setattr(self, key, self._properties[key])

131 132
    def to_dict(self):
        resp = {}
133 134
        # let's use sorted so API returns items inside always in the same order
        for field in sorted(self._msg_data.keys()):
135
            resp[field] = getattr(self, field)
136

137
        return OrderedDict(sorted(resp.items(), key=lambda t: t[0]))  # sorted by key
138 139 140 141

    def to_json(self):
        return json.dumps(self.to_dict())

142
    def get_properties(self):
143 144 145 146
        resp = OrderedDict()
        for field in self._properties:
            resp[field] = getattr(self, field)
        return resp
147

148
    def __str__(self):
149 150 151 152 153 154 155
        s = " - " * 20 + "\n"
        s += "Message routing key: %s" % self.routing_key
        s += "\n -  -  - \n"
        s += "Message properties: %s" % json.dumps(self.get_properties(), indent=4, )
        s += "\n -  -  - \n"
        s += "Message body: %s" % json.dumps(self.to_dict(), indent=4, )
        s += "\n" + " - " * 20
156
        return s
157

158 159 160 161 162
    def update_properties(self, **kwargs):
        for key, value in kwargs.items():
            if key in self._properties:
                setattr(self, key, value)

163 164
    @classmethod
    def from_json(cls, body):
165 166 167 168 169 170 171 172 173 174
        """
        :param body: json string or string encoded as utf-8
        :return:  Message object generated from the body
        :raises NonCompliantMessageFormatError: If the message cannot be build from the provided json
        """

        if type(body) is str:
            message_dict = json.loads(body)
        # Note: pika re-encodes json.dumps strings as utf-8 for some reason, the following line undoes this
        elif type(body) is bytes:
175
            message_dict = json.loads(body.decode("utf-8"))
176
        else:
177
            raise NonCompliantMessageFormatError("Not a Json")
178

179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
        # check fist if it's a response
        if "ok" in message_dict:
            # cannot build a complete reply message just from the json representation
            return

        return cls.from_dict(message_dict)

    @classmethod
    def from_dict(cls, message_dict):
        """
        :param body: dict
        :return:  Message object generated from the body
        :raises NonCompliantMessageFormatError: If the message cannot be build from the provided json
        """
        assert type(message_dict) is dict

195
        # check fist if it's a response
196
        if "ok" in message_dict:
197
            # cannot build a complete reply message just from the json representation
198
            return
199

200
        message_type = message_dict["_type"]
201

202 203 204
        if message_type in message_types_dict:
            return message_types_dict[message_type](**message_dict)
        else:
205 206
            raise NonCompliantMessageFormatError("Cannot load json message: %s" % str(message_dict))

207
    def __repr__(self):
208
        ret = "%s(" % self.__class__.__name__
209
        for key, value in self.to_dict().items():
210 211
            ret += "%s = %s, " % (key, value)
        ret += ")"
212 213
        return ret

214

215 216 217 218 219
class MsgReply(Message):
    """
    Auxiliary class which creates replies messages with fields based on the request.
    Routing key, corr_id and _type are generated based on the request message
    """
220

221 222 223 224 225 226 227
    def __init__(self, request_message, **kwargs):
        assert request_message

        self.routing_key = request_message.routing_key + ".reply"

        # if not data template, then let's build one for a reply
        # (possible when creating a MsgReply directly and not by using subclass)
228
        if not hasattr(self, "_msg_data_template"):
229
            self._msg_data_template = {
230
                "_type": request_message._type,
231
                "ok": True,
232 233
            }

234
        super(MsgReply, self).__init__(**kwargs)
235

236
        # overwrite correlation id template and attribute
237
        self._properties["correlation_id"] = request_message.correlation_id
238 239 240 241 242
        self.correlation_id = request_message.correlation_id


class MsgErrorReply(MsgReply):
    """
243
    see section "F-Interop conventions" on top
244
    """
245

246 247
    def __init__(self, request_message, **kwargs):
        assert request_message
248
        # msg_data_template doesnt include _type cause this class is generic, we can only get this at init from request
249
        # so, let's copy the _type from request and let the MsgReply handle the rest of the fields
250
        self._msg_data_template["_type"] = request_message._type
251
        super(MsgErrorReply, self).__init__(request_message, **kwargs)
252 253

    _msg_data_template = {
254
        "ok": False,
255
        "error_message": "Some error message TBD",
256
        "error_code": "Some error code TBD"
257 258
    }

259 260

# # # # # # AGENT MESSAGES # # # # # #
Federico Sismondi's avatar
Federico Sismondi committed
261 262 263

class MsgAgentTunStart(Message):
    """
264
    Requirements: Testing Tool MAY implement (if IP tun needed)
Federico Sismondi's avatar
Federico Sismondi committed
265

266
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
267

268
    Pub/Sub: Testing Tool -> Agent
Federico Sismondi's avatar
Federico Sismondi committed
269

270
    Description: Message for triggering start IP tun interface in OS where the agent is running
Federico Sismondi's avatar
Federico Sismondi committed
271
    """
272
    routing_key = "control.tun.toAgent.agent_TT"
Federico Sismondi's avatar
Federico Sismondi committed
273 274

    _msg_data_template = {
275 276 277 278
        "_type": "tun.start",
        "name": "agent_TT",
        "ipv6_prefix": "bbbb",
        "ipv6_host": ":3",
279
        "ipv6_no_forwarding": False,
280 281 282
        "ipv4_host": None,
        "ipv4_network": None,
        "ipv4_netmask": None,
Federico Sismondi's avatar
Federico Sismondi committed
283 284 285
    }


286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
class MsgAgentSerialStarted(Message):
    """
    Description: Message for indicating that agent serial interface has been started

    Type: Event

    Pub/Sub: Testing Tool -> Agent

    Description: TBD
    """
    routing_key = "control.serial.from.tbd"

    _msg_data_template = {
        "_type": "serial.started",
        "name": "tbd",
        "port": "tbd",
        "boudrate": "tbd",
    }


Federico Sismondi's avatar
Federico Sismondi committed
306 307
class MsgAgentTunStarted(Message):
    """
308
    Description: Message for indicating that agent tun has been started
Federico Sismondi's avatar
Federico Sismondi committed
309

310
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
311

312
    Pub/Sub: Agent -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
313

314
    Description: TBD
Federico Sismondi's avatar
Federico Sismondi committed
315
    """
316
    routing_key = "control.tun.from.tbd"
Federico Sismondi's avatar
Federico Sismondi committed
317 318

    _msg_data_template = {
319 320 321 322 323 324 325
        "_type": "tun.started",
        "name": "agent_TT",
        "ipv6_prefix": "bbbb",
        "ipv6_host": ":3",
        "ipv4_host": None,
        "ipv4_network": None,
        "ipv4_netmask": None,
326
        "ipv6_no_forwarding": False,
Federico Sismondi's avatar
Federico Sismondi committed
327 328
    }

329

330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
class MsgPacketInjectRaw(Message):
    """
    Description: Message to be captured by the agent an push into the correct embedded interface (e.g. tun, serial, etc..)

    Type: Event

    Pub/Sub: Testing Tool -> Agent

    Description: TBD
    """
    routing_key = None  # depends on the agent_id and the agent interface being used, re-write after creation

    _msg_data_template = {
        "_type": "packet.to_inject.raw",
        "timestamp": "1488586183.45",
        "interface_name": "tun0",
        "data": [96, 0, 0, 0, 0, 36, 0, 1, 254, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 255, 2, 0, 0, 0, 0, 0, 0,
                 0, 0, 0, 0, 0, 0, 0, 22, 58, 0, 5, 2, 0, 0, 1, 0, 143, 0, 112, 7, 0, 0, 0, 1, 4, 0, 0, 0, 255, 2, 0, 0,
                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2]}


351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
class MsgPacketSniffedRaw(Message):
    """
    Description: Message captured by the agent in one of its embedded interfaces (e.g. tun, serial, etc..)

    Type: Event

    Pub/Sub: Agent -> Testing Tool

    Description: TBD
    """
    routing_key = None  # depends on the agent_id and the agent interface being used, re-write after creation

    _msg_data_template = {
        "_type": "packet.sniffed.raw",
        "timestamp": "1488586183.45",
        "interface_name": "tun0",
        "data": [96, 0, 0, 0, 0, 36, 0, 1, 254, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 255, 2, 0, 0, 0, 0, 0, 0,
                 0, 0, 0, 0, 0, 0, 0, 22, 58, 0, 5, 2, 0, 0, 1, 0, 143, 0, 112, 7, 0, 0, 0, 1, 4, 0, 0, 0, 255, 2, 0, 0,
                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2]}
370

371 372

# # # # # # SESSION MESSAGES # # # # # #
373

374
class MsgTestingToolTerminate(Message):
375
    """
376
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
377

378
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
379

380
    Pub/Sub: GUI, (or Orchestrator) -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
381

382
    Description: Testing tool should stop all it's processes gracefully.
383
    """
384
    routing_key = "control.session"
385 386

    _msg_data_template = {
387
        "_type": "testingtool.terminate",
388
        "description": "Event TERMINATE testing tool execution"
389 390 391 392 393
    }


class MsgTestingToolReady(Message):
    """
394
    Requirements: Testing Tool MUST publish event
Federico Sismondi's avatar
Federico Sismondi committed
395

396
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
397

398
    Typcal_use: Testing Tool -> GUI
Federico Sismondi's avatar
Federico Sismondi committed
399

400
    Description: Used to indicate to the GUI that testing is ready to start the test suite
401
    """
402
    routing_key = "control.session"
403 404

    _msg_data_template = {
405 406
        "_type": "testingtool.ready",
        "description": "Event Testing tool READY to start test suite."
407 408 409 410 411
    }


class MsgTestingToolComponentReady(Message):
    """
412
    Requirements: Testing Tool SHOULD implement (other components should not subscribe to event)
Federico Sismondi's avatar
Federico Sismondi committed
413

414
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
415

416
    Pub/Sub: Any Testing tool's component -> Test Coordinator
Federico Sismondi's avatar
Federico Sismondi committed
417

418
    Description: Once a testing tool's component is ready, it should publish a compoennt ready message
419
    """
420
    routing_key = "control.session"
421 422

    _msg_data_template = {
423
        "_type": "testingtool.component.ready",
424
        "component": "SomeComponent",
425
        "description": "Component READY to start test suite."
426 427 428
    }


429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
class MsgSessionChat(Message):
    """
    Requirements: GUI should implement

    Type: Event

    Pub/Sub: UI 1 (2) -> UI 2 (1)

    Description: Generic descriptor of chat messages
    """
    routing_key = "log.warning.the_drummer"

    _msg_data_template = {
        "_type": "chat",
        "user_name": "Ringo",
        "iut_node": "tbd",
        "description": "I've got blisters on my fingers!"
    }


class MsgSessionLog(Message):
    """
    Requirements: Testing Tool SHOULD implement

    Type: Event

    Pub/Sub: Any Testing tool's component -> user/devs interfaces

    Description: Generic descriptor of log messages
    """
    routing_key = "log.warning.the_drummer"

    _msg_data_template = {
        "_type": "log",
Federico Sismondi's avatar
Federico Sismondi committed
463
        "component": "misc",
464
        "message": "I've got blisters on my fingers!"
465 466 467
    }


468 469 470 471 472 473 474 475 476 477 478
class MsgSessionConfiguration(Message):
    """
    Requirements: Testing Tool MUST listen to event

    Type: Event

    Pub/Sub: Orchestrator -> Testing Tool

    Description: Testing tool MUST listen to this message and configure the testsuite correspondingly
    """
    routing_key = "control.session"
479

480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
    _msg_data_template = {
        "_type": "session.configuration",
        "session_id": "666",
        "configuration": {
            'testsuite.testcases': [
                'someTestCaseId1',
                'someTestCaseId2'
            ]
        },
        "testing_tools": "f-interop/someTestToolId",
        "users": [
            "u1",
            "f-interop"
        ],
    }


# TODO deprecate this in favor of the generic MsgSessionConfiguration
498
class MsgInteropSessionConfiguration(Message):
499
    """
500
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
501

502
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
503

504
    Pub/Sub: Orchestrator -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
505

506
    Description: Testing tool MUST listen to this message and configure the testsuite correspondingly
507
    """
508
    routing_key = "control.session"
509 510

    _msg_data_template = {
511 512
        "_type": "session.interop.configuration",
        "session_id": "TBD",
513 514 515 516 517 518 519 520
        "configuration":
            {
                'testsuite.testcases': [
                    'http://doc.f-interop.eu/tests/TD_COAP_CORE_01',
                    'http://doc.f-interop.eu/tests/TD_COAP'
                ]
            },

521
        "testing_tools": "f-interop/interoperability-coap",
522
        "users": [
523 524 525
            "u1",
            "f-interop"
        ],
526
        "tests": [
527
            {
Federico Sismondi's avatar
Federico Sismondi committed
528
                "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_01",
529
                "settings": {}
530 531
            },
            {
Federico Sismondi's avatar
Federico Sismondi committed
532
                "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_02",
533 534 535
                "settings": {}
            },
            {
Federico Sismondi's avatar
Federico Sismondi committed
536
                "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_03",
537
                "settings": {}
538 539 540 541 542
            }
        ]
    }


543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
class MsgAgentConfigured(Message):
    """
    Requirements: Testing Tool SHOULD publish event

    Type: Event

    Pub/Sub: Testing Tool -> GUI

    Description: The goal is to notify GUI when agents are ready to start the session
    """

    routing_key = "control.session"

    _msg_data_template = {
        "_type": "agent.configured",
        "description": "Event agent successfully CONFIGURED",
        'name': 'agent_TT'
    }


563 564
class MsgTestingToolConfigured(Message):
    """
565
    Requirements: Testing Tool MUST publish event
Federico Sismondi's avatar
Federico Sismondi committed
566

567
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
568

569
    Pub/Sub: Testing Tool -> Orchestrator, GUI
Federico Sismondi's avatar
Federico Sismondi committed
570

571
    Description: The goal is to notify orchestrator and other components that the testing tool has been configured
572 573 574 575 576
    """

    routing_key = "control.session"

    _msg_data_template = {
577 578 579
        "_type": "testingtool.configured",
        "description": "Event Testing tool CONFIGURED",
        "session_id": "TBD",
580 581 582
        "testing_tools": "f-interop/interoperability-coap",
    }

583

584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
class MsgSessionCreated(Message):
    """
    Requirements: Session Orchestrator MUST publish message on common-services channel (on every session creation)

    Type: Event

    Pub/Sub: SO -> viz tools

    Description: The goal is to notify viz tools about new sessions
    """

    routing_key = "control.session.created"

    _msg_data_template = {
        "_type": "session.created",
        "description": "A new session has been created",
        "session_id": "TBD",
        "testing_tools": "TBD",
    }


605 606
class MsgTestingToolComponentShutdown(Message):
    """
607
    Requirements: Testing Tool SHOULD implement (other components should not subscribe to event)
Federico Sismondi's avatar
Federico Sismondi committed
608

609
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
610

611
    Pub/Sub: Any Testing tool's component -> Test Coordinator
Federico Sismondi's avatar
Federico Sismondi committed
612

613 614
    Description: tbd
    """
615 616 617
    routing_key = "control.session"

    _msg_data_template = {
618
        "_type": "testingtool.component.shutdown",
619
        "component": "SomeComponent",
620
        "description": "Event Component SHUTDOWN. Bye!"
621 622
    }

623
    # # # # # # TEST COORDINATION MESSAGES # # # # # #
624

625 626 627

class MsgTestSuiteStart(Message):
    """
628
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
629

630
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
631

632
    Pub/Sub: GUI -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
633

634
    Description: tbd
635 636
    """

637
    routing_key = "control.testcoordination"
638 639

    _msg_data_template = {
640
        "_type": "testcoordination.testsuite.start",
641
        "description": "Event test suite START"
642 643
    }

644

Federico Sismondi's avatar
Federico Sismondi committed
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
class MsgTestSuiteStarted(Message):
    """
    Requirements: Testing Tool SHOULD publish to event

    Type: Event

    Pub/Sub: Testing Tool -> GUI

    Description: tbd
    """

    routing_key = "control.testcoordination"

    _msg_data_template = {
        "_type": "testcoordination.testsuite.started",
        "description": "Event test suite STARTED"
    }
662

663

664 665
class MsgTestSuiteFinish(Message):
    """
666
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
667

668
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
669

670
    Pub/Sub: GUI -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
671

672
    Description: tbd
673 674 675 676 677
    """

    routing_key = "control.testcoordination"

    _msg_data_template = {
678
        "_type": "testcoordination.testsuite.finish",
679
        "description": "Event test suite FINISH"
680 681
    }

682

683 684
class MsgTestCaseReady(Message):
    """
685
    Requirements: Testing Tool MUST publish event
Federico Sismondi's avatar
Federico Sismondi committed
686

687
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
688

Federico Sismondi's avatar
Federico Sismondi committed
689
    Pub/Sub: Testing Tool -> GUI
Federico Sismondi's avatar
Federico Sismondi committed
690

691 692 693
    Description:
        - Used to indicate to the GUI (or automated-iut) which is the next test case to be executed.
        - This message is normally followed by a MsgTestCaseStart (from GUI-> Testing Tool)
694 695
    """

696
    routing_key = "control.testcoordination"
697 698

    _msg_data_template = {
699
        "_type": "testcoordination.testcase.ready",
Federico Sismondi's avatar
Federico Sismondi committed
700 701 702
        "description": "Next test case to be executed is TD_COAP_CORE_01",
        "testcase_id": "TD_COAP_CORE_01",
        "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_01",
703 704
        "objective": "Perform GET transaction(CON mode)",
        "state": None
705 706 707
    }


708 709
class MsgTestCaseStart(Message):
    """
710
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
711

712
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
713

714
    Pub/Sub: GUI -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
715

716 717
    Description:
        - Message used for indicating the testing tool to start the test case (the one previously selected)
718 719
        - if testcase_id is Null then testing tool starts previously announced testcase in message
        "testcoordination.testcase.ready",
720
    """
721
    routing_key = "control.testcoordination"
722 723

    _msg_data_template = {
724
        "_type": "testcoordination.testcase.start",
725 726
        "description": "Event test case START",
        "testcase_id": "TBD",
727 728
    }

Federico Sismondi's avatar
Federico Sismondi committed
729

730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
class MsgTestCaseStarted(Message):
    """
    Requirements: Testing Tool SHOULD publish event

    Type: Event

    Pub/Sub: Testing Tool -> GUI

    Description:
        - Message used for indicating that testcase has started
    """
    routing_key = "control.testcoordination"

    _msg_data_template = {
        "_type": "testcoordination.testcase.started",
        "description": "Event test case STARTED",
        "testcase_id": "TBD",
    }
748

Federico Sismondi's avatar
Federico Sismondi committed
749

750 751
# TODO MsgTestCaseNotes, see https://portal.etsi.org/cti/downloads/TestSpecifications/6LoWPAN_Plugtests_TestDescriptions_1.0.pdf

752

753 754
class MsgTestCaseConfiguration(Message):
    """
755
    Requirements: Testing Tool MAY publish event (if needed for executing the test case)
756 757 758 759 760 761 762 763 764
    Type: Event
    Pub/Sub: Testing Tool -> GUI & automated-iut
    Description:
        - Message used to indicate GUI and/or automated-iut which configuration to use.
        - IMPORTANT: deprecate this message in favor of MsgConfigurationExecute and MsgConfigurationExecuted
    """
    routing_key = "control.testcoordination"
    _msg_data_template = {
        "_type": "testcoordination.testcase.configuration",
Federico Sismondi's avatar
Federico Sismondi committed
765
        "configuration_id": "COAP_CFG_01",
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
        "node": "coap_server",
        "testcase_id": "TBD",
        "testcase_ref": "TBD",
        "description":
            ["CoAP servers running service at [bbbb::2]:5683",
             "CoAP servers are requested to offer the following resources",
             ["/test", "Default test resource", "Should not exceed 64bytes"],
             ["/seg1/seg2/seg3", "Long path ressource", "Should not exceed 64bytes"],
             ["/query", "Ressource accepting query parameters", "Should not exceed 64bytes"],
             ["/separate",
              "Ressource which cannot be served immediately and which cannot be "
              "acknowledged in a piggy-backed way",
              "Should not exceed 64bytes"],
             ["/large", "Large resource (>1024 bytes)", "shall not exceed 2048bytes"],
             ["/large_update",
              "Large resource that can be updated using PUT method (>1024 bytes)",
              "shall not exceed 2048bytes"],
             ["/large_create",
              "Large resource that can be  created using POST method (>1024 bytes)",
              "shall not exceed 2048bytes"],
             ["/obs", "Observable resource which changes every 5 seconds",
              "shall not exceed 2048bytes"],
             ["/.well-known/core", "CoRE Link Format", "may require usage of Block options"]
             ]
    }


class MsgConfigurationExecute(Message):
    """
    Requirements: Testing Tool MAY publish event (if needed for executing the test case)
Federico Sismondi's avatar
Federico Sismondi committed
796

797
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
798

799
    Pub/Sub: Testing Tool -> GUI & automated-iut
Federico Sismondi's avatar
Federico Sismondi committed
800

801 802
    Description:
        - Message used to indicate GUI and/or automated-iut which configuration to use.
803 804 805 806
    """
    routing_key = "control.testcoordination"

    _msg_data_template = {
807
        "_type": "testcoordination.configuration.execute",
Federico Sismondi's avatar
Federico Sismondi committed
808
        "configuration_id": "COAP_CFG_01",
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
        "node": "coap_server",
        "testcase_id": "TBD",
        "testcase_ref": "TBD",
        "description":
            ["CoAP servers running service at [bbbb::2]:5683",
             "CoAP servers are requested to offer the following resources",
             ["/test", "Default test resource", "Should not exceed 64bytes"],
             ["/seg1/seg2/seg3", "Long path ressource", "Should not exceed 64bytes"],
             ["/query", "Ressource accepting query parameters", "Should not exceed 64bytes"],
             ["/separate",
              "Ressource which cannot be served immediately and which cannot be "
              "acknowledged in a piggy-backed way",
              "Should not exceed 64bytes"],
             ["/large", "Large resource (>1024 bytes)", "shall not exceed 2048bytes"],
             ["/large_update",
              "Large resource that can be updated using PUT method (>1024 bytes)",
              "shall not exceed 2048bytes"],
             ["/large_create",
              "Large resource that can be  created using POST method (>1024 bytes)",
              "shall not exceed 2048bytes"],
             ["/obs", "Observable resource which changes every 5 seconds",
              "shall not exceed 2048bytes"],
             ["/.well-known/core", "CoRE Link Format", "may require usage of Block options"]
             ]
833 834 835
    }


836 837 838 839 840 841 842 843 844 845
class MsgConfigurationExecuted(Message):
    """
    Requirements: Testing Tool SHOULD listen to event

    Type: Event

    Pub/Sub: GUI (automated-IUT) -> Testing Tool

    Description:
        - Message used for indicating that the IUT has been configured as requested
846
        - pixit must be included in this message (pixit = Protocol Implementaiton eXtra Information for Testing)
847 848 849 850 851 852
    """
    routing_key = "control.testcoordination"

    _msg_data_template = {
        "_type": "testcoordination.configuration.executed",
        "description": "Event IUT has been configured",
853
        "node": "coap_server",
Federico Sismondi's avatar
Federico Sismondi committed
854
        "ipv6_address": "tbd"  # example of pixit
855 856 857
    }


858 859
class MsgTestCaseStop(Message):
    """
860
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
861

862
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
863

864
    Pub/Sub: GUI & automated-iut -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
865

866 867
    Description:
        - Message used for indicating the testing tool to stop the test case (the one running).
868 869
    """

870
    routing_key = "control.testcoordination"
871 872

    _msg_data_template = {
873
        "_type": "testcoordination.testcase.stop",
874
        "description": "Event test case STOP"
875 876 877 878 879
    }


class MsgTestCaseRestart(Message):
    """
880
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
881

882
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
883

884
    Pub/Sub: GUI -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
885

886
    Description: Restart the running test cases.
887 888
    """

889
    routing_key = "control.testcoordination"
890 891

    _msg_data_template = {
892
        "_type": "testcoordination.testcase.restart",
893
        "description": "Event test case RESTART"
894 895
    }

896

897
class MsgStepStimuliExecute(Message):
898
    """
899
    Requirements: Testing Tool MUST publish event
900

901
    Type: Event
902

903
    Pub/Sub: Testing Tool -> GUI
904

905
    Description:
906 907
        - Used to indicate to the GUI (or automated-iut) which is the stimuli step to be executed by the user (or
        automated-IUT).
908 909
    """

910
    routing_key = "control.testcoordination"
911 912

    _msg_data_template = {
913
        "_type": "testcoordination.step.stimuli.execute",
Federico Sismondi's avatar
Federico Sismondi committed
914 915
        "description": "Please execute TD_COAP_CORE_01_step_01",
        "step_id": "TD_COAP_CORE_01_step_01",
916 917
        "step_type": "stimuli",
        "step_info": [
918 919 920 921
            "Client is requested to send a GET request with",
            "Type = 0(CON)",
            "Code = 1(GET)"
        ],
922 923
        "step_state": "executing",
        "node": "coap_client",
924
        "node_execution_mode": "user_assisted",
925
        "testcase_id": "TBD",
Federico Sismondi's avatar
Federico Sismondi committed
926 927
        "testcase_ref": "TBD",
        "target_address": "TBD"
928 929
    }

930

931
class MsgStepStimuliExecuted(Message):
932
    """
933
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
934

935
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
936

937
    Pub/Sub: GUI (or automated-IUT)-> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
938

939 940
    Description:
        - Used to indicate stimuli has been executed by user (and it's user-assisted iut) or by automated-iut
941 942
    """

943
    routing_key = "control.testcoordination"
944 945

    _msg_data_template = {
946
        "_type": "testcoordination.step.stimuli.executed",
947 948 949
        "description": "Event step (stimuli) EXECUTED",
        "node": "coap_client",
        "node_execution_mode": "user_assisted",
950 951 952
    }


953
class MsgStepCheckExecute(Message):
954
    """
955
    Requirements: Testing Tool SHOULD publish event
Federico Sismondi's avatar
Federico Sismondi committed
956

957
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
958

959
    Pub/Sub: Testing Tool -> Analysis
Federico Sismondi's avatar
Federico Sismondi committed
960

961 962 963 964 965 966 967 968 969
    Description:
        - Used to indicate to the GUI (or automated-iut) which is the stimuli step to be executed by the user (or
        automated-IUT).
    """

    routing_key = "control.testcoordination"

    _msg_data_template = {
        "_type": "testcoordination.step.check.execute",
Federico Sismondi's avatar
Federico Sismondi committed
970 971
        "description": "Please execute TD_COAP_CORE_01_step_02",
        "step_id": "TD_COAP_CORE_01_step_02",
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988
        "step_type": "check",
        "step_info": [
            "The request sent by the client contains",
            "Type=0 and Code=1,"
            "Client-generated Message ID (➔ CMID)",
            "Client-generated Token (➔ CTOK)",
            "UTEST Uri-Path option test"
        ],
        "step_state": "executing",
        "testcase_id": "TBD",
        "testcase_ref": "TBD"
    }


class MsgStepCheckExecuted(Message):
    """
    Requirements: Testing Tool SHOULD implement
Federico Sismondi's avatar
Federico Sismondi committed
989

990
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
991

992
    Pub/Sub: test coordination -> test analysis
Federico Sismondi's avatar
Federico Sismondi committed
993

994
    Description:
995 996
        - In the context of IUT to IUT test execution, this message is used for indicating that the previously
        executed
997 998
        messages (stimuli message and its reply) CHECK or comply to what is described in the Test Description.
        - Not used in CoAP testing Tool (analysis of traces is done post mortem)
999 1000
    """

1001
    routing_key = "control.testcoordination"
1002

1003
    _msg_data_template = {
1004
        "_type": "testcoordination.step.check.executed",
1005
        "partial_verdict": "pass",
1006
        "description": "TAT says: step complies (checks) with specification",
1007 1008 1009
    }


1010
class MsgStepVerifyExecute(Message):
1011
    """
1012
    Requirements: Testing Tool MUST publish event
Federico Sismondi's avatar
Federico Sismondi committed
1013

1014
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
1015

1016
    Pub/Sub: Testing Tool -> GUI (or automated-IUT)
Federico Sismondi's avatar
Federico Sismondi committed
1017

1018
    Description:
1019 1020
        - Used to indicate to the GUI (or automated-iut) which is the verify step to be executed by the user (or
        automated-IUT).
1021 1022
    """

1023
    routing_key = "control.testcoordination"
1024 1025

    _msg_data_template = {
1026 1027
        "_type": "testcoordination.step.verify.execute",
        "response_type": "bool",
Federico Sismondi's avatar
Federico Sismondi committed
1028 1029
        "description": "Please execute TD_COAP_CORE_01_step_04",
        "step_id": "TD_COAP_CORE_01_step_04",
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
        "step_type": "verify",
        "step_info": [
            "Client displays the received information"
        ],
        "node": "coap_client",
        "node_execution_mode": "user_assisted",
        "step_state": "executing",
        "testcase_id": "TBD",
        "testcase_ref": "TBD"

1040 1041
    }

1042

1043
class MsgStepVerifyExecuted(Message):
1044
    """
1045
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
1046

1047
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
1048

1049
    Pub/Sub: GUI (or automated-IUT)-> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
1050

1051
    Description:
1052
        - Message generated by user (GUI or automated-IUT) declaring if the IUT VERIFY verifies the expected behaviour.
1053 1054
    """

1055
    routing_key = "control.testcoordination"
1056 1057

    _msg_data_template = {
1058 1059 1060 1061 1062 1063
        "_type": "testcoordination.step.verify.executed",
        "description": "Event step (verify) EXECUTED",
        "response_type": "bool",
        "verify_response": True,
        "node": "coap_client",
        "node_execution_mode": "user_assisted",
1064 1065
    }

1066 1067 1068 1069 1070 1071
    # class MsgTestCaseFinish(Message):
    #     """
    #     TODO: TBD if needed or not
    #
    #     Requirements: Testing Tool MAY listen to event
    #     Type: Event
1072
    #     Pub/Sub: GUI (or automated-IUT)-> Testing Tool