
Provide a pure C test program employing libnetwork. Note it is linked with libcmpiutil, so need CU_DEBUG to be set to stdout to see the output. Try vconfig and brctl command modifying the network and then run the test program to see the output. Signed-off-by: Wenchao Xia <xiawenc@cn.ibm.com> --- libnetwork/libnetwork_test.c | 91 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 91 insertions(+), 0 deletions(-) create mode 100644 libnetwork/libnetwork_test.c diff --git a/libnetwork/libnetwork_test.c b/libnetwork/libnetwork_test.c new file mode 100644 index 0000000..a611846 --- /dev/null +++ b/libnetwork/libnetwork_test.c @@ -0,0 +1,91 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <pthread.h> +#include <unistd.h> +#include <time.h> +#include <assert.h> +#include <sys/time.h> + +#include "host_network_API.h" + +static long print_and_ret_time_stamp(void) +{ + struct timeval tv; + long ret; + gettimeofday(&tv, NULL); + ret = tv.tv_sec*1000+ tv.tv_usec/1000; + printf("time is [%ld] ms.", ret); + return ret; +} + +int main(int argc, char **argv) +{ + EthIfacesList ifaces_list; + EthIface iface_ref,iface_br,iface_vlan; + int comp_ret = 0; + int persist_flag = 1; + long timestart, timeend; + int i; + + + printf("executing the program with persist flag %d.\n", persist_flag); + comp_ret = 0; + + eth_ifaceslist_init(&ifaces_list); + eth_iface_init(&iface_ref); + eth_iface_init(&iface_br); + eth_iface_init(&iface_vlan); + + eth_iface_add_br_prop(&iface_br); + eth_iface_add_vlan_prop(&iface_vlan, VLAN_TYPE_802_1_Q); + iface_br.eth_type = ETH_TYPE_ETHER_SUB_BRIDGE | ETH_TYPE_ETHER_ANY; + iface_vlan.eth_type = ETH_TYPE_ETHER_SUB_VLAN | ETH_TYPE_ETHER_ANY; + + //iface_ref.name = SAFE_STRDUP("eth1.100"); + iface_ref.eth_type = ETH_TYPE_ETHER_SUB_BRIDGE | ETH_TYPE_ETHER_ANY; + + iface_br.name = SAFE_STRDUP("test_br"); + iface_vlan.name = SAFE_STRDUP("eth0.1000"); + + iface_br.pbr_prop->STP = 1; + + iface_vlan.pvlan_prop->vlan_type = VLAN_TYPE_802_1_Q; + iface_vlan.pvlan_prop->props.prop_8021q.parent = SAFE_STRDUP("eth0"); + iface_vlan.pvlan_prop->props.prop_8021q.vlan_id = 1000; + iface_vlan.pvlan_prop->props.prop_8021q.reorder_hdr = 0; + iface_vlan.pvlan_prop->props.prop_8021q.ingress.count = 1; + iface_vlan.pvlan_prop->props.prop_8021q.ingress.values[0].from = 2; + iface_vlan.pvlan_prop->props.prop_8021q.ingress.values[0].to = 3; + iface_vlan.pvlan_prop->props.prop_8021q.egress.count = 1; + iface_vlan.pvlan_prop->props.prop_8021q.egress.values[0].from = 4; + iface_vlan.pvlan_prop->props.prop_8021q.egress.values[0].to = 6; + + timestart = print_and_ret_time_stamp(); + printf(" start list the host ifaces.\n"); + + get_host_ifaces(&ifaces_list, NULL, NULL); + //get_host_ifaces(&ifaces_list, eth_iface_filter_by_ref, &iface_ref); + //get_host_ifaces(&ifaces_list, eth_iface_filter_vlans, NULL); + //get_host_ifaces(&ifaces_list, eth_iface_filter_peths, NULL); + + timeend = print_and_ret_time_stamp(); + printf(" end list the host ifaces, cost [%ld]ms.\n", timeend-timestart); + + eth_ifaceslist_print(&ifaces_list); + eth_ifaceslist_uninit(&ifaces_list); + + /* test for mem leak */ +/* + for (i = 0; i < 10; i++) { + eth_ifaceslist_init(&ifaces_list); + get_host_ifaces(&ifaces_list, NULL, NULL); + eth_ifaceslist_uninit(&ifaces_list); + } +*/ + eth_iface_uninit(&iface_ref); + eth_iface_uninit(&iface_br); + eth_iface_uninit(&iface_vlan); + + return 0; +} -- 1.7.1