Commit 4ee2aa2b authored by Antoine Kaufmann's avatar Antoine Kaufmann
Browse files

lib/netif: refactor identifier names for google style

parent 12cca0cf
......@@ -36,7 +36,7 @@
static uint64_t current_epoch = 0;
int netsim_init(struct netsim_interface *nsif, const char *eth_socket_path,
int SimbricksNetIfInit(struct SimbricksNetIf *nsif, const char *eth_socket_path,
int *sync_eth) {
struct SimbricksProtoNetDevIntro di;
struct SimbricksProtoNetNetIntro ni;
......@@ -85,13 +85,13 @@ int netsim_init(struct netsim_interface *nsif, const char *eth_socket_path,
return 0;
}
void netsim_cleanup(struct netsim_interface *nsif) {
fprintf(stderr, "netsim_cleanup: TODO\n");
void SimbricksNetIfCleanup(struct SimbricksNetIf *nsif) {
fprintf(stderr, "SimbricksNetIfCleanup: TODO\n");
abort();
}
volatile union SimbricksProtoNetD2N *netsim_d2n_poll(
struct netsim_interface *nsif, uint64_t timestamp) {
volatile union SimbricksProtoNetD2N *SimbricksNetIfD2NPoll(
struct SimbricksNetIf *nsif, uint64_t timestamp) {
volatile union SimbricksProtoNetD2N *msg =
(volatile union SimbricksProtoNetD2N *)(nsif->d2n_queue +
nsif->d2n_pos * nsif->d2n_elen);
......@@ -110,15 +110,15 @@ volatile union SimbricksProtoNetD2N *netsim_d2n_poll(
return msg;
}
void netsim_d2n_done(struct netsim_interface *nsif,
void SimbricksNetIfD2NDone(struct SimbricksNetIf *nsif,
volatile union SimbricksProtoNetD2N *msg) {
msg->dummy.own_type =
(msg->dummy.own_type & SIMBRICKS_PROTO_NET_D2N_MSG_MASK) |
SIMBRICKS_PROTO_NET_D2N_OWN_DEV;
}
volatile union SimbricksProtoNetN2D *netsim_n2d_alloc(
struct netsim_interface *nsif, uint64_t timestamp, uint64_t latency) {
volatile union SimbricksProtoNetN2D *SimbricksNetIfN2DAlloc(
struct SimbricksNetIf *nsif, uint64_t timestamp, uint64_t latency) {
volatile union SimbricksProtoNetN2D *msg =
(volatile union SimbricksProtoNetN2D *)(nsif->n2d_queue +
nsif->n2d_pos * nsif->n2d_elen);
......@@ -135,7 +135,7 @@ volatile union SimbricksProtoNetN2D *netsim_n2d_alloc(
return msg;
}
int netsim_n2d_sync(struct netsim_interface *nsif, uint64_t timestamp,
int SimbricksNetIfN2DSync(struct SimbricksNetIf *nsif, uint64_t timestamp,
uint64_t latency, uint64_t sync_delay, int sync_mode) {
volatile union SimbricksProtoNetN2D *msg;
volatile struct SimbricksProtoNetN2DSync *sync;
......@@ -161,7 +161,7 @@ int netsim_n2d_sync(struct netsim_interface *nsif, uint64_t timestamp,
return 0;
}
msg = netsim_n2d_alloc(nsif, timestamp, latency);
msg = SimbricksNetIfN2DAlloc(nsif, timestamp, latency);
if (msg == NULL)
return -1;
......@@ -173,7 +173,7 @@ int netsim_n2d_sync(struct netsim_interface *nsif, uint64_t timestamp,
return 0;
}
void netsim_advance_epoch(uint64_t timestamp, uint64_t sync_delay,
void SimbricksNetIfAdvanceEpoch(uint64_t timestamp, uint64_t sync_delay,
int sync_mode) {
if (sync_mode == SIMBRICKS_PROTO_SYNC_BARRIER) {
if (timestamp - current_epoch >= sync_delay) {
......@@ -182,7 +182,7 @@ void netsim_advance_epoch(uint64_t timestamp, uint64_t sync_delay,
}
}
uint64_t netsim_advance_time(uint64_t timestamp, uint64_t sync_delay,
uint64_t SimbricksNetIfAdvanceTime(uint64_t timestamp, uint64_t sync_delay,
int sync_mode) {
switch (sync_mode) {
case SIMBRICKS_PROTO_SYNC_SIMBRICKS:
......
......@@ -30,7 +30,7 @@
#include <simbricks/proto/network.h>
struct netsim_interface {
struct SimbricksNetIf {
uint8_t *d2n_queue;
size_t d2n_pos;
size_t d2n_elen;
......@@ -46,25 +46,25 @@ struct netsim_interface {
int sync;
};
int netsim_init(struct netsim_interface *nsif, const char *eth_socket_path,
int SimbricksNetIfInit(struct SimbricksNetIf *nsif, const char *eth_socket_path,
int *sync_eth);
void netsim_cleanup(struct netsim_interface *nsif);
void SimbricksNetIfCleanup(struct SimbricksNetIf *nsif);
volatile union SimbricksProtoNetD2N *netsim_d2n_poll(
struct netsim_interface *nsif, uint64_t timestamp);
void netsim_d2n_done(struct netsim_interface *nsif,
volatile union SimbricksProtoNetD2N *SimbricksNetIfD2NPoll(
struct SimbricksNetIf *nsif, uint64_t timestamp);
void SimbricksNetIfD2NDone(struct SimbricksNetIf *nsif,
volatile union SimbricksProtoNetD2N *msg);
static inline uint64_t netsim_d2n_timestamp(struct netsim_interface *nsif) {
static inline uint64_t SimbricksNetIfD2NTimestamp(struct SimbricksNetIf *nsif) {
return nsif->d2n_timestamp;
}
volatile union SimbricksProtoNetN2D *netsim_n2d_alloc(
struct netsim_interface *nsif, uint64_t timestamp, uint64_t latency);
int netsim_n2d_sync(struct netsim_interface *nsif, uint64_t timestamp,
volatile union SimbricksProtoNetN2D *SimbricksNetIfN2DAlloc(
struct SimbricksNetIf *nsif, uint64_t timestamp, uint64_t latency);
int SimbricksNetIfN2DSync(struct SimbricksNetIf *nsif, uint64_t timestamp,
uint64_t latency, uint64_t sync_delay, int sync_mode);
void netsim_advance_epoch(uint64_t timestamp, uint64_t sync_delay,
void SimbricksNetIfAdvanceEpoch(uint64_t timestamp, uint64_t sync_delay,
int sync_mode);
uint64_t netsim_advance_time(uint64_t timestamp, uint64_t sync_delay,
uint64_t SimbricksNetIfAdvanceTime(uint64_t timestamp, uint64_t sync_delay,
int sync_mode);
#endif // SIMBRICKS_NETIF_NETSIM_H_
......@@ -22,6 +22,8 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <simbricks/nicif/nicsim.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -29,8 +31,6 @@
#include <sys/socket.h>
#include <unistd.h>
#include <simbricks/nicif/nicsim.h>
#include "lib/simbricks/nicif/internal.h"
#include <simbricks/proto/base.h>
......
Subproject commit 160793a40cc120da2a3175b62e813bb750683c69
Subproject commit 763b902bbcde6cc675c9210db9abaa2bb3e1c4d4
......@@ -75,7 +75,7 @@ static uint64_t cur_ts = 0;
static int exiting = 0;
static const volatile uint8_t bcast[6] = {0xFF};
static const MAC bcast_addr(bcast);
static std::vector<struct netsim_interface> nsifs;
static std::vector<struct SimbricksNetIf> nsifs;
static std::unordered_map<MAC, int> mac_table;
static void sigint_handler(int dummy) {
......@@ -85,7 +85,7 @@ static void sigint_handler(int dummy) {
static void forward_pkt(volatile struct SimbricksProtoNetD2NSend *tx,
int port) {
volatile union SimbricksProtoNetN2D *msg_to;
msg_to = netsim_n2d_alloc(&nsifs[port], cur_ts, eth_latency);
msg_to = SimbricksNetIfN2DAlloc(&nsifs[port], cur_ts, eth_latency);
if (msg_to != NULL) {
volatile struct SimbricksProtoNetN2DRecv *rx;
rx = &msg_to->recv;
......@@ -101,9 +101,9 @@ static void forward_pkt(volatile struct SimbricksProtoNetD2NSend *tx,
}
}
static void switch_pkt(struct netsim_interface *nsif, int iport) {
static void switch_pkt(struct SimbricksNetIf *nsif, int iport) {
volatile union SimbricksProtoNetD2N *msg_from =
netsim_d2n_poll(nsif, cur_ts);
SimbricksNetIfD2NPoll(nsif, cur_ts);
if (msg_from == NULL) {
return;
}
......@@ -136,7 +136,7 @@ static void switch_pkt(struct netsim_interface *nsif, int iport) {
fprintf(stderr, "switch_pkt: unsupported type=%u\n", type);
abort();
}
netsim_d2n_done(nsif, msg_from);
SimbricksNetIfD2NDone(nsif, msg_from);
}
int main(int argc, char *argv[]) {
......@@ -148,9 +148,9 @@ int main(int argc, char *argv[]) {
while ((c = getopt(argc, argv, "s:S:E:m:")) != -1 && !bad_option) {
switch (c) {
case 's': {
struct netsim_interface nsif;
struct SimbricksNetIf nsif;
int sync = 1;
if (netsim_init(&nsif, optarg, &sync) != 0) {
if (SimbricksNetIfInit(&nsif, optarg, &sync) != 0) {
fprintf(stderr, "connecting to %s failed\n", optarg);
return EXIT_FAILURE;
}
......@@ -193,13 +193,13 @@ int main(int argc, char *argv[]) {
while (!exiting) {
// Sync all interfaces
for (auto &nsif : nsifs) {
if (netsim_n2d_sync(&nsif, cur_ts, eth_latency, sync_period, sync_mode) !=
0) {
fprintf(stderr, "netsim_n2d_sync failed\n");
if (SimbricksNetIfN2DSync(&nsif, cur_ts, eth_latency, sync_period,
sync_mode) != 0) {
fprintf(stderr, "SimbricksNetIfN2DSync failed\n");
abort();
}
}
netsim_advance_epoch(cur_ts, sync_period, sync_mode);
SimbricksNetIfAdvanceEpoch(cur_ts, sync_period, sync_mode);
// Switch packets
uint64_t min_ts;
......@@ -209,7 +209,7 @@ int main(int argc, char *argv[]) {
auto &nsif = nsifs.at(port);
switch_pkt(&nsif, port);
if (nsif.sync) {
uint64_t ts = netsim_d2n_timestamp(&nsif);
uint64_t ts = SimbricksNetIfD2NTimestamp(&nsif);
min_ts = ts < min_ts ? ts : min_ts;
}
}
......@@ -217,7 +217,7 @@ int main(int argc, char *argv[]) {
// Update cur_ts
if (min_ts < ULLONG_MAX) {
cur_ts = netsim_advance_time(min_ts, sync_period, sync_mode);
cur_ts = SimbricksNetIfAdvanceTime(min_ts, sync_period, sync_mode);
}
}
......
......@@ -37,7 +37,7 @@
// #define DEBUG_PKTMETA
static struct netsim_interface nsif;
static struct SimbricksNetIf nsif;
static int tap_fd;
static int tap_open(const char *name) {
......@@ -73,7 +73,7 @@ static void d2n_send(volatile struct SimbricksProtoNetD2NSend *s) {
}
static void poll_d2n(void) {
volatile union SimbricksProtoNetD2N *msg = netsim_d2n_poll(&nsif, 0);
volatile union SimbricksProtoNetD2N *msg = SimbricksNetIfD2NPoll(&nsif, 0);
uint8_t type;
/* message not ready */
......@@ -90,7 +90,7 @@ static void poll_d2n(void) {
fprintf(stderr, "poll_d2n: unsupported type=%u\n", type);
}
netsim_d2n_done(&nsif, msg);
SimbricksNetIfD2NDone(&nsif, msg);
}
static void *rx_handler(void *arg) {
......@@ -99,7 +99,7 @@ static void *rx_handler(void *arg) {
ssize_t len;
while (1) {
msg = netsim_n2d_alloc(&nsif, 0, 0);
msg = SimbricksNetIfN2DAlloc(&nsif, 0, 0);
if (msg == NULL) {
fprintf(stderr, "coudl not allocate message for rx\n");
abort();
......@@ -135,7 +135,7 @@ int main(int argc, char *argv[]) {
}
sync = 0;
if (netsim_init(&nsif, argv[2], &sync) != 0) {
if (SimbricksNetIfInit(&nsif, argv[2], &sync) != 0) {
close(tap_fd);
return -1;
}
......
......@@ -53,10 +53,10 @@ static void sigusr1_handler(int dummy) {
fprintf(stderr, "main_time = %lu\n", cur_ts);
}
static void move_pkt(struct netsim_interface *from,
struct netsim_interface *to) {
static void move_pkt(struct SimbricksNetIf *from,
struct SimbricksNetIf *to) {
volatile union SimbricksProtoNetD2N *msg_from =
netsim_d2n_poll(from, cur_ts);
SimbricksNetIfD2NPoll(from, cur_ts);
volatile union SimbricksProtoNetN2D *msg_to;
volatile struct SimbricksProtoNetD2NSend *tx;
volatile struct SimbricksProtoNetN2DRecv *rx;
......@@ -80,7 +80,7 @@ static void move_pkt(struct netsim_interface *from,
pcap_dump((unsigned char *)dumpfile, &ph, (unsigned char *)tx->data);
}
msg_to = netsim_n2d_alloc(to, cur_ts, eth_latency);
msg_to = SimbricksNetIfN2DAlloc(to, cur_ts, eth_latency);
if (msg_to != NULL) {
rx = &msg_to->recv;
rx->len = tx->len;
......@@ -99,11 +99,11 @@ static void move_pkt(struct netsim_interface *from,
abort();
}
netsim_d2n_done(from, msg_from);
SimbricksNetIfD2NDone(from, msg_from);
}
int main(int argc, char *argv[]) {
struct netsim_interface nsif_a, nsif_b;
struct SimbricksNetIf nsif_a, nsif_b;
uint64_t ts_a, ts_b;
int sync_a, sync_b;
pcap_t *pc = NULL;
......@@ -144,42 +144,42 @@ int main(int argc, char *argv[]) {
sync_mode == SIMBRICKS_PROTO_SYNC_BARRIER);
sync_a = sync_b = 1;
if (netsim_init(&nsif_a, argv[1], &sync_a) != 0) {
if (SimbricksNetIfInit(&nsif_a, argv[1], &sync_a) != 0) {
return -1;
}
if (netsim_init(&nsif_b, argv[2], &sync_b) != 0) {
if (SimbricksNetIfInit(&nsif_b, argv[2], &sync_b) != 0) {
return -1;
}
printf("start polling\n");
while (!exiting) {
if (netsim_n2d_sync(&nsif_a, cur_ts, eth_latency, sync_period, sync_mode) !=
0) {
fprintf(stderr, "netsim_n2d_sync(nsif_a) failed\n");
if (SimbricksNetIfN2DSync(&nsif_a, cur_ts, eth_latency, sync_period,
sync_mode) != 0) {
fprintf(stderr, "SimbricksNetIfN2DSync(nsif_a) failed\n");
abort();
}
if (netsim_n2d_sync(&nsif_b, cur_ts, eth_latency, sync_period, sync_mode) !=
0) {
fprintf(stderr, "netsim_n2d_sync(nsif_a) failed\n");
if (SimbricksNetIfN2DSync(&nsif_b, cur_ts, eth_latency, sync_period,
sync_mode) != 0) {
fprintf(stderr, "SimbricksNetIfN2DSync(nsif_a) failed\n");
abort();
}
netsim_advance_epoch(cur_ts, sync_period, sync_mode);
SimbricksNetIfAdvanceEpoch(cur_ts, sync_period, sync_mode);
do {
move_pkt(&nsif_a, &nsif_b);
move_pkt(&nsif_b, &nsif_a);
ts_a = netsim_d2n_timestamp(&nsif_a);
ts_b = netsim_d2n_timestamp(&nsif_b);
ts_a = SimbricksNetIfD2NTimestamp(&nsif_a);
ts_b = SimbricksNetIfD2NTimestamp(&nsif_b);
} while (!exiting &&
((sync_a && ts_a <= cur_ts) || (sync_b && ts_b <= cur_ts)));
if (sync_a && sync_b)
cur_ts = netsim_advance_time(ts_a <= ts_b ? ts_a : ts_b, sync_period,
sync_mode);
cur_ts = SimbricksNetIfAdvanceTime(ts_a <= ts_b ? ts_a : ts_b,
sync_period, sync_mode);
else if (sync_a)
cur_ts = netsim_advance_time(ts_a, sync_period, sync_mode);
cur_ts = SimbricksNetIfAdvanceTime(ts_a, sync_period, sync_mode);
else if (sync_b)
cur_ts = netsim_advance_time(ts_b, sync_period, sync_mode);
cur_ts = SimbricksNetIfAdvanceTime(ts_b, sync_period, sync_mode);
}
if (dumpfile)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment