Skip to content

Commit c436306

Browse files
committed
hello + init msg send/recv
1 parent 93dfb21 commit c436306

File tree

6 files changed

+479
-10
lines changed

6 files changed

+479
-10
lines changed

Makefile.am

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ utils_test_SOURCES = test/utils_test.c test/vec_test.c test/fifo_test.c
2929
utils_test_LDADD = libutils.la
3030
utils_test_CPPFLAGS = $(AM_CPPFLAGS) -Isrc/vector -Isrc/fifo -Itest
3131

32+
#
33+
# perf test
34+
#
35+
perf_test_SOURCES = test/perform/pt.c
36+
perf_test_LDADD = libutils.la
37+
perf_test_CPPFLAGS = $(AM_CPPFLAGS) -Isrc/vector -Isrc/fifo -Itest/perform
38+
3239
#
3340
# main lib
3441
#
@@ -43,7 +50,7 @@ icmp_responder_SOURCES = examples/icmp_responder/main.c
4350
icmp_responder_LDADD = libmemif.la
4451
icmp_responder_CPPFLAGS = $(AM_CPPFLAGS) -Isrc
4552

46-
noinst_PROGRAMS = icmp_responder
53+
noinst_PROGRAMS = icmp_responder perf_test
4754

4855
check_PROGRAMS = utils_test
4956

src/libmemif.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
*------------------------------------------------------------------
1616
*/
1717

18-
#ifndef _MEMIF_H_
19-
#define _MEMIF_H_
18+
#ifndef _LIBMEMIF_H_
19+
#define _LIBMEMIF_H_
2020

2121
#include <inttypes.h>
2222

23-
#include <memif_proto.h>
23+
#include <memif.h>
2424

2525
typedef void* memif_conn_handle_t;
2626

2727
typedef struct
2828
{
2929
uint8_t *socket_filename;
30-
uint8_t *secret;
30+
uint8_t secret[24];
3131

3232
uint8_t num_s2m_rings;
3333
uint8_t num_m2s_rings;
@@ -36,8 +36,8 @@ typedef struct
3636
uint8_t is_master;
3737

3838
uint32_t interface_id;
39-
uint8_t *interface_name;
40-
uint8_t *instance_name;
39+
uint8_t interface_name[32];
40+
uint8_t instance_name[32];
4141
memif_interface_mode_t mode:8;
4242
} memif_conn_args_t;
4343

src/memif.h

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/*
2+
*------------------------------------------------------------------
3+
* Copyright (c) 2017 Cisco and/or its affiliates.
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*------------------------------------------------------------------
16+
*/
17+
18+
#ifndef _MEMIF_H_
19+
#define _MEMIF_H_
20+
21+
#ifndef MEMIF_CACHELINE_SIZE
22+
#define MEMIF_CACHELINE_SIZE 64
23+
#endif
24+
25+
#define MEMIF_COOKIE 0x3E31F10
26+
#define MEMIF_VERSION_MAJOR 1
27+
#define MEMIF_VERSION_MINOR 0
28+
#define MEMIF_VERSION ((MEMIF_VERSION_MAJOR << 8) | MEMIF_VERSION_MINOR)
29+
30+
/*
31+
* Type definitions
32+
*/
33+
34+
typedef enum memif_msg_type
35+
{
36+
MEMIF_MSG_TYPE_NONE = 0,
37+
MEMIF_MSG_TYPE_ACK = 1,
38+
MEMIF_MSG_TYPE_HELLO = 2,
39+
MEMIF_MSG_TYPE_INIT = 3,
40+
MEMIF_MSG_TYPE_ADD_REGION = 4,
41+
MEMIF_MSG_TYPE_ADD_RING = 5,
42+
MEMIF_MSG_TYPE_CONNECT = 6,
43+
MEMIF_MSG_TYPE_CONNECTED = 7,
44+
MEMIF_MSG_TYPE_DISCONNECT = 8,
45+
} memif_msg_type_t;
46+
47+
typedef enum
48+
{
49+
MEMIF_RING_S2M = 0,
50+
MEMIF_RING_M2S = 1
51+
} memif_ring_type_t;
52+
53+
typedef enum
54+
{
55+
MEMIF_INTERFACE_MODE_ETHERNET = 0,
56+
MEMIF_INTERFACE_MODE_IP = 1,
57+
MEMIF_INTERFACE_MODE_PUNT_INJECT = 2,
58+
} memif_interface_mode_t;
59+
60+
typedef uint16_t memif_region_index_t;
61+
typedef uint64_t memif_region_offset_t;
62+
typedef uint64_t memif_region_size_t;
63+
typedef uint16_t memif_ring_index_t;
64+
typedef uint32_t memif_interface_id_t;
65+
typedef uint16_t memif_version_t;
66+
typedef uint8_t memif_log2_ring_size_t;
67+
68+
/*
69+
* Socket messages
70+
*/
71+
72+
typedef struct __attribute__ ((packed))
73+
{
74+
uint8_t name[32];
75+
memif_version_t min_version;
76+
memif_version_t max_version;
77+
memif_region_index_t max_region;
78+
memif_ring_index_t max_m2s_ring;
79+
memif_ring_index_t max_s2m_ring;
80+
memif_log2_ring_size_t max_log2_ring_size;
81+
} memif_msg_hello_t;
82+
83+
typedef struct __attribute__ ((packed))
84+
{
85+
memif_version_t version;
86+
memif_interface_id_t id;
87+
memif_interface_mode_t mode:8;
88+
uint8_t secret[24];
89+
uint8_t name[32];
90+
} memif_msg_init_t;
91+
92+
typedef struct __attribute__ ((packed))
93+
{
94+
memif_region_index_t index;
95+
memif_region_size_t size;
96+
} memif_msg_add_region_t;
97+
98+
typedef struct __attribute__ ((packed))
99+
{
100+
uint16_t flags;
101+
#define MEMIF_MSG_ADD_RING_FLAG_S2M (1 << 0)
102+
memif_ring_index_t index;
103+
memif_region_index_t region;
104+
memif_region_offset_t offset;
105+
memif_log2_ring_size_t log2_ring_size;
106+
} memif_msg_add_ring_t;
107+
108+
typedef struct __attribute__ ((packed))
109+
{
110+
uint8_t if_name[32];
111+
} memif_msg_connect_t;
112+
113+
typedef struct __attribute__ ((packed))
114+
{
115+
uint8_t if_name[32];
116+
} memif_msg_connected_t;
117+
118+
typedef struct __attribute__ ((packed))
119+
{
120+
uint32_t code;
121+
uint8_t string[96];
122+
} memif_msg_disconnect_t;
123+
124+
typedef struct __attribute__ ((packed, aligned (128)))
125+
{
126+
memif_msg_type_t type:16;
127+
union
128+
{
129+
memif_msg_hello_t hello;
130+
memif_msg_init_t init;
131+
memif_msg_add_region_t add_region;
132+
memif_msg_add_ring_t add_ring;
133+
memif_msg_connect_t connect;
134+
memif_msg_connected_t connected;
135+
memif_msg_disconnect_t disconnect;
136+
};
137+
} memif_msg_t;
138+
139+
_Static_assert (sizeof (memif_msg_t) == 128,
140+
"Size of memif_msg_t must be 128");
141+
142+
/*
143+
* Ring and Descriptor Layout
144+
*/
145+
146+
typedef struct __attribute__ ((packed))
147+
{
148+
uint16_t flags;
149+
#define MEMIF_DESC_FLAG_NEXT (1 << 0)
150+
memif_region_index_t region;
151+
uint32_t buffer_length;
152+
uint32_t length;
153+
uint8_t reserved[4];
154+
memif_region_offset_t offset;
155+
uint64_t metadata;
156+
} memif_desc_t;
157+
158+
_Static_assert (sizeof (memif_desc_t) == 32,
159+
"Size of memif_dsct_t must be 32");
160+
161+
#define MEMIF_CACHELINE_ALIGN_MARK(mark) \
162+
uint8_t mark[0] __attribute__((aligned(MEMIF_CACHELINE_SIZE)))
163+
164+
typedef struct
165+
{
166+
MEMIF_CACHELINE_ALIGN_MARK (cacheline0);
167+
uint32_t cookie;
168+
uint16_t flags;
169+
#define MEMIF_RING_FLAG_MASK_INT 1
170+
volatile uint16_t head;
171+
MEMIF_CACHELINE_ALIGN_MARK (cacheline1);
172+
volatile uint16_t tail;
173+
MEMIF_CACHELINE_ALIGN_MARK (cacheline2);
174+
memif_desc_t desc[0];
175+
} memif_ring_t;
176+
177+
#endif /* _MEMIF_H_ */
178+
179+
/*
180+
* fd.io coding-style-patch-verification: ON
181+
*
182+
* Local Variables:
183+
* eval: (c-set-style "gnu")
184+
* End:
185+
*/

src/memif_private.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,21 @@
2424
#include <sys/syscall.h>
2525

2626
#include <libmemif.h>
27-
2827
#include <fifo.h>
2928

3029
#define MEMIF_DEFAULT_SOCKET_DIR "/run/vpp"
3130
#define MEMIF_DEFAULT_SOCKET_FILENAME "memif.sock"
3231
#define MEMIF_DEFAULT_RING_SIZE 1024
32+
#define MEMIF_DEFAULT_LOG2_RING_SIZE 10
3333
#define MEMIF_DEFAULT_RX_QUEUES 1
3434
#define MEMIF_DEFAULT_TX_QUEUES 1
3535
#define MEMIF_DEFAULT_BUFFER_SIZE 2048
3636

37+
#define MEMIF_MAX_M2S_RING 1
38+
#define MEMIF_MAX_S2M_RING 1
39+
#define MEMIF_MAX_REGION 255
40+
#define MEMIF_MAX_LOG2_RING_SIZE 14
41+
3742
#define MEMIF_MAX_FDS 512
3843

3944
#define MEMIF_DEBUG 1
@@ -108,10 +113,11 @@ typedef struct memif_connection
108113

109114
memif_fn *write_fn, *read_fn, *error_fn;
110115

116+
/* connection message queue */
111117
memif_fifo_t msg_queue;
112118

113-
uint8_t *remote_if_name;
114-
uint8_t *remote_name;
119+
uint8_t remote_if_name[32];
120+
uint8_t remote_name[32];
115121

116122
memif_region_t *regions;
117123

0 commit comments

Comments
 (0)