Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dplane-rpc"
version = "1.1.1"
version = "1.1.2"
edition = "2021"
license = "Apache-2.0"

Expand Down
17 changes: 17 additions & 0 deletions clib/bin/cpmock.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ static void log_msg(const char *prefix, struct RpcMsg *msg)
str_rpc_op(msg->request.op),
str_object_type(msg->request.object.type));
break;
case Control:
case Notification:
log_dbg("%s msg: %s", prefix, str_msg_type(msg->type));
break;
default:
// we only cover requests atm
break;
Expand Down Expand Up @@ -241,6 +245,14 @@ static int send_notification(void)
struct RpcMsg msg = {.type = Notification};
return send_msg(&msg);
}
static int send_control(void)
{
struct RpcControl ctl = {0};
ctl.refresh = 1;

struct RpcMsg msg = {.type = Control, .control = ctl};
return send_msg_compare_echo(&msg);
}

int main(int argc, char **argv)
{
Expand Down Expand Up @@ -286,6 +298,11 @@ int main(int argc, char **argv)
if (r != EXIT_SUCCESS)
return r;

/* Send control */
r = send_control();
if (r != EXIT_SUCCESS)
return r;

/* Send notification: won't wait for answer */
r = send_notification();
if (r != EXIT_SUCCESS)
Expand Down
4 changes: 2 additions & 2 deletions clib/src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ char *fmt_conninfo(struct fmt_buff *fb, bool clear, struct conn_info *c)
if (clear)
clear_fmt_buff(fb);

fmt_buff(fb, "ConnInfo ─── name: %s pid: %u ", c->name, c->pid);
fmt_buff(fb, "ConnInfo ─── name: %s pid: %u synt: %lu ", c->name, c->pid, c->synt);
return fmt_verinfo(fb, false, &c->verinfo);
}
char *fmt_rmac(struct fmt_buff *fb, bool clear, struct rmac *rmac)
Expand Down Expand Up @@ -336,7 +336,7 @@ char *fmt_rpc_control(struct fmt_buff *fb, bool clear, struct RpcControl *ctl)
BUG(!fb || !ctl, NULL);
if (clear)
clear_fmt_buff(fb);
return fmt_buff(fb, "Control");
return fmt_buff(fb, "Control refresh:%u", ctl->refresh);
}
char *fmt_rpc_notification(struct fmt_buff *fb, bool clear, struct RpcNotification *ctl)
{
Expand Down
9 changes: 8 additions & 1 deletion clib/src/dp_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,18 @@ static int decode_response(buff_t *buff, struct RpcResponse *resp)
/* msg:control */
static int encode_control(buff_t *buff, struct RpcControl *ctl)
{
// Control messages are empty at the moment
int r;
if ((r = put_u8(buff, ctl->refresh)))
return r;

return E_OK;
}
static int decode_control(buff_t *buff, struct RpcControl *ctl)
{
int r;
if ((r = get_u8(buff, &ctl->refresh)))
return r;

return E_OK;
}

Expand Down
1 change: 1 addition & 0 deletions clib/src/dp_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct RpcResponse {
};

struct RpcControl {
uint8_t refresh;
};

struct RpcNotification {
Expand Down
8 changes: 6 additions & 2 deletions clib/src/dp_objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ static int encode_conn_info(buff_t *buff, struct conn_info *info)
return r;
if ((r = put_u32(buff, info->pid)) != E_OK)
return r;
if ((r = encode_verinfo(buff, &info->verinfo)) != E_OK)
return r;

return encode_verinfo(buff, &info->verinfo);
return put_u64(buff, info->synt);
}
static int decode_conn_info(buff_t *buff, struct conn_info *info)
{
Expand All @@ -229,8 +231,10 @@ static int decode_conn_info(buff_t *buff, struct conn_info *info)
return r;
if ((r = get_u32(buff, &info->pid)) != E_OK)
return r;
if ((r = decode_verinfo(buff, &info->verinfo)) != E_OK)
return r;

return decode_verinfo(buff, &info->verinfo);
return get_u64(buff, &info->synt);
}

/* ifadddress: encode / decode */
Expand Down
1 change: 1 addition & 0 deletions clib/src/dp_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct conn_info {
char name[MAX_STRING_LEN + 1];
uint32_t pid;
struct ver_info verinfo;
uint64_t synt;
};

struct rmac {
Expand Down
3 changes: 2 additions & 1 deletion clib/test/object_builders.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ struct conn_info build_conn_info(void)
struct conn_info info = {
.name = "test",
.pid = 1234,
.verinfo = build_ver_info()
.verinfo = build_ver_info(),
.synt = 1492
};
return info;
}
Expand Down
90 changes: 0 additions & 90 deletions clib/test/test_vec.c

This file was deleted.

17 changes: 17 additions & 0 deletions clib/test/test_wire.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,19 @@ int test_msg_response(buff_t *buff)
return EXIT_SUCCESS;
}

int test_msg_control(buff_t *buff) {
TEST();
buff_clear(buff);

struct RpcMsg msg = {0};
struct RpcControl ctl = {0};

ctl.refresh = 1;
msg.type = Control;
msg.control = ctl;

return check_msg(buff, &msg);
}

int main (int argc, char **argv)
{
Expand All @@ -367,6 +380,10 @@ int main (int argc, char **argv)
if (test_msg_response(buff) != EXIT_SUCCESS)
return EXIT_FAILURE;

/* test msg:control encoding / decoding */
if (test_msg_control(buff) != EXIT_SUCCESS)
return EXIT_FAILURE;

buff_free(buff);
fprintf(stderr, "Success!\n");
return EXIT_SUCCESS;
Expand Down
6 changes: 4 additions & 2 deletions src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ pub struct RpcResponse {

#[doc = "A control message"]
#[derive(Debug, PartialEq, Default)]
pub struct RpcControl {}
pub struct RpcControl {
pub refresh: u8, /* treated as bool */
}

#[doc = "A notification message"]
#[derive(Debug, PartialEq, Default)]
Expand Down Expand Up @@ -235,7 +237,7 @@ impl Display for RpcNotification {
}
impl Display for RpcControl {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Control")
write!(f, "Control refresh:{}", self.refresh)
}
}
impl Display for RpcMsg {
Expand Down
9 changes: 5 additions & 4 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ use std::fmt::Display;
pub use std::net::IpAddr;

#[doc = "A versioning information object."]
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct VerInfo {
pub major: u8,
pub minor: u8,
pub patch: u8,
}

#[doc = "A connection information object identifying the requestor."]
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct ConnectInfo {
pub pid: u32,
pub name: String,
pub verinfo: VerInfo,
pub synt: u64,
}

#[doc = "A (IP, MAC, Vni) tuple"]
Expand Down Expand Up @@ -153,8 +154,8 @@ impl Display for ConnectInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"ConnectInfo ─── name:{} pid:{} verinfo:{}",
&self.name, self.pid, self.verinfo
"ConnectInfo ─── name:{} pid:{} verinfo:{} synt:{}",
&self.name, self.pid, self.verinfo, self.synt
)
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ mod positive_tests {
minor: 66,
patch: 99,
},
synt: 1714,
};
let req = RpcRequest::new(RpcOp::Connect, 999).set_object(RpcObject::ConnectInfo(coninfo));
let msg = req.wrap_in_msg();
Expand Down Expand Up @@ -223,6 +224,13 @@ mod positive_tests {
test_encode_decode_msg(&msg);
}

#[test]
fn test_rpcmsg_control() {
let ctl = RpcControl{ refresh: 1 };
let msg = ctl.wrap_in_msg();
test_encode_decode_msg(&msg);
}

#[test]
fn test_rpcmsg_response_with_objects() {
// create a response
Expand Down
19 changes: 15 additions & 4 deletions src/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,19 @@ impl Wire<ConnectInfo> for ConnectInfo {
let name = buf.sget_string("name")?;
let pid = buf.sget_u32_ne("pid")?;
let verinfo = VerInfo::decode(buf)?;
Ok(ConnectInfo { name, pid, verinfo })
let synt = buf.sget_u64_ne("synt")?;
Ok(ConnectInfo {
name,
pid,
verinfo,
synt,
})
}
fn encode(&self, buf: &mut BytesMut) -> Result<(), WireError> {
put_string(buf, &self.name)?;
buf.put_u32_ne(self.pid);
self.verinfo.encode(buf)?;
buf.put_u64_ne(self.synt);
Ok(())
}
}
Expand Down Expand Up @@ -570,10 +577,14 @@ impl Wire<RpcNotification> for RpcNotification {

/* RpcControl */
impl Wire<RpcControl> for RpcControl {
fn decode(_buf: &mut Bytes) -> WireResult<RpcControl> {
Ok(RpcControl::default())
fn decode(buf: &mut Bytes) -> WireResult<RpcControl> {
let refresh = buf.sget_u8("refresh")?;
Ok(RpcControl{
refresh
})
}
fn encode(&self, _buf: &mut BytesMut) -> Result<(), WireError> {
fn encode(&self, buf: &mut BytesMut) -> Result<(), WireError> {
buf.put_u8(self.refresh);
Ok(())
}
}
Expand Down