1 // Copyright 2021 Google LLC
2 //
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 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <arpa/inet.h>
18 #include <sys/socket.h>
19 
20 #include <cstdint>
21 #include <cstdio>
22 #include <cstring>
23 #include <memory>
24 #include <vector>
25 
26 #define MAC_ADDR_SIZE 6
27 
28 struct MacAddr
29 {
30     std::uint8_t octet[MAC_ADDR_SIZE]; // network order
31 };
32 
33 enum class NemoraDatagramType
34 {
35     NemoraEvent,
36 };
37 
38 /**
39  * Encompasses all valid outbound UDP messages
40  */
41 struct NemoraDatagram
42 {
43     // destination
44     sockaddr_in destination;
45     sockaddr_in6 destination6;
46     // type
47     NemoraDatagramType type;
48     std::vector<uint8_t> payload;
49 };
50 
51 /**
52  * Event information as broadcast to System Health Data Collector
53  */
54 struct NemoraEvent : NemoraDatagram
55 {
56     std::uint8_t mac[MAC_ADDR_SIZE];
57     std::uint64_t sent_time_s;
58     std::vector<uint64_t> postcodes;
59 };
60