work on gobgp
This commit is contained in:
parent
b9f353809d
commit
c3e8b06615
12 changed files with 140 additions and 77 deletions
|
|
@ -0,0 +1,8 @@
|
||||||
|
defmodule EvpnRouter.GoBGP.NativeUtils do
|
||||||
|
use Rustler, otp_app: :evpn_router, crate: :evpn_router
|
||||||
|
|
||||||
|
@spec get_route_family(String.t()) :: {:ok, non_neg_integer()}
|
||||||
|
def get_route_family(_p0) do
|
||||||
|
{:error, :nif_error}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -30,7 +30,7 @@ defmodule EvpnRouter.MixProject do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp rustler_crates do
|
defp rustler_crates do
|
||||||
[evpn_router: [path: "native/gobgp", mode: rustc_mode(Mix.env)]]
|
[evpn_router: [path: "native/evpn_router", mode: rustc_mode(Mix.env)]]
|
||||||
end
|
end
|
||||||
|
|
||||||
defp rustc_mode(:prod), do: :release
|
defp rustc_mode(:prod), do: :release
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
[package]
|
[package]
|
||||||
name = "gobgp"
|
name = "evpn_router"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["HansiHE <hansihe@hansihe.com>"]
|
build = "build.rs"
|
||||||
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "gobgp"
|
name = "evpn_router"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
crate-type = ["dylib"]
|
crate-type = ["dylib"]
|
||||||
|
|
||||||
[package.metadata.release]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rustler = { git = "https://github.com/hansihe/rustler", branch = "remove_nif_from_types"}
|
rustler = { git = "https://github.com/hansihe/rustler", branch = "remove_nif_from_types"}
|
||||||
rustler_codegen = { git = "https://github.com/hansihe/rustler", branch = "remove_nif_from_types"}
|
rustler_codegen = { git = "https://github.com/hansihe/rustler", branch = "remove_nif_from_types"}
|
||||||
bufstream = "0.1.2"
|
bufstream = "0.1.2"
|
||||||
lazy_static = "1.0.0"
|
lazy_static = "1.0.0"
|
||||||
|
libc = "0.2"
|
||||||
3
examples/evpn_router/native/evpn_router/build.rs
Normal file
3
examples/evpn_router/native/evpn_router/build.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
println!("cargo:rustc-link-search=../evpn_router");
|
||||||
|
}
|
||||||
0
examples/evpn_router/vendor/libgobgp.so → examples/evpn_router/native/evpn_router/libgobgp.so
Normal file → Executable file
0
examples/evpn_router/vendor/libgobgp.so → examples/evpn_router/native/evpn_router/libgobgp.so
Normal file → Executable file
82
examples/evpn_router/native/evpn_router/src/gobgp_utils.rs
Normal file
82
examples/evpn_router/native/evpn_router/src/gobgp_utils.rs
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
/* automatically generated by rust-bindgen */
|
||||||
|
|
||||||
|
extern crate libc;
|
||||||
|
use self::libc::{c_void, c_int, c_longlong, c_char, size_t};
|
||||||
|
|
||||||
|
#[derive(PartialEq, Copy, Clone, Hash, Debug, Default)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct __BindgenComplex<T> {
|
||||||
|
pub re: T,
|
||||||
|
pub im: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct max_align_t {
|
||||||
|
pub __clang_max_align_nonce1: c_longlong,
|
||||||
|
pub __bindgen_padding_0: u64,
|
||||||
|
pub __clang_max_align_nonce2: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct _GoString_ {
|
||||||
|
pub p: *const c_char,
|
||||||
|
pub n: isize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct buf {
|
||||||
|
pub value: *mut c_char,
|
||||||
|
pub len: c_int,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct path_t {
|
||||||
|
pub nlri: buf,
|
||||||
|
pub path_attributes: *mut *mut buf,
|
||||||
|
pub path_attributes_len: c_int,
|
||||||
|
pub path_attributes_cap: c_int,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type path = path_t;
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct GoInterface {
|
||||||
|
pub t: *mut c_void,
|
||||||
|
pub v: *mut c_void,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct GoSlice {
|
||||||
|
pub data: *mut c_void,
|
||||||
|
pub len: c_longlong,
|
||||||
|
pub cap: c_longlong,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[link(name = "gobgp")]
|
||||||
|
extern {
|
||||||
|
pub fn new_path() -> *mut path;
|
||||||
|
|
||||||
|
pub fn free_path(arg1: *mut path);
|
||||||
|
|
||||||
|
pub fn append_path_attribute(
|
||||||
|
arg1: *mut path,
|
||||||
|
arg2: c_int,
|
||||||
|
arg3: *mut c_char,
|
||||||
|
) -> c_int;
|
||||||
|
|
||||||
|
pub fn get_path_attribute(arg1: *mut path, arg2: c_int) -> *mut buf;
|
||||||
|
|
||||||
|
pub fn get_route_family(p0: *mut String) -> u32;
|
||||||
|
|
||||||
|
pub fn serialize_path(p0: u32, p1: *mut String) -> *mut path;
|
||||||
|
|
||||||
|
pub fn decode_path(p0: *mut path) -> *mut c_char;
|
||||||
|
|
||||||
|
pub fn decode_capabilities(p0: *mut buf) -> *mut c_char;
|
||||||
|
}
|
||||||
40
examples/evpn_router/native/evpn_router/src/lib.rs
Normal file
40
examples/evpn_router/native/evpn_router/src/lib.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
#![allow(bad_style, missing_copy_implementations, improper_ctypes)]
|
||||||
|
|
||||||
|
mod gobgp_utils;
|
||||||
|
use gobgp_utils::get_route_family;
|
||||||
|
use gobgp_utils::serialize_path;
|
||||||
|
|
||||||
|
use gobgp_utils::{buf, path_t};
|
||||||
|
|
||||||
|
#[macro_use] extern crate rustler;
|
||||||
|
#[macro_use] extern crate lazy_static;
|
||||||
|
|
||||||
|
use rustler::{Env, Term, NifResult, Encoder};
|
||||||
|
|
||||||
|
mod atoms {
|
||||||
|
rustler_atoms! {
|
||||||
|
atom ok;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rustler_export_nifs!(
|
||||||
|
"Elixir.EvpnRouter.GoBGP.NativeUtils",
|
||||||
|
[("nif_get_route_family", 1, nif_get_route_family),
|
||||||
|
("serialize_path", 2, nif_serialize_path)],
|
||||||
|
None
|
||||||
|
);
|
||||||
|
|
||||||
|
pub fn nif_get_route_family<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> {
|
||||||
|
let mut p0: String = args[0].decode()?;
|
||||||
|
let family = unsafe { get_route_family(&mut p0) };
|
||||||
|
|
||||||
|
Ok((atoms::ok(), family).encode(env))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn nif_serialize_path<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> {
|
||||||
|
let mut family: u32 = args[0].decode()?;
|
||||||
|
let mut path_str: String = args[1].decode()?;
|
||||||
|
let mut path: path_t = unsafe { serialize_path(&mut family, &mut path_str) }
|
||||||
|
|
||||||
|
Ok((atoms::ok(), ))
|
||||||
|
}
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fn main() {
|
|
||||||
println!("cargo:rustc-link-search=native=../../vendor/libgobgp.so");
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
/* automatically generated by rust-bindgen */
|
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone, Hash, Debug, Default)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct __BindgenComplex<T> {
|
|
||||||
pub re: T,
|
|
||||||
pub im: T,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type wchar_t = ::std::os::raw::c_int;
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct max_align_t {
|
|
||||||
pub __clang_max_align_nonce1: ::std::os::raw::c_longlong,
|
|
||||||
pub __bindgen_padding_0: u64,
|
|
||||||
pub __clang_max_align_nonce2: f64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct _GoString_ {
|
|
||||||
pub p: *const ::std::os::raw::c_char,
|
|
||||||
pub n: isize,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct buf {
|
|
||||||
pub value: *mut ::std::os::raw::c_char,
|
|
||||||
pub len: ::std::os::raw::c_int,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub struct path_t {
|
|
||||||
pub nlri: buf,
|
|
||||||
pub path_attributes: *mut *mut buf,
|
|
||||||
pub path_attributes_len: ::std::os::raw::c_int,
|
|
||||||
pub path_attributes_cap: ::std::os::raw::c_int,
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
#![allow(bad_style, missing_copy_implementations, improper_ctypes)]
|
|
||||||
|
|
||||||
pub mod gobgp_utils;
|
|
||||||
|
|
||||||
#[macro_use] extern crate rustler;
|
|
||||||
#[macro_use] extern crate lazy_static;
|
|
||||||
|
|
||||||
use rustler::{Env, Term, NifResult, Encoder};
|
|
||||||
|
|
||||||
mod atoms {
|
|
||||||
rustler_atoms! {
|
|
||||||
atom ok;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rustler_export_nifs!(
|
|
||||||
"Elixir.EvpnRouter.GoBGP.NativeUtils",
|
|
||||||
[("get_route_family", 2, get_route_family)],
|
|
||||||
None
|
|
||||||
);
|
|
||||||
|
|
||||||
fn get_route_family<'a>(env: Env<'a>, args: &[Term<'a>]) -> NifResult<Term<'a>> {
|
|
||||||
let num1: i64 = args[0].decode()?;
|
|
||||||
let num2: i64 = args[1].decode()?;
|
|
||||||
|
|
||||||
Ok((atoms::ok(), num1 + num2).encode(env))
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue