"research/inception/README.md" did not exist on "f3d896bdac1bb3bda28fd6a50d83c1ad4e1d2165"
netsim.h 2.48 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
 * Copyright 2020 Max Planck Institute for Software Systems
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef COSIM_NETSIM_H_
#define COSIM_NETSIM_H_

#include <stddef.h>
#include <stdint.h>
#include <cosim_eth_proto.h>

31
32
33
#define SYNC_MODES 0
#define SYNC_BARRIER 1

34
35
36
37
38
struct netsim_interface {
    uint8_t *d2n_queue;
    size_t d2n_pos;
    size_t d2n_elen;
    size_t d2n_enum;
39
    uint64_t d2n_timestamp;
40
41
42
43
44

    uint8_t *n2d_queue;
    size_t n2d_pos;
    size_t n2d_elen;
    size_t n2d_enum;
45
46
47
    uint64_t n2d_timestamp;

    int sync;
48
49
50
51
52
53
54
};

int netsim_init(struct netsim_interface *nsif,
        const char *eth_socket_path, int *sync_eth);
void netsim_cleanup(struct netsim_interface *nsif);

volatile union cosim_eth_proto_d2n *netsim_d2n_poll(
55
        struct netsim_interface *nsif, uint64_t timestamp);
56
57
void netsim_d2n_done(struct netsim_interface *nsif,
        volatile union cosim_eth_proto_d2n *msg);
58
59
60
61
static inline uint64_t netsim_d2n_timestamp(struct netsim_interface *nsif)
{
    return nsif->d2n_timestamp;
}
62
63

volatile union cosim_eth_proto_n2d *netsim_n2d_alloc(
64
65
66
        struct netsim_interface *nsif, uint64_t timestamp,
        uint64_t latency);
int netsim_n2d_sync(struct netsim_interface *nsif, uint64_t timestamp,
67
68
69
        uint64_t latency, uint64_t sync_delay, int sync_mode);
void netsim_advance_epoch(uint64_t timestamp, uint64_t sync_delay, int sync_mode);
uint64_t netsim_advance_time(uint64_t timestamp, uint64_t sync_delay, int sync_mode);
70
71

#endif /* ndef COSIM_NETSIM_H_ */