def test_selabel_cipso_mode_BIBA(self):

        # 下发配置并检查结果
        for key in self.case3_step:
            fun.cmd(self.case3_step[key][0], 'gw')
            re = fun.cmd(self.case3_step[key][1], 'gw')
            assert self.case3_step[key][2] in re

        # 服务端抓取报文
        cap_iface, cap_filter, cap_num, cap_pcap = self.pkt3_cfg['capture'][0], self.pkt3_cfg['capture'][1], \
                      self.pkt3_cfg['capture'][2], self.pkt3_cfg['capture'][3]
        pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)
        fun.cmd(pre_cfg, 's', thread=1)
        print('step wait')
        time.sleep(20)

        # 发送报文
        c_iface, c_num, c_pcap = self.pkt3_cfg["send"][0], self.pkt3_cfg[
            "send"][1], self.pkt3_cfg["send"][2]
        send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)
        fun.cmd(send_cmd, 'c')

        # 检查报文是否存在
        pcap_file = fun.search('/opt/pkt', 'pcap', 's')
        assert cap_pcap in pcap_file

        # 读包
        read_name, read_id = self.pkt3_cfg["read"][0], self.pkt3_cfg["read"][1]
        read_cmd = fun.pkt_read(read_name, read_id)
        print(read_cmd)
        read_re = fun.cmd(read_cmd, 's')
        print(read_re)
        # 获取期望结果
        exp = self.pkt3_cfg["expect"][0]
        assert exp == read_re
    def test_acl_mode_a4(self):

        #初始化
        cap_iface, cap_filter, cap_num, cap_pcap = self.pkt4_cfg["capture"][
            0], self.pkt4_cfg["capture"][1], self.pkt4_cfg["capture"][
                2], self.pkt4_cfg["capture"][3]
        c_iface, c_num, c_pcap = self.pkt4_cfg["send"][0], self.pkt4_cfg[
            "send"][1], self.pkt4_cfg["send"][2]
        read_name, read_id = self.pkt4_cfg["read"][0], self.pkt4_cfg["read"][1]

        # 下发配置并检查结果
        for key in self.case4_step1:
            fun.cmd(self.case4_step1[key][0], 'gw')
            re = fun.cmd(self.case4_step1[key][1], 'gw')
            assert self.case4_step1[key][2] in re

        # 服务端抓取报文
        pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)
        print(pre_cfg)
        fun.cmd(pre_cfg, 's', thread=1)
        print('step wait')
        time.sleep(20)

        # 发送报文
        send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)
        fun.cmd(send_cmd, 'c')

        # 检查报文是否存在
        pcap_file = fun.search('/opt/pkt', 'pcap', 's')
        assert cap_pcap not in pcap_file

        # 重新配置策略,下发配置并检查结果
        for key in self.case4_step2:
            fun.cmd(self.case4_step2[key][0], 'gw')
            re = fun.cmd(self.case4_step2[key][1], 'gw')
            assert self.case4_step2[key][2] in re

        # 服务端抓取报文
        pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)
        print(pre_cfg)
        fun.cmd(pre_cfg, 's', thread=1)
        print('step wait')
        time.sleep(20)

        # 发送报文
        send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)
        fun.cmd(send_cmd, 'c')

        # 检查报文是否存在
        pcap_file = fun.search('/opt/pkt', 'pcap', 's')
        assert cap_pcap in pcap_file

        # 读包
        read_cmd = fun.pkt_read(read_name, read_id)
        read_re = fun.cmd(read_cmd, 's')
        print(read_re)

        # 获取期望结果
        exp = self.pkt4_cfg["expect"][0]
        assert exp == read_re
    def test_acl_priority_quintet_same_a1(self):

        #初始化
        cap_iface, cap_filter, cap_num, cap_pcap = self.pkt1_cfg["capture"][
            0], self.pkt1_cfg["capture"][1], self.pkt1_cfg["capture"][
                2], self.pkt1_cfg["capture"][3]
        c_iface, c_num, c_pcap = self.pkt1_cfg["send"][0], self.pkt1_cfg[
            "send"][1], self.pkt1_cfg["send"][2]
        read_name, read_id = self.pkt1_cfg["read"][0], self.pkt1_cfg["read"][1]

        #切换卡面为0,下发配置并检查结果
        for key in self.case1_step1:
            fun.cmd(self.case1_step1[key][0], 'gw')
            re = fun.cmd(self.case1_step1[key][1], 'gw')
            assert self.case1_step1[key][2] in re

        # # 切换卡面为1,下发配置并检查结果
        # fun.cmd('export cardid=1', 'gw')
        # for key in self.case1_step2:
        # 	fun.cmd(self.case1_step2[key][0], 'gw')
        # 	card1 = fun.cmd(self.case1_step2[key][1], 'gw')
        # 	assert self.case1_step2[key][2] in card1

        # 服务端抓取报文
        # pcap_cmd = f'tcpdump -i {cap_iface} -w /opt/pkt/{cap_pcap} host {cap_filter}'
        # print(pcap_cmd)
        # fun.cmd(pcap_cmd,'s',thread=1)
        pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)
        print(pre_cfg)
        fun.cmd(pre_cfg, 's', thread=1)
        print('step wait')
        time.sleep(20)

        # 发送报文
        send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)
        fun.cmd(send_cmd, 'c')

        #检查报文是否存在
        pcap_file = fun.search('/opt/pkt', 'pcap', 's')
        assert cap_pcap in pcap_file

        # #c从远程服务器读取文件
        # pkt_read = fun.read(f'/opt/pkt/{cap_pcap}','read','r','','s')
        # print(pkt_read)	#b为二进制读取,后面的字符串为读取的内容
        # 读包
        read_cmd = fun.pkt_read(read_name, read_id)
        print(read_cmd)
        read_re = fun.cmd(read_cmd, 's')
        print(read_re)

        # 获取期望结果
        exp = self.pkt1_cfg["expect"][0]
        assert exp == read_re
Exemple #4
0
    def test_acl_old_a1(self):

        # 初始化
        cap_iface, cap_filter, cap_num, cap_pcap = self.pkt1_cfg["capture"][0], self.pkt1_cfg["capture"][1], \
                                                   self.pkt1_cfg["capture"][2], self.pkt1_cfg["capture"][3]
        c_iface, c_num, c_pcap = self.pkt1_cfg["send"][0], self.pkt1_cfg[
            "send"][1], self.pkt1_cfg["send"][2]
        read_name, read_id = self.pkt1_cfg["read"][0], self.pkt1_cfg["read"][1]

        # 下发配置并检查结果
        for key in self.case1_step1:
            fun.cmd(self.case1_step1[key][0], 'gw')
            re = fun.cmd(self.case1_step1[key][1], 'gw')
            assert self.case1_step1[key][2] in re

        # 服务端抓取报文
        pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)
        print('pre_cfg: ', pre_cfg)
        fun.cmd(pre_cfg, 's', thread=1)
        print('step wait')
        time.sleep(20)

        # 发送报文
        send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)
        print('send_cmd: ', send_cmd)
        fun.cmd(send_cmd, 'c')

        # 检查报文是否存在
        pcap_file = fun.search('/opt/pkt', 'pcap', 's')
        print('cap_pcap: ', cap_pcap)
        assert cap_pcap in pcap_file

        # 读包
        read_cmd = fun.pkt_read(read_name, read_id)
        read_re = fun.cmd(read_cmd, 's')
        print('read_re: ', read_re)

        # 获取期望结果
        exp = self.pkt1_cfg["expect"][0]
        print('exp: ', exp)
        assert exp == read_re

        print('等待60s的老化时间')
        time.sleep(70)

        # 下发配置并检查结果
        for key in self.case1_step1:
            re = fun.cmd(self.case1_step1[key][1], 'gw')
            assert self.case1_step1[key][2] not in re
    def test_acl_compare_selabel_a1(self):

        #初始化
        cap_iface, cap_filter, cap_num, cap_pcap = self.pkt1_cfg["capture"][0], self.pkt1_cfg["capture"][1], \
                     self.pkt1_cfg["capture"][2], self.pkt1_cfg["capture"][3]
        c_iface, c_num, c_pcap = self.pkt1_cfg["send"][0], self.pkt1_cfg[
            "send"][1], self.pkt1_cfg["send"][2]
        read_name, read_id = self.pkt1_cfg["read"][0], self.pkt1_cfg["read"][1]

        #下发配置并检查结果
        fun.cmd('export cardid=0&&defconf --action drop', 'gw')
        fun.cmd('export cardid=1&&defconf --action drop', 'gw')
        for key in self.case1_step:
            fun.cmd(self.case1_step[key][0], 'gw')
            re = fun.cmd(self.case1_step[key][1], 'gw')
            assert self.case1_step[key][2] in re

        # 服务端抓取报文
        pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)
        print(pre_cfg)
        fun.cmd(pre_cfg, 's', thread=1)
        print('step wait')
        time.sleep(20)

        # 发送报文
        send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)
        fun.cmd(send_cmd, 'c')

        # 检查报文是否存在
        pcap_file = fun.search('/opt/pkt', 'pcap', 's')
        # 还原配置,防止抓不到包,断言失败,无法恢复环境
        fun.cmd('export cardid=0&&defconf --action forward', 'gw')
        fun.cmd('export cardid=1&&defconf --action forward', 'gw')
        assert cap_pcap in pcap_file

        # 读包
        read_cmd = fun.pkt_read(read_name, read_id)
        read_re = fun.cmd(read_cmd, 's')
        print(read_re)

        # 获取期望结果
        exp = self.pkt1_cfg["expect"][0]
        assert exp == read_re
    def test_a1(self):
        #清空环境

        for i in self.clr_env:
            print(i)
            dd = fun.cmd(i, 'gw_c', self.mac)
            print(dd)

        #设置初始环境
        cap_iface, cap_filter, cap_num, cap_pcap = self.pre_env["capture"][
            0], self.pre_env["capture"][1], self.pre_env["capture"][
                2], self.pre_env["capture"][3]
        pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)
        fun.cmd(pre_cfg, 'gw_c', thread=1)
        print('step wait')
        time.sleep(3)

        #下发配置并检查结果
        for key in self.case_step:
            fun.cmd(self.case_step[key][0], 'gw_c')
            re = fun.cmd(self.case_step[key][1], 'gw_c')
            assert self.case_step[key][2] in re

        #发送报文
        c_iface, c_num, c_pcap = self.pkt_cfg["send"][0], self.pkt_cfg["send"][
            1], self.pkt_cfg["send"][2]
        send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)
        fun.cmd(send_cmd, 'gw_s')

        #检查报文是否存在
        pcap_file = fun.search('/opt/pkt', 'pcap', 'gw_c')
        assert cap_pcap in pcap_file

        #读包
        read_name, read_id = self.pkt_cfg["read"][0], self.pkt_cfg["read"][1]
        read_cmd = fun.pkt_read(read_name, read_id)
        read_re = fun.cmd(read_cmd, 'gw_c')
        print(read_re)

        #获取期望结果
        exp = self.pkt_cfg["expect"][0]
        assert exp in read_re
Exemple #7
0
    def test_acl_category_0(self):

        # 初始化
        cap_iface, cap_filter, cap_num, cap_pcap = self.pkt1_cfg["capture"][0], self.pkt1_cfg["capture"][1], \
                                                   self.pkt1_cfg["capture"][2], self.pkt1_cfg["capture"][3]
        c_iface, c_num, c_pcap = self.pkt1_cfg["send"][0], self.pkt1_cfg[
            "send"][1], self.pkt1_cfg["send"][2]
        read_name, read_id = self.pkt1_cfg["read"][0], self.pkt1_cfg["read"][1]

        # 下发配置并检查结果
        for key in self.case1_step:
            fun.cmd(self.case1_step[key][0], 'gw')
            re = fun.cmd(self.case1_step[key][1], 'gw')
            assert self.case1_step[key][2] in re

        # 服务端抓取报文
        pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)
        print("sniff_cmd: ", pre_cfg)
        fun.cmd(pre_cfg, 's', thread=1)
        print('step wait')
        time.sleep(20)

        # 发送报文
        send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)
        print('send_cmd:', send_cmd)
        fun.cmd(send_cmd, 'c')

        # 检查报文是否存在
        pcap_file = fun.search('/opt/pkt', 'pcap', 's')
        assert cap_pcap in pcap_file

        # 读包
        read_cmd = fun.pkt_read(read_name, read_id)
        print('read_cmd: {}'.format(read_cmd))
        read_re = fun.cmd(read_cmd, 's')
        print('read_re: '.format(read_re))

        # 获取期望结果
        exp = self.pkt1_cfg["expect"][0]
        print('期望值为: {}'.format(exp))
        assert exp == read_re
Exemple #8
0
    def test_selabel_cipso_type_1(self):

        # 下发配置并检查结果
        for key in self.case1_step:
            fun.cmd(self.case1_step[key][0], 'gw')
            re = fun.cmd(self.case1_step[key][1], 'gw')
            print(re)
            assert self.case1_step[key][2] in re

        # 服务端抓取报文
        cap_iface, cap_filter, cap_num, cap_pcap = self.pkt1_cfg['capture'][0], self.pkt1_cfg['capture'][1], \
                                                   self.pkt1_cfg['capture'][2], self.pkt1_cfg['capture'][3]
        pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)
        print('pre_cfg:', pre_cfg)
        fun.cmd(pre_cfg, 's', thread=1)
        print('step wait')
        time.sleep(20)

        # 发送报文
        c_iface, c_num, c_pcap = self.pkt1_cfg["send"][0], self.pkt1_cfg[
            "send"][1], self.pkt1_cfg["send"][2]
        send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)
        print('send_cmd:', send_cmd)
        fun.cmd(send_cmd, 'c')

        # 检查报文是否存在
        # fun.wait_data(f"ls /opt/pkt/ | grep pcap", 'gw', self.pkt1_cfg['capture'][3], '检查服务端抓包结果', 300, flag='存在')
        pcap_file = fun.search('/opt/pkt', 'pcap', 's')
        assert cap_pcap in pcap_file
        print('服务端抓到报文:{}'.format(self.read_1))

        # 读包
        read_name, read_id = self.pkt1_cfg["read"][0], self.pkt1_cfg["read"][1]
        read_cmd = fun.pkt_read(read_name, read_id)
        print('read_cmd', read_cmd)
        read_re = fun.cmd(read_cmd, 's')
        print('read_re', read_re)
        # 获取期望结果
        exp = self.pkt1_cfg["expect"][0]
        assert exp == read_re
Exemple #9
0
    def test_acl_priority_quintet_same_a3(self):

        # 初始化
        cap_iface, cap_filter, cap_num, cap_pcap = self.pkt3_cfg["capture"][0], self.pkt3_cfg["capture"][1], \
                                                   self.pkt3_cfg["capture"][2], self.pkt3_cfg["capture"][3]
        c_iface, c_num, c_pcap = self.pkt3_cfg["send"][0], self.pkt3_cfg[
            "send"][1], self.pkt3_cfg["send"][2]
        read_name, read_id = self.pkt3_cfg["read"][0], self.pkt3_cfg["read"][1]

        # 切换卡面为0,下发配置并检查结果
        for key in self.case3_step1:
            fun.cmd(self.case3_step1[key][0], 'gw')
            re = fun.cmd(self.case3_step1[key][1], 'gw')
            assert self.case3_step1[key][2] in re

        # 服务端抓取报文
        pre_cfg = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap)
        print('pre_cfg: ', pre_cfg)
        fun.cmd(pre_cfg, 's', thread=1)
        print('step wait')
        time.sleep(20)

        # 发送报文
        send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)
        fun.cmd(send_cmd, 'c')

        # 检查报文是否存在
        pcap_file = fun.search('/opt/pkt', 'pcap', 's')
        assert cap_pcap in pcap_file

        # 读包
        read_cmd = fun.pkt_read(read_name, read_id)
        read_re = fun.cmd(read_cmd, 's')
        print('read_re: ', read_re)

        # 获取期望结果
        exp = self.pkt3_cfg["expect"][0]
        assert exp == read_re
Exemple #10
0
    def test_acl_drop_a1(self):

        # 初始化
        cap_iface, cap_filter, cap_num, cap_pcap1, cap_pcap2, cap_pcap3 = self.pkt1_cfg["capture"][0], \
                                                                          self.pkt1_cfg["capture"][1], \
                                                                          self.pkt1_cfg["capture"][2], \
                                                                          self.pkt1_cfg["capture"][3], \
                                                                          self.pkt1_cfg['capture'][4], \
                                                                          self.pkt1_cfg['capture'][5]
        c_iface, c_num, c_pcap = self.pkt1_cfg["send"][0], self.pkt1_cfg["send"][1], self.pkt1_cfg["send"][2]
        read_name1, read_name2, read_name3, read_id = self.pkt1_cfg["read"][0], self.pkt1_cfg["read"][1], \
                                                      self.pkt1_cfg['read'][2], self.pkt1_cfg['read'][3]

        # 下发配置并检查结果
        for key in self.case1_step1:
            fun.cmd(self.case1_step1[key][0], 'gw')
            re = fun.cmd(self.case1_step1[key][1], 'gw')
            assert self.case1_step1[key][2] in re

        # 服务端抓取报文

        pre_cfg1 = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap1)
        print(pre_cfg1)
        fun.cmd(pre_cfg1, 's', thread=1)
        print('step wait')
        time.sleep(20)

        # 发送报文

        send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)
        fun.cmd(send_cmd, 'c')

        # 检查报文是否存在
        pcap_file = fun.search('/opt/pkt', 'pcap', 's')
        fun.pid_kill(cap_pcap1)
        assert cap_pcap1 in pcap_file

        # 读包
        read_cmd = fun.pkt_read(read_name1, read_id)
        read_re = fun.cmd(read_cmd, 's')
        print('read_re: ', read_re)

        # 获取期望结果
        exp = self.pkt1_cfg["expect"][0]
        assert exp == read_re

        # 再次下发配置并检查结果
        for key in self.case1_step2:
            fun.cmd(self.case1_step2[key][0], 'gw')
            re = fun.cmd(self.case1_step2[key][1], 'gw')
            assert self.case1_step2[key][2] in re

        pre_cfg2 = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap2)
        print(pre_cfg2)
        fun.cmd(pre_cfg2, 's', thread=1)
        print('step wait')
        time.sleep(20)

        # 发送报文
        send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)
        fun.cmd(send_cmd, 'c')

        # 检查报文是否存在
        pcap_file = fun.search('/opt/pkt', 'pcap', 's')
        fun.pid_kill(cap_pcap2)
        assert cap_pcap2 in pcap_file

        # 读包
        read_cmd = fun.pkt_read(read_name2, read_id)
        read_re = fun.cmd(read_cmd, 's')
        print('read_re: ', read_re)

        # 获取期望结果
        exp = self.pkt1_cfg["expect"][0]
        assert exp == read_re

        # 再次下发配置并检查结果
        for key in self.case1_step3:
            fun.cmd(self.case1_step3[key][0], 'gw')
            re = fun.cmd(self.case1_step3[key][1], 'gw')
            assert self.case1_step3[key][2] in re

        pre_cfg3 = fun.pkt_capture(cap_iface, cap_filter, cap_num, cap_pcap3)
        print(pre_cfg3)
        fun.cmd(pre_cfg3, 's', thread=1)
        print('step wait')
        time.sleep(20)

        # 发送报文
        send_cmd = fun.pkt_send(c_iface, c_num, c_pcap)
        fun.cmd(send_cmd, 'c')

        # 检查报文是否存在
        pcap_file = fun.search('/opt/pkt', 'pcap', 's')
        fun.pid_kill(cap_pcap3)
        assert cap_pcap3 in pcap_file

        # 读包
        read_cmd = fun.pkt_read(read_name3, read_id)
        read_re = fun.cmd(read_cmd, 's')
        print('read_re: ', read_re)

        # 获取期望结果
        exp = self.pkt1_cfg["expect"][0]
        assert exp == read_re