-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvlan.cpp
More file actions
60 lines (50 loc) · 1.22 KB
/
vlan.cpp
File metadata and controls
60 lines (50 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<iostream>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
using namespace std;
#include<gtest/gtest.h>
TEST(VLANCONFIG,AddVlan1)
{
int vlan_id = 1;
ASSERT_GT(vlan_id,0);
FILE *stream = NULL;
char rbuf[4096];
char cbuf[1024];
sprintf(cbuf,"sudo config vlan add %d 2>&1",vlan_id);
stream = popen(cbuf,"r");
fread(rbuf,sizeof(char),sizeof(rbuf),stream);
sprintf(cbuf,"sudo config vlan member add %d Ethernet2 2>&1",vlan_id);
stream = popen(cbuf,"r");
fread(rbuf,sizeof(char),sizeof(rbuf),stream);
sprintf(cbuf,"show vlan config|grep Vlan%d|awk -F' ' '{print $2}'",vlan_id);
stream = popen(cbuf,"r");
memset(rbuf,0,sizeof(rbuf));
fread(rbuf,sizeof(char),sizeof(rbuf),stream);
char *pEnd = NULL;
int val = -1;
char *p = rbuf;
while(1){
val = strtol(p,&pEnd,10);
if(val == vlan_id){
break;
}
if(val == 0 && pEnd==p){
ASSERT_FALSE(1==1);
break;
}
memset(cbuf,0,sizeof(cbuf));
sprintf(cbuf,"%d\n",val);
p += strlen(cbuf);
}
//sprintf(cbuf,"%d\n",vlan_id);
//ASSERT_STREQ(cbuf,rbuf);
}