messages.py 23.3 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 67 68 69 70
"""

from collections import OrderedDict
import json
import uuid
import logging

71
API_VERSION = '0.1.6'
72 73

# TODO use metaclasses instead?
74
# TODO Define also a reply method which provides amessage with routig key for the reply, correlation id, reply_to,etc
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92


class NonCompliantMessageFormatError(Exception):

    def __init__(self, value):
        self.value = value

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

class Message:

    def __init__(self,**kwargs):
        global API_VERSION

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

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

99 100 101 102 103 104
        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:
                pass
105

106 107 108 109 110 111 112 113 114 115
        # rewrite default metadata and data fields of the message instance
        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])

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

120 121 122

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

127
        # for readability
128 129 130 131 132 133
        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:
            resp.move_to_end('_type',False)
134 135 136 137 138 139

        return resp

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

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

146
    def __str__(self):
147
        str = ' - '*20 + '\n'
148 149 150 151
        str += 'Message routing key: %s' %self.routing_key
        str += '\n'
        str += 'Message properties: %s'%json.dumps(self.get_properties())
        str += '\n'
152 153 154 155 156 157
        str += 'Message body: %s' %self.to_json()
        str += '\n' + ' - ' * 20
        return str

    @classmethod
    def from_json(cls, body):
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
        """
        :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
            raise NotImplementedError()

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

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

190

191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
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
    """
    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'):
            self._msg_data_template= {
                '_type' : request_message._type,
                'ok' : True,
            }

        super().__init__(**kwargs)

        # override correlation id template and attribute
        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

    """

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


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

class MsgSessionTerminate(Message):
    """
    Testing Tool MUST-implement API endpoint
    GUI, (or Orchestrator?) -> Testing Tool
    Testing tool should stop all it's processes gracefully.
    """
    routing_key = 'control.session.terminate'

    _msg_data_template = {
        '_type': 'session.terminate',
    }

246 247 248 249 250 251 252 253
###### TEST COORDINATION MESSAGES ######

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

254
    routing_key = "control.testcoordination"
255 256 257 258 259 260 261 262 263 264 265 266

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


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)
    """
267
    routing_key = "control.testcoordination"
268 269 270 271 272 273 274 275 276 277 278 279 280

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


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

281
    routing_key = 'control.testcoordination'
282 283 284 285 286 287 288 289 290 291 292 293

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


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

294
    routing_key = 'control.testcoordination'
295 296 297 298 299 300 301 302 303 304 305 306 307

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

#TODO step.execute event

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

308
    routing_key = 'control.testcoordination'
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323

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

324 325
    routing_key = 'control.testcoordination'

326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
    _msg_data_template = {
        '_type': 'testcoordination.step.check.response',
        'partial_verdict':'pass',
        'description':'TAT says: step complies (checks) with specification'
    }


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

341
    routing_key = 'control.testcoordination'
342 343 344 345 346 347 348 349 350 351 352 353 354 355

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

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

356
    routing_key = 'control.testcoordination'
357 358 359 360 361 362 363 364 365 366 367

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

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

368
    routing_key = 'control.testcoordination'
369 370 371 372 373 374 375 376 377 378 379 380 381

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

382
    routing_key = 'control.testcoordination'
383 384 385 386 387 388 389 390 391 392 393 394

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

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

395
    routing_key = 'control.testcoordination'
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411

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

class MsgTestSuiteGetStatus(Message):
    """
    Testing Tool SHOULD-implement API entrypoint
    Describes current state of the test suite.
    Format for the response not standardised.

    GUI -> Testing Tool

    GUI MUST implement
    """

412
    routing_key = 'control.testcoordination.service'
413 414 415 416 417

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

418 419 420 421
class MsgTestSuiteGetStatusReply(MsgReply):
    # TODO implement
    pass

422 423 424 425 426 427 428
class MsgTestSuiteGetTestCases(Message):
    """
    Testing Tool's MUST-implement API entrypoint
    GUI -> Testing Tool
    GUI MUST implement
    """

429
    routing_key = 'control.testcoordination.service'
430 431 432 433 434

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

435 436 437 438
class MsgTestSuiteGetTestCasesReply(Message):
    # TODO implement
    pass

439 440 441 442 443 444 445 446 447
###### SNIFFING SERVICES REQUEST MESSAGES ######

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

448
    routing_key = 'control.sniffing.service'
449 450 451 452 453 454 455 456

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

457 458 459 460 461 462 463 464 465 466 467 468 469 470
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
    }

471 472 473 474 475 476 477
class MsgSniffingStop(Message):
    """
    Testing Tools'internal call.
    Coordinator -> Sniffer
    Testing Tool SHOULD implement (design recommendation)
    """

478
    routing_key = 'control.sniffing.service'
479 480 481 482 483

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

484 485 486 487 488 489 490 491 492 493 494 495 496 497
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
    }

498 499 500 501 502 503 504
class MsgSniffingGetCapture(Message):
    """
    Testing Tools'internal call.
    Coordinator -> Sniffer
    Testing Tool SHOULD implement (design recommendation)
    """

505
    routing_key = 'control.sniffing.service'
506 507 508 509 510 511 512

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

    }

513 514 515 516
class MsgSniffingGetCaptureReply(MsgReply):
    # TODO implement
    pass

517 518 519 520 521 522 523
class MsgSniffingGetCaptureLast(Message):
    """
    Testing Tools'internal call.
    Coordinator -> Sniffer
    Testing Tool SHOULD implement (design recommendation)
    """

524
    routing_key ='control.sniffing.service'
525 526 527 528

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

530 531 532 533 534
class MsgSniffingGetCaptureLastReply(MsgReply):
    # TODO implement
    pass

###### ANALYSIS MESSAGES ######
535

536
class MsgInteropTestCaseAnalyze(Message):
537 538 539 540 541 542 543 544
    """
    Testing Tools'internal call.
    Coordinator -> Analyzer
    Testing Tool SHOULD implement (design recommendation)
    """

    PCAP_empty_base64 = '1MOyoQIABAAAAAAAAAAAAMgAAAAAAAAA'

545
    routing_key = 'control.analysis.service'
546 547

    _msg_data_template = {
548
        '_type': 'analysis.interop.testcase.analyze',
549
        "testcase_id": "TD_COAP_CORE_01",
550
        "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_01_v01",
551 552 553 554 555
        "file_enc": "pcap_base64",
        "filename": "TD_COAP_CORE_01.pcap",
        "value": PCAP_empty_base64,
    }

556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
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 = {
        '_type' : 'analysis.interop.testcase.analyze.reply',
        'ok' : True,
        'verdict': 'pass',
        'analysis_type': 'postmortem',
        'description': 'The test purpose has been verified without any fault detected',
        'review_frames':[],
        'token' : '0lzzb_Bx30u8Gu-xkt1DFE1GmB4',
        "partial_verdicts": [
            [
                "pass", "<Frame   1: [127.0.0.1 -> 127.0.0.1] CoAP [CON 43521] GET /test> Match: CoAP(type=0, code=1)"
             ],

            [
                "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''))"
             ],
            [
                "pass",
                "<Frame   2: [127.0.0.1 -> 127.0.0.1] CoAP [ACK 43521] 2.05 Content > \
                Match: CoAP(opt=Opt(CoAPOptionContentFormat()))"
             ]
        ],
        "testcase_id": "TD_COAP_CORE_01",
        "testcase_ref": "http://doc.f-interop.eu/tests/TD_COAP_CORE_01_v01",
    }

###### DISSECTION MESSAGES ######

601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
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=="

618
    routing_key = 'control.dissection.service'
619 620 621 622 623 624 625 626 627 628

    _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',
    }


629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 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
class MsgDissectionDissectCaptureReply(MsgReply):
    """
    Testing Tools'internal call.
    Dissector -> Coordinator
    and
    Dissector -> Analyzer
    Testing Tool SHOULD implement (design recommendation)
    """

    frames_example = \
    """"frames": [
        {
            "_type": "frame",
            "id": 1,
            "timestamp": 1464858393.547275,
            "error": null,
            "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''"
                  }
        }
    ]"""


    _msg_data_template = {
        '_type' : 'dissection.dissectcapture.reply',
        'ok' : True,
        'token' : '0lzzb_Bx30u8Gu-xkt1DFE1GmB4',
        'frames' : frames_example
    }


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

    """
    event_r_key = 'control.dissection.auto'

    frames_example = MsgDissectionDissectCaptureReply.frames_example

    _msg_data_template = {
        '_type' : 'dissection.autotriggered',
        'token' : '0lzzb_Bx30u8Gu-xkt1DFE1GmB4',
        'frames' : frames_example
    }


message_types_dict = {
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
    "testcoordination.testsuite.start": MsgTestSuiteStart,
    "testcoordination.testcase.start": MsgTestCaseStart,
    "testcoordination.testcase.stop": MsgTestCaseStop,
    "testcoordination.testcase.restart": MsgTestCaseRestart,
    "testcoordination.step.stimuli.executed": MsgStimuliExecuted,
    "testcoordination.step.check.response": MsgCheckResponse,
    "testcoordination.step.verify.response": MsgVerifyResponse,
    "testcoordination.testcase.finish": MsgTestCaseFinish,
    "testcoordination.testcase.skip": MsgTestCaseSkip,
    "testcoordination.testcase.select": MsgTestCaseSelect,
    "testcoordination.testsuite.abort": MsgTestSuiteAbort,
    "testcoordination.testsuite.getstatus": MsgTestSuiteGetStatus,
    "testcoordination.testsuite.gettestcases": MsgTestSuiteGetTestCases,
    "sniffing.start": MsgSniffingStart,
    "sniffing.stop": MsgSniffingStop,
    "sniffing.getcapture": MsgSniffingGetCapture,
722 723 724
    "sniffing.getlastcapture": MsgSniffingGetCaptureLast,
    "analysis.interop.testcase.analyze": MsgInteropTestCaseAnalyze,
    "analysis.interop.testcase.analyze.reply": MsgInteropTestCaseAnalyzeReply,
725
    "dissection.dissectcapture": MsgDissectionDissectCapture,
726 727
    "reply.error" : MsgErrorReply,
    "session.terminate" : MsgSessionTerminate,
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
}


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

    m1 = MsgTestCaseStart( hola = 'verano')
    m2 = MsgTestCaseStart()
    #m2 = MsgTestCaseStart(routing_key = 'lolo', hola='verano')

    print(m1)
    print(m1._msg_data)
744 745 746 747 748
    j = m1.to_json()
    print(j)
    deco = Message.from_json(j)
    print(repr(deco))

749 750 751 752

    print(m2)
    print(m2.to_json())
    print(m2._msg_data)
753 754 755 756 757 758 759 760 761 762 763 764

    m2=MsgTestSuiteStart()
    print(json.dumps(m2.to_dict()))
    print(m2.routing_key)
    print(m2.to_json())
    print(m2)

    m3=MsgTestCaseStop()
    print(json.dumps(m3.to_dict()))
    print(m3.routing_key)
    print(m3.to_json())
    print(m3)
765 766 767 768 769 770 771 772 773 774 775

    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)

776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807

    m = MsgTestCaseSkip()
    print(m)
    print(
        m.routing_key,
        m.message_id,
        m.testcase_id,
    )
    m = MsgTestCaseSkip(testcase_id = 'TD_COAP_CORE_03_v01')
    print(
            m.testcase_id,
            m.to_json(),
    )
    m=MsgTestSuiteStart()
    m.to_json()
    json_message = m.to_json()
    obj=Message.from_json(json_message)
    type(obj)

    #build responses from requests
    m = MsgSniffingStart()
    err = MsgErrorReply(m)
    print(
        err,
        m.reply_to,
        err.routing_key,
        m.message_id,
        m.correlation_id,
    )

    import doctest
    doctest.testmod()