messages.py 44.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# -*- coding: utf-8 -*-

"""
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.

Usage:
------
15
>>> from messages import * # doctest: +SKIP
16
>>> m = MsgTestCaseSkip()
17 18
>>> m
MsgTestCaseSkip(_type = testcoordination.testcase.skip, _api_version = 0.1.2, testcase_id = TD_COAP_CORE_02_v01, )
19 20
>>> m.routing_key
'control.testcoordination'
21 22
>>> m.message_id # doctest: +SKIP
'802012eb-24e3-45c4-9dcc-dc293c584f63'
23 24
>>> m.testcase_id
'TD_COAP_CORE_02_v01'
25

26 27 28
# also we can modify some of the fields (rewrite the default ones)
>>> m = MsgTestCaseSkip(testcase_id = 'TD_COAP_CORE_03_v01')
>>> m
29
MsgTestCaseSkip(_type = testcoordination.testcase.skip, _api_version = 0.1.2, testcase_id = TD_COAP_CORE_03_v01, )
30 31
>>> m.testcase_id
'TD_COAP_CORE_03_v01'
32

33 34
# and even export the message in json format (for example for sending the message though the amqp event bus)
>>> m.to_json()
35
'{"_type": "testcoordination.testcase.skip", "_api_version": "0.1.2", "testcase_id": "TD_COAP_CORE_03_v01"}'
Federico Sismondi's avatar
Federico Sismondi committed
36

37
# We can use the Message class to import json into Message objects:
Federico Sismondi's avatar
Federico Sismondi committed
38 39
>>> m=MsgTestSuiteStart()
>>> m.to_json()
40
'{"_type": "testcoordination.testsuite.start", "_api_version": "0.1.2"}'
Federico Sismondi's avatar
Federico Sismondi committed
41 42 43
>>> json_message = m.to_json()
>>> obj=Message.from_json(json_message)
>>> type(obj)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
<class '__main__.MsgTestSuiteStart'>

# We can use the library for generating error responses to the requests:
# the request:
>>> m = MsgSniffingStart()
>>>
# the error reply (note that we pass the message of the request to build the reply):
>>> err = MsgErrorReply(m)
>>> err
MsgErrorReply(_type = sniffing.start, _api_version = 0.1.2, ok = False, error_code = Some error code TBD, error_message = Some error message TBD, )
>>> 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
63

64 65 66
"""

from collections import OrderedDict
67
import time
68 69 70
import json
import uuid

71
API_VERSION = '0.1.25'
72

73 74 75 76 77 78 79 80 81 82 83

# TODO use metaclasses instead?

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

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


84 85
class Message:
    def __init__(self, **kwargs):
86 87 88
        global API_VERSION

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

91 92
        # init properties
        self._properties = dict(
93 94
                content_type='application/json',
                message_id=str(uuid.uuid4()),
95
                timestamp=int(time.time())
96 97
        )

98 99 100 101 102
        try:
            if self.routing_key.endswith('.service'):
                self._properties['reply_to'] = '%s.%s' % (self.routing_key, 'reply')
                self._properties['correlation_id'] = self._properties['message_id']
        except AttributeError:
103
            pass
104

105
        # rewrite default data fields with the passed args
106 107 108 109 110 111 112 113 114
        self._msg_data.update(kwargs)

        # add API's version
        self._msg_data['_api_version'] = API_VERSION

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

115 116 117 118
        # add props as objects attributes
        for key in self._properties:
            setattr(self, key, self._properties[key])

119 120
    def to_dict(self) -> OrderedDict:
        resp = OrderedDict()
121 122
        # let's use sorted so API returns items inside always in the same order
        for field in sorted(self._msg_data.keys()):
123
            resp[field] = getattr(self, field)
124

125
        # for readability
126 127 128 129 130
        if 'ok' in resp:
            resp.move_to_end('ok', False)
        if '_api_version' in resp:
            resp.move_to_end('_api_version', False)
        if '_type' in resp:
131
            resp.move_to_end('_type', False)
132 133 134 135 136 137

        return resp

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

138
    def get_properties(self) -> dict:
139 140 141 142
        resp = OrderedDict()
        for field in self._properties:
            resp[field] = getattr(self, field)
        return resp
143

144
    def __str__(self):
145 146
        str = ' - ' * 20 + '\n'
        str += 'Message routing key: %s' % self.routing_key
147 148 149 150
        str += '\n -  -  - \n'
        str += 'Message properties: %s' % json.dumps(self.get_properties(),indent=4,)
        str += '\n -  -  - \n'
        str += 'Message body: %s' % json.dumps(self.to_dict(),indent=4,)
151 152 153
        str += '\n' + ' - ' * 20
        return str

154 155 156 157 158
    def update_properties(self, **kwargs):
        for key, value in kwargs.items():
            if key in self._properties:
                setattr(self, key, value)

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

        # check fist if it's a response
        if 'ok' in message_dict:
            # cannot build a complete reply message just from the json representation
178
            return
179 180 181 182 183

        message_type = message_dict['_type']
        if message_type in message_types_dict:
            return message_types_dict[message_type](**message_dict)
        else:
184
            raise NonCompliantMessageFormatError('Cannot load json message: %s' % str(body))
185

186
    def __repr__(self):
187
        ret = '%s(' % self.__class__.__name__
188
        for key, value in self.to_dict().items():
189
            ret += '%s = %s, ' % (key, value)
190 191 192
        ret += ')'
        return ret

193

194 195 196 197 198
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
    """
199

200 201 202 203 204 205 206 207
    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)
        if not hasattr(self, '_msg_data_template'):
208 209 210
            self._msg_data_template = {
                '_type': request_message._type,
                'ok': True,
211 212 213 214
            }

        super().__init__(**kwargs)

215
        # overwrite correlation id template and attribute
216 217 218 219 220 221 222 223 224 225 226 227
        self._properties['correlation_id'] = request_message.correlation_id
        self.correlation_id = request_message.correlation_id


class MsgErrorReply(MsgReply):
    """
    F-Interop conventions:
        - if event is a service request then the routing keys is control.someFunctionality.service
        also, its reply will be control.someFunctionality.service.reply
        - reply.correlation_id = request.correlation_id

    """
228

229 230
    def __init__(self, request_message, **kwargs):
        assert request_message
231
        # msg_data_template doesnt include _type cause this class is generic, we can only get this at init from request
232 233 234
        # so, let's copy the _type from request and let the MsgReply handle the rest of the fields
        self._msg_data_template['_type'] = request_message._type
        super().__init__(request_message, **kwargs)
235 236 237 238 239 240 241

    _msg_data_template = {
        'ok': False,
        'error_message': 'Some error message TBD',
        'error_code': 'Some error code TBD'
    }

Federico Sismondi's avatar
Federico Sismondi committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
###### AGENT MESSAGES ######

class MsgAgentTunStart(Message):
    """
    Message for triggering start IP tun interface in OS where the agent is running
    """
    routing_key = 'control.tun.toAgent.agent_TT'

    _msg_data_template = {
        '_type': 'tun.start',
        'name': 'agent_TT',
        'ipv6_prefix': 'bbbb',
        'ipv6_host': ':3',
        'ipv6_no_forwarding': False,
        'ipv4_host': None,
        'ipv4_network': None,
        'ipv4_netmask': None,
    }


class MsgAgentTunStarted(Message):
    """
    Message for indicating that agent tun has been started
    """
    routing_key = 'control.tun.from.agent_TT'

    _msg_data_template = {
        '_type': 'tun.started',
        'name': 'agent_TT',
        'ipv6_prefix': 'bbbb',
        'ipv6_host': ':3',
        'ipv4_host': None,
        'ipv4_network': None,
        'ipv4_netmask': None,
        'ipv6_no_forwarding': False,
    }

'''
TODO add packet.sniffed.raw
ROUTING_KEY: data.tun.fromAgent.coap_server_agent
 - - -
PROPS: {"delivery_mode": 2, "content_type": "application/json", "headers": {}, "priority": 0, "content_encoding": "utf-8"}
 - - -
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]}
'''
287 288 289

###### SESSION MESSAGES ######

290
class MsgTestingToolTerminate(Message):
291 292 293 294 295
    """
    Testing Tool MUST-implement API endpoint
    GUI, (or Orchestrator?) -> Testing Tool
    Testing tool should stop all it's processes gracefully.
    """
296
    routing_key = 'control.session'
297 298

    _msg_data_template = {
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
        '_type': 'testingtool.terminate',
    }


class MsgTestingToolReady(Message):
    """
    Testing Tool MUST-implement notification.
    Testing Tool -> GUI

    Used to indicate to the GUI that testing is ready to start the test suite
    """
    routing_key = 'control.session'

    _msg_data_template = {
        '_type': 'testingtool.ready',
        "message": "Testing tool ready to start test suite."
    }


class MsgTestingToolComponentReady(Message):
    """
    Testing Tools'internal call.
    Component x -> Test Coordinator
    Testing Tool SHOULD implement (design recommendation)
    """
    routing_key = 'control.session'

    _msg_data_template = {
        '_type': 'testingtool.component.ready',
        'component': 'SomeComponent',
        "message": "Component ready to start test suite."
    }


class MsgTestingToolComponentShutdown(Message):
    """
    Testing Tools'internal call.
    Component x -> Test Coordinator
    Testing Tool SHOULD implement (design recommendation)
    """
    routing_key = 'control.session'

    _msg_data_template = {
        '_type': 'testingtool.component.shutdown',
        'component': 'SomeComponent',
        "message": "Component is shutting down. Bye!"
345 346
    }

347

348 349 350 351 352 353 354 355
###### TEST COORDINATION MESSAGES ######

class MsgTestSuiteStart(Message):
    """
    Testing Tool MUST-implement API endpoint
    GUI -> Testing Tool
    """

356
    routing_key = "control.testcoordination"
357 358 359 360 361 362

    _msg_data_template = {
        '_type': "testcoordination.testsuite.start",
    }


363 364 365 366 367 368 369 370 371 372 373 374
class MsgTestSuiteFinish(Message):
    """
    Testing Tool MUST-implement API endpoint
    GUI -> Testing Tool
    """

    routing_key = "control.testcoordination"

    _msg_data_template = {
        '_type': "testcoordination.testsuite.finish",
    }

375

376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
class MsgTestCaseReady(Message):
    """
    Testing Tool MUST-implement notification.
    Testing Tool -> GUI

    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)
    """

    routing_key = 'control.testcoordination'

    _msg_data_template = {
        "_type": "testcoordination.testcase.ready",
        "message": "Next test case to be executed is TD_COAP_CORE_01_v01",
        "testcase_id": "TD_COAP_CORE_01_v01",
        "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_01_v01",
        "objective": "Perform GET transaction(CON mode)",
        "state": None
    }


397 398 399 400 401 402
class MsgTestCaseStart(Message):
    """
    Testing Tool MUST-implement API endpoint
    GUI -> Testing Tool
    Message used for indicating the testing tool to start the test case (the one previously selected)
    """
403
    routing_key = "control.testcoordination"
404 405 406 407 408 409

    _msg_data_template = {
        '_type': "testcoordination.testcase.start",
    }


410 411 412 413 414 415 416 417 418 419 420 421
class MsgTestCaseConfiguration(Message):
    """
    Testing Tool MUST-implement notification
    Testing Tool -> GUI
    Messages used to indicate GUI which configuration to use.
    """
    routing_key = "control.testcoordination"

    _msg_data_template = {
        "_type": "testcoordination.testcase.configuration",
        "configuration_id": "COAP_CFG_01_v01",
        "node": "coap_server",
422 423
        "testcase_id": "TBD",
        "testcase_ref": "TBD",
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
        "message":
            ["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"]
             ]
    }


444 445 446 447 448 449 450
class MsgTestCaseStop(Message):
    """
    Testing Tool MUST-implement API endpoint
    GUI -> Testing Tool
    Message used for indicating the testing tool to stop the test case (the one running)
    """

451
    routing_key = 'control.testcoordination'
452 453 454 455 456 457 458 459 460 461 462 463

    _msg_data_template = {
        '_type': 'testcoordination.testcase.stop',
    }


class MsgTestCaseRestart(Message):
    """
    Testing Tool MUST-implement API endpoint
    GUI -> Testing Tool
    """

464
    routing_key = 'control.testcoordination'
465 466 467 468 469

    _msg_data_template = {
        '_type': 'testcoordination.testcase.restart',
    }

470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492

class MsgStepExecute(Message):
    """
    Testing Tool MUST-implement notification.
    Testing Tool -> GUI

    Used to indicate to the GUI (or automated-iut) which is the step to be executed by the user (or automated-IUT)
    """

    routing_key = 'control.testcoordination'

    _msg_data_template = {
        "_type": "testcoordination.step.execute",
        "message": "Next test step to be executed is TD_COAP_CORE_01_v01_step_01",
        "step_id": "TD_COAP_CORE_01_v01_step_01",
        "step_type": "stimuli",
        "step_info": [
            "Client is requested to send a GET request with",
            "Type = 0(CON)",
            "Code = 1(GET)"
        ],
        "step_state": "executing",
        "node": "coap_client",
493 494 495
        "node_execution_mode": "user_assisted",
        "testcase_id": "TBD",
        "testcase_ref": "TBD"
496 497
    }

498 499 500 501 502 503 504

class MsgStimuliExecuted(Message):
    """
    Testing Tool MUST-implement API endpoint
    GUI (or automated-IUT)-> Testing Tool
    """

505
    routing_key = 'control.testcoordination'
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520

    _msg_data_template = {
        '_type': 'testcoordination.step.stimuli.executed',
    }


class MsgCheckResponse(Message):
    """
    Testing Tools'internal call.
    In the context of IUT to IUT test execution, this message is used for indicating that the previously executed
    messages (stimuli message and its reply) CHECK or comply to what is described in the Test Description.
    Testing tools' coordinator -> Testing Tool's analyzer (TAT)
    Not used in CoAP testing Tool (analysis of traces is done post mortem)
    """

521 522
    routing_key = 'control.testcoordination'

523 524
    _msg_data_template = {
        '_type': 'testcoordination.step.check.response',
525 526
        'partial_verdict': 'pass',
        'description': 'TAT says: step complies (checks) with specification'
527 528 529 530 531 532 533 534 535 536 537
    }


class MsgVerifyResponse(Message):
    """
    Testing Tool MUST-implement API endpoint
    Message provided by user declaring if the IUT VERIFY the step previously executed as described in the Test
    Description.
    GUI (or automated-IUT)-> Testing Tool
    """

538
    routing_key = 'control.testcoordination'
539 540 541 542 543 544 545

    _msg_data_template = {
        '_type': 'testcoordination.step.verify.response',
        'verify_response': True,
        'response_type': 'bool'
    }

546

547 548 549 550 551 552 553
class MsgTestCaseFinish(Message):
    """
    Testing Tool MUST-implement API endpoint
    GUI (or automated-IUT)-> Testing Tool
    Not used in CoAP Testing Tool (test coordinator deduces it automatically by using the testcase's step sequence)
    """

554
    routing_key = 'control.testcoordination'
555 556 557 558 559

    _msg_data_template = {
        '_type': 'testcoordination.testcase.finish',
    }

560

561 562 563 564 565 566 567 568 569 570 571 572
class MsgTestCaseFinished(Message):
    """
    Testing Tool MUST-implement notification.
    Testing Tool -> GUI

    This message is followed by a verdict
    """

    routing_key = 'control.testcoordination'

    _msg_data_template = {
        '_type': 'testcoordination.testcase.finished',
573 574 575
        'testcase_id': 'TD_COAP_CORE_01',
        "testcase_ref": "TBD",
        'message': 'Testcase finished'
576 577
    }

578

579 580 581 582
class MsgTestCaseSkip(Message):
    """
    Testing Tool MUST-implement API endpoint
    GUI (or automated-IUT)-> Testing Tool
583 584

    - testcase_id (optional) : if not provided then current tc is skipped
585 586
    """

587
    routing_key = 'control.testcoordination'
588 589 590 591 592 593 594 595 596 597 598 599 600

    _msg_data_template = {
        '_type': 'testcoordination.testcase.skip',
        'testcase_id': 'TD_COAP_CORE_02_v01',
    }


class MsgTestCaseSelect(Message):
    """
    Testing Tool MUST-implement API endpoint
    GUI (or automated-IUT)-> Testing Tool
    """

601
    routing_key = 'control.testcoordination'
602 603 604 605 606 607

    _msg_data_template = {
        '_type': 'testcoordination.testcase.select',
        'testcase_id': 'TD_COAP_CORE_03_v01',
    }

608

609 610 611 612 613 614
class MsgTestSuiteAbort(Message):
    """
    Testing Tool MUST-implement API endpoint
    GUI (or automated-IUT)-> Testing Tool
    """

615
    routing_key = 'control.testcoordination'
616 617 618 619 620

    _msg_data_template = {
        '_type': 'testcoordination.testsuite.abort',
    }

621

622 623
class MsgTestSuiteGetStatus(Message):
    """
624
    Testing Tool SHOULD-implement API endpoint
625 626 627 628 629 630
    Describes current state of the test suite.
    Format for the response not standardised.

    GUI -> Testing Tool
    """

631
    routing_key = 'control.testcoordination.service'
632 633 634 635 636

    _msg_data_template = {
        '_type': 'testcoordination.testsuite.getstatus',
    }

637

638
class MsgTestSuiteGetStatusReply(MsgReply):
639 640 641 642 643 644 645 646 647 648 649 650 651 652
    """
    Testing Tool SHOULD-implement API endpoint
    Describes current state of the test suite.
    Format for the response not standardised.

    Testing Tool -> GUI

    """

    routing_key = 'control.testcoordination.service.reply'

    _msg_data_template = {
        '_type': 'testcoordination.testsuite.getstatus.reply',
        'ok': True,
653 654 655 656 657
        "started": True,
        "testcase_id": "TD_COAP_CORE_01_v01",
        "testcase_state": "executing",
        "step_id": "TD_COAP_CORE_01_v01_step_01"

658 659
    }

660

661 662
class MsgTestSuiteGetTestCases(Message):
    """
663
    Testing Tool's MUST-implement API endpoint
664 665 666 667
    GUI -> Testing Tool
    GUI MUST implement
    """

668
    routing_key = 'control.testcoordination.service'
669 670 671 672 673

    _msg_data_template = {
        '_type': 'testcoordination.testsuite.gettestcases',
    }

674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 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 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750

class MsgTestSuiteGetTestCasesReply(MsgReply):
    """
    Testing Tool's MUST-implement API endpoint
    Testing Tool -> GUI
    """

    routing_key = 'control.testcoordination.service.reply'

    _msg_data_template = {
        '_type': 'testcoordination.testsuite.gettestcases.reply',
        'ok': True,
        "tc_list": [
            {
                "testcase_id": "TD_COAP_CORE_01_v01",
                "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_01_v01",
                "objective": "Perform GET transaction(CON mode)",
                "state": None
            },
            {
                "testcase_id": "TD_COAP_CORE_02_v01",
                "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_02_v01",
                "objective": "Perform DELETE transaction (CON mode)",
                "state": None
            },
            {
                "testcase_id": "TD_COAP_CORE_03_v01",
                "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_03_v01",
                "objective": "Perform PUT transaction (CON mode)",
                "state": None
            }
        ]
    }


class MsgTestCaseVerdict(Message):
    """
    Testing Tool MUST-implement notification.
    Testing Tool -> GUI

    Used to indicate to the GUI (or automated-iut) which is the final verdict of the testcase.
    """

    routing_key = 'control.testcoordination'

    _msg_data_template = {
        "_type": "testcoordination.testcase.verdict",
        "verdict": "pass",
        "description": "No interoperability error was detected,",
        "partial_verdicts": [
            ["TD_COAP_CORE_01_v01_step_02", None, "CHECK postponed", ""],
            ["TD_COAP_CORE_01_v01_step_03", None, "CHECK postponed", ""],
            ["TD_COAP_CORE_01_v01_step_04", "pass",
             "VERIFY step: User informed that the information was displayed correclty on his/her IUT", ""],
            ["CHECK_1_post_mortem_analysis", "pass",
             "<Frame   3: [bbbb::1 -> bbbb::2] CoAP [CON 43211] GET /test> Match: CoAP(type=0, code=1)"],
            ["CHECK_2_post_mortem_analysis", "pass",
             "<Frame   4: [bbbb::2 -> bbbb::1] CoAP [ACK 43211] 2.05 Content > Match: CoAP(code=69, mid=0xa8cb, tok=b'', pl=Not(b''))"],
            ["CHECK_3_post_mortem_analysis", "pass",
             "<Frame   4: [bbbb::2 -> bbbb::1] CoAP [ACK 43211] 2.05 Content > Match: CoAP(opt=Opt(CoAPOptionContentFormat()))"]],
        "testcase_id": "TD_COAP_CORE_01_v01",
        "testcase_ref": "http://f-interop.paris.inria.fr/tests/TD_COAP_CORE_01_v01",
        "objective": "Perform GET transaction(CON mode)", "state": "finished"
    }


class MsgTestSuiteReport(Message):
    """
    Testing Tool MUST-implement notification.
    Testing Tool -> GUI

    Used to indicate to the GUI (or automated-iut) the final results of the test session.
    """

    routing_key = 'control.testcoordination'

    _msg_data_template = {
751
        "_type": "testcoordination.testsuite.report",
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
        "TD_COAP_CORE_01_v01":
            {
                "verdict": "pass",
                "description": "No interoperability error was detected,",
                "partial_verdicts":
                    [
                        ["TD_COAP_CORE_01_v01_step_02", None, "CHECK postponed", ""],
                        ["TD_COAP_CORE_01_v01_step_03", None, "CHECK postponed", ""],
                        ["TD_COAP_CORE_01_v01_step_04", "pass",
                         "VERIFY step: User informed that the information was displayed correclty on his/her IUT", ""],
                        ["CHECK_1_post_mortem_analysis", "pass",
                         "<Frame   3: [bbbb::1 -> bbbb::2] CoAP [CON 43211] GET /test> Match: CoAP(type=0, code=1)"],
                        ["CHECK_2_post_mortem_analysis", "pass",
                         "<Frame   4: [bbbb::2 -> bbbb::1] CoAP [ACK 43211] 2.05 Content > Match: CoAP(code=69, mid=0xa8cb, tok=b'', pl=Not(b''))"],
                        [
                            "CHECK_3_post_mortem_analysis",
                            "pass",
                            "<Frame   4: [bbbb::2 -> bbbb::1] CoAP [ACK 43211] 2.05 Content > Match: CoAP(opt=Opt(CoAPOptionContentFormat()))"]
                    ]
            },

        "TD_COAP_CORE_02_v01":
            {
                "verdict": "pass",
                "description": "No interoperability error was detected,",
                "partial_verdicts": [
                    ["TD_COAP_CORE_02_v01_step_02", None, "CHECK postponed", ""],
                    ["TD_COAP_CORE_02_v01_step_03", None, "CHECK postponed", ""],
                    ["TD_COAP_CORE_02_v01_step_04", "pass",
                     "VERIFY step: User informed that the information was displayed correclty on his/her IUT",
                     ""], ["CHECK_1_post_mortem_analysis", "pass",
                           "<Frame   3: [bbbb::1 -> bbbb::2] CoAP [CON 43213] DELETE /test> Match: CoAP(type=0, code=4)"],
                    ["CHECK_2_post_mortem_analysis", "pass",
                     "<Frame   4: [bbbb::2 -> bbbb::1] CoAP [ACK 43213] 2.02 Deleted > Match: CoAP(code=66, mid=0xa8cd, tok=b'')"]]
            }
    }

789

790 791 792 793 794 795 796 797 798
###### SNIFFING SERVICES REQUEST MESSAGES ######

class MsgSniffingStart(Message):
    """
    Testing Tools'internal call.
    Coordinator -> Sniffer
    Testing Tool SHOULD implement (design recommendation)
    """

799
    routing_key = 'control.sniffing.service'
800 801 802 803 804 805 806 807

    _msg_data_template = {
        '_type': 'sniffing.start',
        'capture_id': 'TD_COAP_CORE_01',
        'filter_if': 'tun0',
        'filter_proto': 'udp port 5683'
    }

808

809 810 811 812 813 814 815 816 817 818 819 820 821 822
class MsgSniffingStartReply(MsgReply):
    """
    Testing Tools'internal call.
    Sniffer -> Coordinator
    Testing Tool SHOULD implement (design recommendation)
    """

    routing_key = 'control.sniffing.service.reply'

    _msg_data_template = {
        '_type': 'sniffing.start.reply',
        'ok': True
    }

823

824 825 826 827 828 829 830
class MsgSniffingStop(Message):
    """
    Testing Tools'internal call.
    Coordinator -> Sniffer
    Testing Tool SHOULD implement (design recommendation)
    """

831
    routing_key = 'control.sniffing.service'
832 833 834 835 836

    _msg_data_template = {
        '_type': 'sniffing.stop',
    }

837

838 839 840 841 842 843 844 845 846 847 848 849 850 851
class MsgSniffingStoptReply(MsgReply):
    """
    Testing Tools'internal call.
    Sniffer -> Coordinator
    Testing Tool SHOULD implement (design recommendation)
    """

    routing_key = 'control.sniffing.service.reply'

    _msg_data_template = {
        '_type': 'sniffing.stop.reply',
        'ok': True
    }

852

853 854 855 856 857 858 859
class MsgSniffingGetCapture(Message):
    """
    Testing Tools'internal call.
    Coordinator -> Sniffer
    Testing Tool SHOULD implement (design recommendation)
    """

860
    routing_key = 'control.sniffing.service'
861 862 863 864 865 866 867

    _msg_data_template = {
        '_type': 'sniffing.getcapture',
        "capture_id": "TD_COAP_CORE_01",

    }

868

869
class MsgSniffingGetCaptureReply(MsgReply):
870 871 872 873 874 875 876 877 878 879
    routing_key = 'control.sniffing.service.reply'

    _msg_data_template = {
        '_type': 'sniffing.getcapture.reply',
        'ok': True,
        'file_enc': 'pcap_base64',
        'filename': 'TD_COAP_CORE_01.pcap',
        'value': '1MOyoQIABAAAAAAAAAAAAMgAAAAAAAAA',  # empty PCAP
    }

880

881 882 883 884 885 886 887
class MsgSniffingGetCaptureLast(Message):
    """
    Testing Tools'internal call.
    Coordinator -> Sniffer
    Testing Tool SHOULD implement (design recommendation)
    """

888
    routing_key = 'control.sniffing.service'
889 890 891 892

    _msg_data_template = {
        '_type': 'sniffing.getlastcapture',
    }
893

894

895
class MsgSniffingGetCaptureLastReply(MsgReply):
896 897 898 899 900 901 902 903 904 905
    routing_key = 'control.sniffing.service.reply'

    _msg_data_template = {
        '_type': 'sniffing.getlastcapture.reply',
        'ok': True,
        'file_enc': 'pcap_base64',
        'filename': 'TD_COAP_CORE_01.pcap',
        'value': '1MOyoQIABAAAAAAAAAAAAMgAAAAAAAAA',  # empty PCAP
    }

906 907

###### ANALYSIS MESSAGES ######
908

909
class MsgInteropTestCaseAnalyze(Message):
910 911
    """
    Testing Tools'internal call.
912 913 914 915 916 917

    Method to launch an analysis from a pcap file or a token if the pcap file has already been provided.
    # TODO token support

    The method need a token or a pcap_file but doesn't allow someone to provide both.

918
    Coordinator -> Analyzer
919

920 921 922 923 924
    Testing Tool SHOULD implement (design recommendation)
    """

    PCAP_empty_base64 = '1MOyoQIABAAAAAAAAAAAAMgAAAAAAAAA'

925
    routing_key = 'control.analysis.service'
926 927

    _msg_data_template = {
928
        '_type': 'analysis.interop.testcase.analyze',
929
        "testcase_id": "TD_COAP_CORE_01",
930
        "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_01_v01",
931 932 933 934 935
        "file_enc": "pcap_base64",
        "filename": "TD_COAP_CORE_01.pcap",
        "value": PCAP_empty_base64,
    }

936

937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
class MsgInteropTestCaseAnalyzeReply(MsgReply):
    """
    Testing Tools'internal call.
    Analyzer -> Coordinator
    Testing Tool SHOULD implement (design recommendation)

    The recommended structure for the partial_verdicts field is a list of partial verdicts with the following
    requirements:
     - each one of those elements of the list correspond to one CHECK or VERIFY steps of the test description
     - first value of the list MUST be a "pass", "fail", "inconclusive" or eventually "error" partial verdict (string)
     - the second value MUST be a string with a description of partial verdict (intended for the user)
     - more values elements MAY be added to the list

    """

    _msg_data_template = {
953 954
        '_type': 'analysis.interop.testcase.analyze.reply',
        'ok': True,
955 956 957
        'verdict': 'pass',
        'analysis_type': 'postmortem',
        'description': 'The test purpose has been verified without any fault detected',
958 959
        'review_frames': [],
        'token': '0lzzb_Bx30u8Gu-xkt1DFE1GmB4',
960 961 962
        "partial_verdicts": [
            [
                "pass", "<Frame   1: [127.0.0.1 -> 127.0.0.1] CoAP [CON 43521] GET /test> Match: CoAP(type=0, code=1)"
963
            ],
964 965 966 967 968

            [
                "pass",
                "<Frame   2: [127.0.0.1 -> 127.0.0.1] CoAP [ACK 43521] 2.05 Content > Match: CoAP(code=69, mid=0xaa01, \
                tok=b'b\\xda', pl=Not(b''))"
969
            ],
970 971 972 973
            [
                "pass",
                "<Frame   2: [127.0.0.1 -> 127.0.0.1] CoAP [ACK 43521] 2.05 Content > \
                Match: CoAP(opt=Opt(CoAPOptionContentFormat()))"
974
            ]
975 976 977 978 979
        ],
        "testcase_id": "TD_COAP_CORE_01",
        "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_01_v01",
    }

980

981 982
###### DISSECTION MESSAGES ######

983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999
class MsgDissectionDissectCapture(Message):
    """
    Testing Tools'internal call.
    Coordinator -> Dissector
    and
    Analyzer -> Dissector
    Testing Tool SHOULD implement (design recommendation)
    """

    PCAP_COAP_GET_OVER_TUN_INTERFACE_base64 = "1MOyoQIABAAAAAAAAAAAAMgAAABlAAAAqgl9WK8aBgA7AAAAOwAAAGADPxUAExFAu7s" \
                                              "AAAAAAAAAAAAAAAAAAbu7AAAAAAAAAAAAAAAAAALXvBYzABNZUEABcGO0dGVzdMECqg" \
                                              "l9WMcaBgCQAAAAkAAAAGAAAAAAaDr//oAAAAAAAAAAAAAAAAAAA7u7AAAAAAAAAAAAA" \
                                              "AAAAAGJAAcTAAAAALu7AAAAAAAAAAAAAAAAAAK7uwAAAAAAAAAAAAAAAAACBAgAAAAA" \
                                              "AABgAz8VABMRQLu7AAAAAAAAAAAAAAAAAAG7uwAAAAAAAAAAAAAAAAAC17wWMwATWVB" \
                                              "AAXBjtHRlc6oJfVjSGgYAOwAAADsAAABgAz8VABMRP7u7AAAAAAAAAAAAAAAAAAG7uw" \
                                              "AAAAAAAAAAAAAAAAAC17wWMwATWVBAAXBjtHRlc3TBAg=="

1000
    routing_key = 'control.dissection.service'
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010

    _msg_data_template = {
        '_type': 'dissection.dissectcapture',
        "file_enc": "pcap_base64",
        "filename": "TD_COAP_CORE_01.pcap",
        "value": PCAP_COAP_GET_OVER_TUN_INTERFACE_base64,
        "protocol_selection": 'coap',
    }


1011 1012 1013 1014 1015 1016 1017 1018 1019
class MsgDissectionDissectCaptureReply(MsgReply):
    """
    Testing Tools'internal call.
    Dissector -> Coordinator
    and
    Dissector -> Analyzer
    Testing Tool SHOULD implement (design recommendation)
    """

1020
    _frames_example = [
1021 1022 1023 1024
        {
            "_type": "frame",
            "id": 1,
            "timestamp": 1464858393.547275,
1025
            "error": None,
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
            "protocol_stack": [
                {
                    "_type": "protocol",
                    "_protocol": "NullLoopback",
                    "AddressFamily": "2",
                    "ProtocolFamily": "0"
                },
                {
                    "_type": "protocol",
                    "_protocol": "IPv4",
                    "Version": "4",
                    "HeaderLength": "5",
                    "TypeOfService": "0x00",
                    "TotalLength": "41",
                    "Identification": "0x71ac",
                    "Reserved": "0",
                    "DontFragment": "0",
                    "MoreFragments": "0",
                    "FragmentOffset": "0",
                    "TimeToLive": "64",
                    "Protocol": "17",
                    "HeaderChecksum": "0x0000",
                    "SourceAddress": "127.0.0.1",
                    "DestinationAddress": "127.0.0.1",
                    "Options": "b''"
1051
                }
1052 1053 1054
            ]
        },
    ]
1055 1056

    _msg_data_template = {
1057 1058 1059 1060
        '_type': 'dissection.dissectcapture.reply',
        'ok': True,
        'token': '0lzzb_Bx30u8Gu-xkt1DFE1GmB4',
        'frames': _frames_example
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
    }


class MsgDissectionAutoDissect(Message):
    """
    Testing Tool's MUST-implement.
    Testing Tool -> GUI
    GUI MUST display this info during execution:
     - interop session
     - conformance session
     - performance ?
     - privacy?

    """
1075
    routing_key = 'control.dissection'
1076

1077
    _frames_example = MsgDissectionDissectCaptureReply._frames_example
1078 1079

    _msg_data_template = {
1080 1081
        '_type': 'dissection.autotriggered',
        'token': '0lzzb_Bx30u8Gu-xkt1DFE1GmB4',
1082 1083 1084
        'frames': _frames_example,
        "testcase_id": "TBD",
        "testcase_ref": "TBD"
1085 1086
    }

1087

Luca Lamorte's avatar
Luca Lamorte committed
1088 1089 1090 1091 1092 1093
###### PRIVACY TESTING TOOL MESSAGES ######


class MsgPrivacyAnalyze(Message):
    """
        Testing Tool's MUST-implement.
1094
        Analyze PCAP File for Privacy checks.
Luca Lamorte's avatar
Luca Lamorte committed
1095 1096 1097 1098
    """
    routing_key = 'control.privacy.service'

    # TODO: This message should be update with a valuable privacy example
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
    # PCAP_COAP_GET_OVER_TUN_INTERFACE_base64 = "1MOyoQIABAAAAAAAAAAAAMgAAABlAAAAqgl9WK8aBgA7AAAAOwAAAGADPxUAExFAu7s" \
    #                                           "AAAAAAAAAAAAAAAAAAbu7AAAAAAAAAAAAAAAAAALXvBYzABNZUEABcGO0dGVzdMECqg" \
    #                                           "l9WMcaBgCQAAAAkAAAAGAAAAAAaDr//oAAAAAAAAAAAAAAAAAAA7u7AAAAAAAAAAAAA" \
    #                                           "AAAAAGJAAcTAAAAALu7AAAAAAAAAAAAAAAAAAK7uwAAAAAAAAAAAAAAAAACBAgAAAAA" \
    #                                           "AABgAz8VABMRQLu7AAAAAAAAAAAAAAAAAAG7uwAAAAAAAAAAAAAAAAAC17wWMwATWVB" \
    #                                           "AAXBjtHRlc6oJfVjSGgYAOwAAADsAAABgAz8VABMRP7u7AAAAAAAAAAAAAAAAAAG7uw" \
    #                                           "AAAAAAAAAAAAAAAAAC17wWMwATWVBAAXBjtHRlc3TBAg=="

    PCAP_COAP_GET_OVER_TUN_INTERFACE_base64 = "Cg0NCpgAAABNPCsaAQAAAP//////////AwAuAE1hYyBPUyBYIDEwLjEyLjQsIGJ1aWxk" \
                                              "IDE2RTE5NSAoRGFyd2luIDE2LjUuMCkAAAQAPQBEdW1wY2FwIChXaXJlc2hhcmspIDIu" \
                                              "Mi4wICh2Mi4yLjAtMC1nNTM2OGM1MCBmcm9tIG1hc3Rlci0yLjIpAAAAAAAAAJgAAAAB" \
                                              "AAAAXAAAAAAAAAAAAAQAAgAEAHR1bjAJAAEABgAAAAwALgBNYWMgT1MgWCAxMC4xMi40" \
                                              "LCBidWlsZCAxNkUxOTUgKERhcndpbiAxNi41LjApAAAAAAAAXAAAAAUAAABsAAAAAAAA" \
                                              "AIdOBQCsif6eAQAcAENvdW50ZXJzIHByb3ZpZGVkIGJ5IGR1bXBjYXACAAgAh04FAN2Z" \
                                              "ip4DAAgAh04FAKGJ/p4EAAgAAAAAAAAAAAAFAAgAAAAAAAAAAAAAAAAAbAAAAA=="
Luca Lamorte's avatar
Luca Lamorte committed
1114 1115 1116

    _msg_data_template = {
        "_type": "privacy.analyze",
1117
        "value": PCAP_COAP_GET_OVER_TUN_INTERFACE_base64,
Luca Lamorte's avatar
Luca Lamorte committed
1118 1119 1120 1121 1122
        "file_enc": "pcap_base64",
        "filename": "TD_PRIVACY_DEMO_01.pcap",
    }


1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
class MsgPrivacyAnalyzeReply(MsgReply):
    """
            Testing Tool's MUST-implement.
            Response of Analyze request from GUI
    """

    _privacy_empty_report = {'type': 'Anomalies Report',
                             'protocols': ['coap'],
                             'conversation': [],
                             'status': 'none',
                             'testing_tool': 'Privacy Testing Tool',
                             'byte_exchanged': 0,
                             'timestamp': 1493798811.53124,
                             'is_final': True,
                             'packets': {},
                             'version': '0.0.1'}


    _msg_data_template = {
        '_type': 'privacy.analyze.reply',
        'ok': True,
        'verdict': _privacy_empty_report,
        'testcase_id': 'TBD',
    }

Luca Lamorte's avatar
Luca Lamorte committed
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
class MsgPrivacyGetConfiguration(Message):
    """
           Read Privacy configuration.
           GUI MUST display this info during setup
    """
    routing_key = 'control.privacy.service'

    _msg_data_template = {
        "_type": "privacy.configuration.get",
    }

1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171
class MsgPrivacyGetConfigurationReply(MsgReply):
    """
           Read Privacy configuration.
           GUI MUST display this info during setup
    """
    routing_key = 'control.privacy.service.reply'

    _msg_data_template = {
        "_type": "privacy.configuration.get.reply",
        "configuration" : {},
        "ok": True,
    }

Luca Lamorte's avatar
Luca Lamorte committed
1172 1173 1174 1175 1176 1177 1178 1179

class MsgPrivacySetConfiguration(Message):
    """
        Write Privacy configuration.
        GUI MUST display this info during setup
    """
    routing_key = 'control.privacy.service'

1180
    CFG_EXAMPLE = dict()
Luca Lamorte's avatar
Luca Lamorte committed
1181 1182 1183 1184 1185 1186 1187

    _msg_data_template = {
        "_type": "privacy.configuration.set",
        "configuration": CFG_EXAMPLE,
    }


1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
class MsgPrivacySetConfigurationReply(MsgReply):
    """
        Write Privacy configuration.
        GUI MUST display this info during setup
    """
    routing_key = 'control.privacy.service.reply'

    _msg_data_template = {
        "_type": "privacy.configuration.set.reply",
        "ok": True,
    }


Luca Lamorte's avatar
Luca Lamorte committed
1201 1202 1203
class MsgPrivacyGetStatus(Message):
    """
    Testing Tool's MUST-implement.
1204
    GUI -> Testing Tool
Luca Lamorte's avatar
Luca Lamorte committed
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
    GUI MUST display this info during execution:
     - privacy?

    """
    routing_key = 'control.privacy.service'

    _msg_data_template = {
        "_type": "privacy.getstatus",
    }


1216
class MsgPrivacyGetStatusReply(MsgReply):
Luca Lamorte's avatar
Luca Lamorte committed
1217 1218
    """
    Testing Tool's MUST-implement.
1219
    GUI -> Testing Tool
Luca Lamorte's avatar
Luca Lamorte committed
1220 1221 1222 1223 1224 1225
    GUI MUST display this info during execution:
     - privacy?

    """

    REPORT_EXAMPLE = dict()
1226
    routing_key = 'control.privacy.service.reply'
Luca Lamorte's avatar
Luca Lamorte committed
1227 1228 1229 1230

    _msg_data_template = {
        "_type": "privacy.getstatus.reply",
        "verdict": REPORT_EXAMPLE,
1231
        "status": "TBD",
Luca Lamorte's avatar
Luca Lamorte committed
1232 1233 1234 1235
        "ok": True,

    }

1236 1237 1238
class MsgPrivacyIssue(Message):
    """
        Testing Tool's MUST-implement.
Federico Sismondi's avatar
Federico Sismondi committed
1239
        Testing tools -> GUI
1240 1241
        GUI MUST display this info during execution:
         - privacy
Luca Lamorte's avatar
Luca Lamorte committed
1242

1243
        """
1244
    routing_key = 'control.privacy'
Luca Lamorte's avatar
Luca Lamorte committed
1245 1246

    _msg_data_template = {
1247 1248
        "_type": "privacy.issue",
        "verdict":  json.dumps(MsgPrivacyAnalyzeReply._privacy_empty_report),
Luca Lamorte's avatar
Luca Lamorte committed
1249 1250
    }

1251 1252

message_types_dict = {
Federico Sismondi's avatar
Federico Sismondi committed
1253 1254
    "tun.start" : MsgAgentTunStart, # TestingTool -> Agent
    "tun.started" : MsgAgentTunStarted, # Agent -> TestingTool
1255 1256
    "testcoordination.testsuite.start": MsgTestSuiteStart,  # GUI -> TestingTool
    "testcoordination.testsuite.finish": MsgTestSuiteFinish,  # GUI -> TestingTool
1257
    "testcoordination.testcase.ready": MsgTestCaseReady,  # TestingTool -> GUI
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
    "testcoordination.testcase.start": MsgTestCaseStart,  # GUI -> TestingTool
    "testcoordination.step.execute": MsgStepExecute,  # TestingTool -> GUI
    "testcoordination.testcase.configuration": MsgTestCaseConfiguration,  # TestingTool -> GUI
    "testcoordination.testcase.stop": MsgTestCaseStop,  # GUI -> TestingTool
    "testcoordination.testcase.restart": MsgTestCaseRestart,  # GUI -> TestingTool
    "testcoordination.step.stimuli.executed": MsgStimuliExecuted,  # GUI -> TestingTool
    "testcoordination.step.check.response": MsgCheckResponse,  # GUI -> TestingTool
    "testcoordination.step.verify.response": MsgVerifyResponse,  # GUI -> TestingTool
    "testcoordination.testcase.skip": MsgTestCaseSkip,  # GUI -> TestingTool
    "testcoordination.testcase.select": MsgTestCaseSelect,  # GUI -> TestingTool
    "testcoordination.testcase.finish": MsgTestCaseFinish,  # GUI -> TestingTool
    "testcoordination.testcase.finished": MsgTestCaseFinished,  # TestingTool -> GUI
    "testcoordination.testcase.verdict": MsgTestCaseVerdict,  # TestingTool -> GUI
    "testcoordination.testsuite.abort": MsgTestSuiteAbort,  # GUI -> TestingTool
    "testcoordination.testsuite.getstatus": MsgTestSuiteGetStatus,  # GUI -> TestingTool
    "testcoordination.testsuite.getstatus.reply": MsgTestSuiteGetStatusReply,  # TestingTool -> GUI (reply)
    "testcoordination.testsuite.gettestcases": MsgTestSuiteGetTestCases,  # GUI -> TestingTool
    "testcoordination.testsuite.gettestcases.reply": MsgTestSuiteGetTestCasesReply,  # TestingTool -> GUI (reply)
    "testcoordination.testsuite.report": MsgTestSuiteReport,  # TestingTool -> GUI
    "sniffing.start": MsgSniffingStart,  # Testing Tool Internal
    "sniffing.stop": MsgSniffingStop,  # Testing Tool Internal
1279 1280 1281 1282 1283 1284
    "sniffing.getcapture": MsgSniffingGetCapture,  # Testing Tool Internal
    "sniffing.getlastcapture": MsgSniffingGetCaptureLast,  # Testing Tool Internal
    "analysis.interop.testcase.analyze": MsgInteropTestCaseAnalyze,  # Testing Tool Internal
    "analysis.interop.testcase.analyze.reply": MsgInteropTestCaseAnalyzeReply,  # Testing Tool Internal
    "dissection.dissectcapture": MsgDissectionDissectCapture,  # Testing Tool Internal
    "dissection.dissectcapture.reply": MsgDissectionDissectCaptureReply,  # Testing Tool Internal
1285 1286 1287 1288 1289
    "dissection.autotriggered": MsgDissectionAutoDissect,  # TestingTool -> GUI
    "testingtool.component.ready": MsgTestingToolComponentReady,  # Testing Tool internal
    "testingtool.component.shutdown": MsgTestingToolComponentShutdown,  # Testing Tool internal
    "testingtool.ready": MsgTestingToolReady,  # GUI Testing Tool -> GUI
    "testingtool.terminate": MsgTestingToolTerminate,  # GUI (or Orchestrator?) -> TestingTool
Luca Lamorte's avatar
Luca Lamorte committed
1290 1291
    # PRIVACY TESTING TOOL -> Reference: Luca Lamorte (UL)
    "privacy.analyze": MsgPrivacyAnalyze, # TestingTool internal
1292
    "privacy.analyze.reply": MsgPrivacyAnalyzeReply, # TestingTool internal (reply)
Luca Lamorte's avatar
Luca Lamorte committed
1293 1294
    "privacy.getstatus":  MsgPrivacyGetStatus, # GUI -> TestingTool
    "privacy.getstatus.reply":  MsgPrivacyGetStatusReply, # GUI -> TestingTool (reply)
1295
    "privacy.issue":  MsgPrivacyIssue, # TestingTool -> GUI,
Luca Lamorte's avatar
Luca Lamorte committed
1296
    "privacy.configuration.get":  MsgPrivacyGetConfiguration, # TestingTool -> GUI,
1297
    "privacy.configuration.get.reply":  MsgPrivacyGetConfigurationReply, # TestingTool -> GUI (reply),
Luca Lamorte's avatar
Luca Lamorte committed
1298
    "privacy.configuration.set":  MsgPrivacySetConfiguration, # GUI -> TestingTool,
1299
    "privacy.configuration.set.reply":  MsgPrivacySetConfigurationReply, # GUI -> TestingTool (reply),
1300 1301 1302 1303 1304 1305 1306 1307 1308
}

if __name__ == '__main__':
    # m1=MsgTestCaseStart()
    # print(json.dumps(m1.to_dict()))
    # print(m1.routing_key)
    # print(m1.to_json())
    # print(m1)

1309
    m1 = MsgTestCaseStart(hola='verano')
1310
    m2 = MsgTestCaseStart()
1311
    # m2 = MsgTestCaseStart(routing_key = 'lolo', hola='verano')
1312 1313 1314

    print(m1)
    print(m1._msg_data)
1315 1316 1317 1318 1319
    j = m1.to_json()
    print(j)
    deco = Message.from_json(j)
    print(repr(deco))

1320 1321 1322
    print(m2)
    print(m2.to_json())
    print(m2._msg_data)
1323

1324
    m2 = MsgTestSuiteStart()
1325 1326 1327 1328 1329
    print(json.dumps(m2.to_dict()))
    print(m2.routing_key)
    print(m2.to_json())
    print(m2)

1330
    m3 = MsgTestCaseStop()
1331 1332 1333 1334
    print(json.dumps(m3.to_dict()))
    print(m3.routing_key)
    print(m3.to_json())
    print(m3)
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345

    j = json.dumps({
        '_type': 'dissection.dissectcapture',
        "file_enc": "pcap_base64",
        "filename": "TD_COAP_CORE_01.pcap",
        "protocol_selection": 'coap',
    })
    r = Message.from_json(j)
    print(type(r))
    print(r)

1346 1347 1348
    m = MsgTestCaseSkip()
    print(m)
    print(
1349 1350 1351
            m.routing_key,
            m.message_id,
            m.testcase_id,
1352
    )
1353
    m = MsgTestCaseSkip(testcase_id='TD_COAP_CORE_03_v01')
1354 1355 1356 1357
    print(
            m.testcase_id,
            m.to_json(),
    )
1358
    m = MsgTestSuiteStart()
1359 1360
    m.to_json()
    json_message = m.to_json()
1361
    obj = Message.from_json(json_message)
1362 1363
    type(obj)

1364
    # build responses from requests
1365 1366 1367
    m = MsgSniffingStart()
    err = MsgErrorReply(m)
    print(
1368 1369 1370 1371 1372
            err,
            m.reply_to,
            err.routing_key,
            m.message_id,
            m.correlation_id,
1373 1374 1375
    )

    import doctest
1376

1377
    doctest.testmod()