messages.py 53.7 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
28
>>> m = MsgTestCaseSkip()
29
>>> m
30
MsgTestCaseSkip(_api_version = 0.1.31, _type = testcoordination.testcase.skip, testcase_id = TD_COAP_CORE_02_v01, )
31 32
>>> m.routing_key
'control.testcoordination'
33 34
>>> m.message_id # doctest: +SKIP
'802012eb-24e3-45c4-9dcc-dc293c584f63'
35 36
>>> m.testcase_id
'TD_COAP_CORE_02_v01'
37

38 39 40
# also we can modify some of the fields (rewrite the default ones)
>>> m = MsgTestCaseSkip(testcase_id = 'TD_COAP_CORE_03_v01')
>>> m
41
MsgTestCaseSkip(_api_version = 0.1.31, _type = testcoordination.testcase.skip, testcase_id = TD_COAP_CORE_03_v01, )
42 43
>>> m.testcase_id
'TD_COAP_CORE_03_v01'
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.31", "_type": "testcoordination.testcase.skip", "testcase_id": "TD_COAP_CORE_03_v01"}'
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.31", "_type": "testcoordination.testsuite.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 66
MsgErrorReply(_api_version = 0.1.31, _type = sniffing.start, error_code = Some error code TBD, error_message = Some
error message TBD, ok = False, )
67 68 69 70 71 72 73 74 75
>>> 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
76

77 78 79
"""

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

84
API_VERSION = '0.1.31'
85

86 87 88 89 90 91 92 93 94 95 96

# TODO use metaclasses instead?

class NonCompliantMessageFormatError(Exception):
    def __init__(self, value):
        self.value = value

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


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

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

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

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

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

        # add API's version
122
        self._msg_data["_api_version"] = API_VERSION
123 124 125 126 127

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

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

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

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

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

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

149
    def __str__(self):
150 151 152 153 154 155 156
        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
157
        return s
158

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

164 165
    @classmethod
    def from_json(cls, body):
166 167 168 169 170 171 172 173 174 175
        """
        :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:
176
            message_dict = json.loads(body.decode("utf-8"))
177
        else:
178
            raise NonCompliantMessageFormatError("Not a Json")
179

180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
        # 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

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

201
        message_type = message_dict["_type"]
202

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

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

215

216 217 218 219 220
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
    """
221

222 223 224 225 226 227 228
    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)
229
        if not hasattr(self, "_msg_data_template"):
230
            self._msg_data_template = {
231
                "_type": request_message._type,
232
                "ok": True,
233 234
            }

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

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


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

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

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

260 261

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

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

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

269
    Typical_use: Testing Tool -> Agent
Federico Sismondi's avatar
Federico Sismondi committed
270

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

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


class MsgAgentTunStarted(Message):
    """
289
    Description: Message for indicating that agent tun has been started
Federico Sismondi's avatar
Federico Sismondi committed
290

291
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
292

293
    Typical_use: Testing Tool -> Agent
Federico Sismondi's avatar
Federico Sismondi committed
294

295
    Description: TBD
Federico Sismondi's avatar
Federico Sismondi committed
296
    """
297
    routing_key = "control.tun.from.agent_TT"
Federico Sismondi's avatar
Federico Sismondi committed
298 299

    _msg_data_template = {
300 301 302 303 304 305 306
        "_type": "tun.started",
        "name": "agent_TT",
        "ipv6_prefix": "bbbb",
        "ipv6_host": ":3",
        "ipv4_host": None,
        "ipv4_network": None,
        "ipv4_netmask": None,
307
        "ipv6_no_forwarding": False,
Federico Sismondi's avatar
Federico Sismondi committed
308 309
    }

310

Federico Sismondi's avatar
Federico Sismondi committed
311 312 313 314
'''
TODO add packet.sniffed.raw
ROUTING_KEY: data.tun.fromAgent.coap_server_agent
 - - -
315 316
PROPS: {"delivery_mode": 2, "content_type": "application/json", "headers": {}, "priority": 0, "content_encoding": 
"utf-8"}
Federico Sismondi's avatar
Federico Sismondi committed
317
 - - -
318 319 320
BODY {"timestamp": "1488586183.45", "_type": "packet.sniffed.raw", "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]}
Federico Sismondi's avatar
Federico Sismondi committed
321
'''
322

323 324

# # # # # # SESSION MESSAGES # # # # # #
325

326
class MsgTestingToolTerminate(Message):
327
    """
328
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
329

330
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
331

332
    Typical_use: GUI, (or Orchestrator) -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
333

334
    Description: Testing tool should stop all it's processes gracefully.
335
    """
336
    routing_key = "control.session"
337 338

    _msg_data_template = {
339
        "_type": "testingtool.terminate",
340
        "description": "Event TERMINATE testing tool execution"
341 342 343 344 345
    }


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

348
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
349

350
    Typcal_use: Testing Tool -> GUI
Federico Sismondi's avatar
Federico Sismondi committed
351

352
    Description: Used to indicate to the GUI that testing is ready to start the test suite
353
    """
354
    routing_key = "control.session"
355 356

    _msg_data_template = {
357 358
        "_type": "testingtool.ready",
        "description": "Event Testing tool READY to start test suite."
359 360 361 362 363
    }


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

366
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
367

368
    Typical_use: Any Testing tool's component -> Test Coordinator
Federico Sismondi's avatar
Federico Sismondi committed
369

370
    Description: Once a testing tool's component is ready, it should publish a compoennt ready message
371
    """
372
    routing_key = "control.session"
373 374

    _msg_data_template = {
375
        "_type": "testingtool.component.ready",
376
        "component": "SomeComponent",
377
        "description": "Component READY to start test suite."
378 379 380
    }


381
class MsgInteropSessionConfiguration(Message):
382
    """
383
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
384

385
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
386

387
    Typical_use: Orchestrator -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
388

389
    Description: Testing tool MUST listen to this message and configure the testsuite correspondingly
390
    """
391
    routing_key = "control.session"
392 393

    _msg_data_template = {
394 395
        "_type": "session.interop.configuration",
        "session_id": "TBD",
396
        "testing_tools": "f-interop/interoperability-coap",
397
        "users": [
398 399 400
            "u1",
            "f-interop"
        ],
401
        "iuts": [
402
            {
403 404
                "id": "someImplementationFromAUser",
                "role": "coap_server",
405
                "execution_mode": "user-assisted",
406 407 408
                "location": "user-facilities",
                "owner": "someUserName",
                "version": "0.1"
409 410
            },
            {
411 412
                "id": "automated_iut-coap_client-coapthon-v0.1",
                "role": "coap_client",
413
                "execution_mode": "automated-iut",
414 415 416
                "location": "central-server-docker",
                "owner": "f-interop",
                "version": "0.1"
417 418
            }
        ],
419
        "tests": [
420 421
            {
                "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_01_v01",
422
                "settings": {}
423 424 425
            },
            {
                "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_02_v01",
426 427 428 429 430
                "settings": {}
            },
            {
                "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_03_v01",
                "settings": {}
431 432 433 434 435 436 437
            }
        ]
    }


class MsgTestingToolConfigured(Message):
    """
438
    Requirements: Testing Tool MUST publish event
Federico Sismondi's avatar
Federico Sismondi committed
439

440
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
441

442
    Typical_use: Testing Tool -> Orchestrator, GUI
Federico Sismondi's avatar
Federico Sismondi committed
443

444
    Description: The goal is to notify orchestrator and other components that the testing tool has been configured
445 446 447 448 449
    """

    routing_key = "control.session"

    _msg_data_template = {
450 451 452
        "_type": "testingtool.configured",
        "description": "Event Testing tool CONFIGURED",
        "session_id": "TBD",
453 454 455
        "testing_tools": "f-interop/interoperability-coap",
    }

456

457 458
class MsgTestingToolComponentShutdown(Message):
    """
459
    Requirements: Testing Tool SHOULD implement (other components should not subscribe to event)
Federico Sismondi's avatar
Federico Sismondi committed
460

461
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
462

463
    Typical_use: Any Testing tool's component -> Test Coordinator
Federico Sismondi's avatar
Federico Sismondi committed
464

465 466
    Description: tbd
    """
467 468 469
    routing_key = "control.session"

    _msg_data_template = {
470
        "_type": "testingtool.component.shutdown",
471
        "component": "SomeComponent",
472
        "description": "Event Component SHUTDOWN. Bye!"
473 474
    }

475
    # # # # # # TEST COORDINATION MESSAGES # # # # # #
476

477 478 479

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

482
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
483

484
    Typical_use: GUI -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
485

486
    Description: tbd
487 488
    """

489
    routing_key = "control.testcoordination"
490 491

    _msg_data_template = {
492
        "_type": "testcoordination.testsuite.start",
493
        "description": "Event test suite START"
494 495 496
    }


497 498
class MsgTestSuiteFinish(Message):
    """
499
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
500

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

503
    Typical_use: GUI -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
504

505
    Description: tbd
506 507 508 509 510
    """

    routing_key = "control.testcoordination"

    _msg_data_template = {
511
        "_type": "testcoordination.testsuite.finish",
512
        "description": "Event test suite FINISH"
513 514
    }

515

516 517
class MsgTestCaseReady(Message):
    """
518
    Requirements: Testing Tool MUST publish event
Federico Sismondi's avatar
Federico Sismondi committed
519

520
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
521

522
    Typical_use: GUI -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
523

524 525 526
    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)
527 528
    """

529
    routing_key = "control.testcoordination"
530 531

    _msg_data_template = {
532 533 534
        "_type": "testcoordination.testcase.ready",
        "description": "Next test case to be executed is TD_COAP_CORE_01_v01",
        "testcase_id": "TD_COAP_CORE_01_v01",
535
        "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_01_v01",
536 537
        "objective": "Perform GET transaction(CON mode)",
        "state": None
538 539 540
    }


541 542
class MsgTestCaseStart(Message):
    """
543
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
544

545
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
546

547
    Typical_use: GUI -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
548

549 550
    Description:
        - Message used for indicating the testing tool to start the test case (the one previously selected)
551
    """
552
    routing_key = "control.testcoordination"
553 554

    _msg_data_template = {
555
        "_type": "testcoordination.testcase.start",
556
        "description": "Event test case START"
557 558 559
    }


560 561
class MsgTestCaseConfiguration(Message):
    """
562
    Requirements: Testing Tool MAY publish event (if needed for executing the test case)
Federico Sismondi's avatar
Federico Sismondi committed
563

564
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
565

566
    Typical_use: Testing Tool -> GUI & automated-iut
Federico Sismondi's avatar
Federico Sismondi committed
567

568 569
    Description:
        - Message used to indicate GUI and/or automated-iut which configuration to use.
570 571 572 573
    """
    routing_key = "control.testcoordination"

    _msg_data_template = {
574
        "_type": "testcoordination.testcase.configuration",
575
        "configuration_id": "COAP_CFG_01_v01",
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
        "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"]
             ]
600 601 602
    }


603 604
class MsgTestCaseStop(Message):
    """
605
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
606

607
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
608

609
    Typical_use: GUI & automated-iut -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
610

611 612
    Description:
        - Message used for indicating the testing tool to stop the test case (the one running).
613 614
    """

615
    routing_key = "control.testcoordination"
616 617

    _msg_data_template = {
618
        "_type": "testcoordination.testcase.stop",
619
        "description": "Event test case STOP"
620 621 622 623 624
    }


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

627
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
628

629
    Typical_use: GUI -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
630

631
    Description: Restart the running test cases.
632 633
    """

634
    routing_key = "control.testcoordination"
635 636

    _msg_data_template = {
637
        "_type": "testcoordination.testcase.restart",
638
        "description": "Event test case RESTART"
639 640
    }

641

642
class MsgStepStimuliExecute(Message):
643
    """
644
    Requirements: Testing Tool MUST publish event
645

646
    Type: Event
647

648
    Typical_use: Testing Tool -> GUI
649

650
    Description:
651 652
        - Used to indicate to the GUI (or automated-iut) which is the stimuli step to be executed by the user (or
        automated-IUT).
653 654
    """

655
    routing_key = "control.testcoordination"
656 657

    _msg_data_template = {
658 659 660 661 662
        "_type": "testcoordination.step.stimuli.execute",
        "description": "Please execute TD_COAP_CORE_01_v01_step_01",
        "step_id": "TD_COAP_CORE_01_v01_step_01",
        "step_type": "stimuli",
        "step_info": [
663 664 665 666
            "Client is requested to send a GET request with",
            "Type = 0(CON)",
            "Code = 1(GET)"
        ],
667 668
        "step_state": "executing",
        "node": "coap_client",
669
        "node_execution_mode": "user_assisted",
670 671
        "testcase_id": "TBD",
        "testcase_ref": "TBD"
672 673
    }

674

675
class MsgStepStimuliExecuted(Message):
676
    """
677
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
678

679
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
680

681
    Typical_use: GUI (or automated-IUT)-> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
682

683 684
    Description:
        - Used to indicate stimuli has been executed by user (and it's user-assisted iut) or by automated-iut
685 686
    """

687
    routing_key = "control.testcoordination"
688 689

    _msg_data_template = {
690
        "_type": "testcoordination.step.stimuli.executed",
691 692 693
        "description": "Event step (stimuli) EXECUTED",
        "node": "coap_client",
        "node_execution_mode": "user_assisted",
694 695 696
    }


697
class MsgStepCheckExecute(Message):
698
    """
699
    Requirements: Testing Tool SHOULD publish event
Federico Sismondi's avatar
Federico Sismondi committed
700

701
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
702

703
    Typical_use: Testing Tool -> Analysis
Federico Sismondi's avatar
Federico Sismondi committed
704

705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
    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",
        "description": "Please execute TD_COAP_CORE_01_v01_step_02",
        "step_id": "TD_COAP_CORE_01_v01_step_02",
        "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
733

734
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
735

736
    Typical_use: test coordination -> test analysis
Federico Sismondi's avatar
Federico Sismondi committed
737

738
    Description:
739 740
        - In the context of IUT to IUT test execution, this message is used for indicating that the previously
        executed
741 742
        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)
743 744
    """

745
    routing_key = "control.testcoordination"
746

747
    _msg_data_template = {
748
        "_type": "testcoordination.step.check.executed",
749
        "partial_verdict": "pass",
750
        "description": "TAT says: step complies (checks) with specification",
751 752 753
    }


754
class MsgStepVerifyExecute(Message):
755
    """
756
    Requirements: Testing Tool MUST publish event
Federico Sismondi's avatar
Federico Sismondi committed
757

758
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
759

760
    Typical_use: Testing Tool -> GUI (or automated-IUT)
Federico Sismondi's avatar
Federico Sismondi committed
761

762
    Description:
763 764
        - Used to indicate to the GUI (or automated-iut) which is the verify step to be executed by the user (or
        automated-IUT).
765 766
    """

767
    routing_key = "control.testcoordination"
768 769

    _msg_data_template = {
770 771 772 773 774 775 776 777 778 779 780 781 782 783
        "_type": "testcoordination.step.verify.execute",
        "response_type": "bool",
        "description": "Please execute TD_COAP_CORE_01_v01_step_04",
        "step_id": "TD_COAP_CORE_01_v01_step_04",
        "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"

784 785
    }

786

787
class MsgStepVerifyExecuted(Message):
788
    """
789
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
790

791
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
792

793
    Typical_use: GUI (or automated-IUT)-> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
794

795
    Description:
796
        - Message generated by user (GUI or automated-IUT) declaring if the IUT VERIFY verifies the expected behaviour.
797 798
    """

799
    routing_key = "control.testcoordination"
800 801

    _msg_data_template = {
802 803 804 805 806 807
        "_type": "testcoordination.step.verify.executed",
        "description": "Event step (verify) EXECUTED",
        "response_type": "bool",
        "verify_response": True,
        "node": "coap_client",
        "node_execution_mode": "user_assisted",
808 809
    }

810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
    # class MsgTestCaseFinish(Message):
    #     """
    #     TODO: TBD if needed or not
    #
    #     Requirements: Testing Tool MAY listen to event
    #     Type: Event
    #     Typical_use: GUI (or automated-IUT)-> Testing Tool
    #     Description:
    #         - Used for indicating that the test case has finished.
    #         - Test coordinator deduces it automatically by using the testcase's step sequence
    #         - Not used in CoAP Testing Tool.
    #     """
    #
    #     routing_key = "control.testcoordination"
    #
    #     _msg_data_template = {
    #         "_type": "testcoordination.testcase.finish",
    #     }

829

830 831
class MsgTestCaseFinished(Message):
    """
832
    Requirements: Testing Tool MUST publish event
Federico Sismondi's avatar
Federico Sismondi committed
833

834
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
835

836
    Typical_use: Testing Tool -> GUI
Federico Sismondi's avatar
Federico Sismondi committed
837

838 839 840
    Description:
        - Used for indicating to subscribers that the test cases has finished.
        - This message is followed by a verdict.
841 842
    """

843
    routing_key = "control.testcoordination"
844 845

    _msg_data_template = {
846 847
        "_type": "testcoordination.testcase.finished",
        "testcase_id": "TD_COAP_CORE_01",
848
        "testcase_ref": "TBD",
849
        "description": "Testcase finished"
850 851
    }

852

853 854
class MsgTestCaseSkip(Message):
    """
855
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
856

857
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
858

859
    Typical_use: GUI (or automated-IUT)-> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
860

861 862 863
    Description:
        - Used for skipping a test cases event when was previusly selected to be executed.
        - testcase_id (optional) : if not provided then current tc is skipped
864
        - node (mandatory): node requesting to skip test case
865 866
    """

867
    routing_key = "control.testcoordination"
868 869

    _msg_data_template = {
870
        "_type": "testcoordination.testcase.skip",
871
        "testcase_id": "TD_COAP_CORE_02_v01",
872
        "node": "TBD",
873 874 875 876 877
    }


class MsgTestCaseSelect(Message):
    """
878
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
879

880
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
881

882
    Typical_use: GUI (or automated-IUT)-> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
883

884 885
    Description: tbd

886 887
    """

888
    routing_key = "control.testcoordination"
889 890

    _msg_data_template = {
891
        "_type": "testcoordination.testcase.select",
892
        "testcase_id": "TD_COAP_CORE_03_v01",
893 894
    }

895

896 897
class MsgTestSuiteAbort(Message):
    """
898
    Requirements: Testing Tool MUST listen to event
Federico Sismondi's avatar
Federico Sismondi committed
899

900
    Type: Event
Federico Sismondi's avatar
Federico Sismondi committed
901

902
    Typical_use: GUI (or automated-IUT)-> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
903

904
    Description: Event test suite ABORT
905 906
    """

907
    routing_key = "control.testcoordination"
908 909

    _msg_data_template = {
910
        "_type": "testcoordination.testsuite.abort",
911
        "description": "Event test suite ABORT"
912 913
    }

914

915 916
class MsgTestSuiteGetStatus(Message):
    """
917
    Requirements: Testing Tool SHOULD implement (other components should not subscribe to event)
Federico Sismondi's avatar
Federico Sismondi committed
918

919
    Type: Request (service)
Federico Sismondi's avatar
Federico Sismondi committed
920

921
    Typical_use: GUI -> Testing Tool
Federico Sismondi's avatar
Federico Sismondi committed
922

923 924 925
    Description:
        - Describes current state of the test suite.