report_service.py 6.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # SPDX-License-Identifier: Apache-2.0
  2. # Copyright 2020 Contributors to OpenLEADR
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. from . import service, handler, VTNService
  13. # ╔══════════════════════════════════════════════════════════════════════════╗
  14. # ║ REPORT SERVICE ║
  15. # ╚══════════════════════════════════════════════════════════════════════════╝
  16. # ┌──────────────────────────────────────────────────────────────────────────┐
  17. # │ The VEN can register its reporting capabilities. │
  18. # │ │
  19. # │ ┌────┐ ┌────┐ │
  20. # │ │VEN │ │VTN │ │
  21. # │ └─┬──┘ └─┬──┘ │
  22. # │ │───────────────oadrRegisterReport(METADATA Report)──────────────▶│ │
  23. # │ │ │ │
  24. # │ │◀ ─ ─ ─ ─oadrRegisteredReport(optional oadrReportRequest) ─ ─ ─ ─│ │
  25. # │ │ │ │
  26. # │ │ │ │
  27. # │ │─────────────oadrCreatedReport(if report requested)─────────────▶│ │
  28. # │ │ │ │
  29. # │ │◀ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ oadrResponse()─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─│ │
  30. # │ │ │ │
  31. # │ │
  32. # └──────────────────────────────────────────────────────────────────────────┘
  33. # ┌──────────────────────────────────────────────────────────────────────────┐
  34. # │ A report can also be canceled │
  35. # │ │
  36. # │ ┌────┐ ┌────┐ │
  37. # │ │VEN │ │VTN │ │
  38. # │ └─┬──┘ └─┬──┘ │
  39. # │ │───────────────oadrRegisterReport(METADATA Report)──────────────▶│ │
  40. # │ │ │ │
  41. # │ │◀ ─ ─ ─ ─oadrRegisteredReport(optional oadrReportRequest) ─ ─ ─ ─│ │
  42. # │ │ │ │
  43. # │ │ │ │
  44. # │ │─────────────oadrCreatedReport(if report requested)─────────────▶│ │
  45. # │ │ │ │
  46. # │ │◀ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ oadrResponse()─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─│ │
  47. # │ │ │ │
  48. # │ │
  49. # └──────────────────────────────────────────────────────────────────────────┘
  50. @service('EiReport')
  51. class ReportService(VTNService):
  52. @handler('oadrRegisterReport')
  53. async def register_report(self, payload):
  54. """
  55. Register a reporting type.
  56. """
  57. print("Called Registered Report")
  58. response_type = 'oadrRegisteredReport'
  59. response_payload = {"response": {"response_code": 200,
  60. "response_description": "OK",
  61. "request_id": payload['request_id']},
  62. "ven_id": '123'}
  63. return response_type, response_payload
  64. @handler('oadrRequestReport')
  65. async def request_report(self, payload):
  66. """
  67. Provide the VEN with the latest report.
  68. """
  69. print("Called Request Report")
  70. @handler('oadrUpdateReport')
  71. async def update_report(self, payload):
  72. """
  73. Updates an existing report from this VEN in our database.
  74. """
  75. print("Called Update Report")
  76. @handler('oadrCancelReport')
  77. async def cancel_report(self, payload):
  78. """
  79. Cancels a previously received report from this VEN.
  80. """
  81. print("Called Cancel Report")