-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfacedown.cpp
More file actions
74 lines (70 loc) · 1.73 KB
/
interfacedown.cpp
File metadata and controls
74 lines (70 loc) · 1.73 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#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(INTERFACEDOWN,interfacedown1)
{
FILE *file = fopen("testbed.csv","r");
char rbuf[4096];
char cbuf[1024];
memset(rbuf,0,4096);
fread(rbuf,4096,1,file);
char *interfacestr = strstr(rbuf,"interfacedown,Ethernet,");
char *id = NULL;
if(interfacestr != NULL){
interfacestr += strlen("interfacedown,Ethernet,");
id = interfacestr;
while(*interfacestr != '\n')
interfacestr++;
*interfacestr = '\0';
}
char *pEnd = NULL;
int num = strtol(id,&pEnd,10);
//printf("id:%d:\n",num);
char interfacename[64];
sprintf(interfacename,"Ethernet%d",num);
printf("name:%s\n",interfacename);
sprintf(cbuf,"sudo config interface shutdown %s 2>&1",interfacename);
FILE *stream = popen(cbuf,"r");
sprintf(cbuf,"show interface status|grep %s|awk -F' ' '{print $7}'",interfacename);
stream = popen(cbuf,"r");
memset(rbuf,0,4096);
fread(rbuf,sizeof(char),sizeof(rbuf),stream);
printf("rbuf:%s\n",rbuf);
ASSERT_STREQ(rbuf,"down\n");
#if 0
char mac[128];
sprintf(mac,"%s",rbuf);
//printf("%s",mac);
sprintf(cbuf,"show mac");
stream = popen(cbuf,"r");
memset(rbuf,0,4096);
fread(rbuf,sizeof(char),sizeof(rbuf),stream);
char *p = strstr(rbuf,mac);
printf("1:%s:",rbuf);
printf("2:%s:",mac);
if(p == NULL){
ASSERT_FALSE(1==1);
}
#endif
#if 0
char *p = strstr(rbuf,"Platform");
if(p == NULL){
ASSERT_FALSE(1==1);
return;
}
p[strlen("Platform")] = 0;
sprintf(cbuf,"Platform");
ASSERT_STREQ(p,cbuf);
#endif
}