< NET > MAC

转载:

http://baike.baidu.com/view/32702.htm#sub4924694


Media Access Control

媒体介入控制层,属于OSI模型中数据链路层下层子层。

介质访问控制

它定义了数据帧怎样在介质上进行传输。在共享同一个带宽的链路中,对连接介质的访问是“先来先服务”的。物理寻址在此处被定义,逻辑拓扑(信号通过物理拓扑的路径)也在此处被定义。线路控制、出错通知(不纠正)、帧的传递顺序和可选择的流量控制也在这一子层实现。


该协议位于OSI七层协议中数据链路层,数据链路层分为上层LLC(逻辑链路控制),和下层的MAC(介质访问控制),MAC主要负责控制与连接物理层的物理介质。在发送数据的时候,MAC协议可以事先判断是否可以发送数据,如果可以发送将给数据加上一些控制信息,最终将数据以及控制信息以规定的格式发送到物理层;在接收数据的时候,MAC协议首先判断输入的信息并是否发生传输错误,如果没有错误,则去掉控制信息发送至LLC(逻辑链路控制)层。


不管是在传统的有线局域网(LAN)中还是在目前流行的无线局域网(WLAN)中,MAC协议都被广泛地应用。在传统局域网中,各种传输介质的物理层对应到相应的MAC层,目前普遍使用的网络采用的是IEEE 802.3的MAC层标准,采用CSMA/CD访问控制方式;而在无线局域网中,MAC所对应的标准为IEEE 802.11,其工作方式采用DCF(分布控制)和PCF(中心控制)。

#!/usr/bin/env python -- coding: UTF-8 -- --------------------------------------------------------- Copyright (C), 2025, Lianzhou International Co.,Ltd. description: TS887553__nd_detection_basic_test.py Author: dengshudan@tp-link.com.hk history: 2025/8/26 13:48, dengshudan@tp-link.com.hk, Created. --------------------------------------------------------- import time from pysat.sat_test import TestCase, CaseInfo from pysat.sat_result import ResultInfo from testbed_init.un_bvt_switch import testbed_util as testbed from pysat.testbeds_def import UN_BVT_SWITCH from pysat import sat_conf from PyLogger import logging from PySwitchCtrl import * import stc_ctrl as stc import special_frame_global as db import random import network_security_global_config logging handle logger = logging.getLogger(name) class NdDetectionBasicTest(TestCase): def __init__(self): TestCase.__init__(self) self.logger = logging.getLogger(self.__class__.__name__) # define the case info self.case_info = CaseInfo() self.case_info.name = 'nd_detection_basic_test' self.case_info.id = 'TS887553' # the id of the test case in 'Testlink' self.case_info.version = '20250827' # test case version self.case_info.auther = 'dengshudan@tp-link.net' # auther of the test case self.case_info.testbeds = [UN_BVT_SWITCH] # testbeds in which the case could run self.case_info.description = ''' ''' def add_task(self): # register the class self.register_case(self.nd_detection_basic_test, self.case_info) def nd_detection_basic_test(self): result = ResultInfo() test_comment = '' stc_ip = db.get_config('stc_ip') stc_port1 = db.get_config('STC_PORT1') stc_port2 = db.get_config('STC_PORT2') stc_port3 = db.get_config('STC_PORT3') stc_port4 = db.get_config('STC_PORT4') stc_port5 = db.get_config('STC_PORT5') self.logger.info('stc_ip is %s' % stc_ip) self.logger.info('stc_port1 is %s' % stc_port1) self.logger.info('stc_port2 is %s' % stc_port2) self.logger.info('stc_port3 is %s' % stc_port3) self.logger.info('stc_port4 is %s' % stc_port4) self.logger.info('stc_port5 is %s' % stc_port5) try: # [Pre-condition]: Login in DUT self.logger.info('[Pre-condition]: Login in DUT...') client1 = testbed.Client1() client1.dut_iface.open() client1.dut_iface.login() dut_port_type_list, dut_port_list, dut_port_type_short_list = network_security_global_config.get_port_id(client1) # [Pre-condition]: reserve STC cards self.logger.info('[Pre-condition]: start to reserve STC ports...') port1 = stc.Port.Port(stc_ip, stc_port1, 0, 0, 0) port2 = stc.Port.Port(stc_ip, stc_port2, 0, 0, 0) port3 = stc.Port.Port(stc_ip, stc_port3, 0, 0, 0) port4 = stc.Port.Port(stc_ip, stc_port4, 0, 0, 0) port5 = stc.Port.Port(stc_ip, stc_port5, 0, 0, 0) # [Pre-condition]: init STC ports self.logger.info('[Pre-condition]: STC ports initializing...') port1.SubscribeGenerator() port1.SubscribeAnalyzer() port2.SubscribeGenerator() port2.SubscribeAnalyzer() port3.SubscribeGenerator() port3.SubscribeAnalyzer() port4.SubscribeGenerator() port4.SubscribeAnalyzer() port5.SubscribeGenerator() port5.SubscribeAnalyzer() # [Step 1.1]: Configure the DUT try: self.logger.info('[Step 1.1]: Configure the DUT') client1.dut_iface.set_configure_mode() client1.dut_iface.exec_command('#') client1.dut_iface.exec_command('vlan 4094') client1.dut_iface.exec_command('name "4094"') client1.dut_iface.exec_command('#') client1.dut_iface.exec_command('ipv6 source binding %s %s %s vlan %s interface %s %s %s' % ('1', '2001::1', '00:00:00:00:00:01', '1', dut_port_type_list[1], dut_port_list[1], 'nd-detection')) client1.dut_iface.exec_command('ipv6 source binding %s %s %s vlan %s interface %s %s %s' % ('2', '2001::2', '00:00:00:00:00:02', '4094', dut_port_type_list[1], dut_port_list[1], 'nd-detection')) client1.dut_iface.exec_command('ipv6 source binding %s %s %s vlan %s interface %s %s %s' % ('3', 'fe80::200:ff:fe00:1', '00:00:00:00:00:01', '1', dut_port_type_list[1], dut_port_list[1], 'nd-detection')) client1.dut_iface.exec_command('#') client1.dut_iface.exec_command('ipv6 nd detection') client1.dut_iface.exec_command('ipv6 nd detection vlan 1,4094') client1.dut_iface.exec_command('ipv6 nd detection vlan 1,4094 logging') client1.dut_iface.exec_command('#') client1.dut_iface.exec_command('interface %s %s' % (dut_port_type_list[1], dut_port_list[1])) client1.dut_iface.exec_command('switchport general allowed vlan 4094 tagged') client1.dut_iface.exec_command('#') client1.dut_iface.exec_command('interface %s %s' % (dut_port_type_list[2], dut_port_list[2])) client1.dut_iface.exec_command('switchport general allowed vlan 4094 tagged') client1.dut_iface.exec_command('interface %s %s' % (dut_port_type_list[5], dut_port_list[5])) client1.dut_iface.exec_command('ipv6 nd detection trust') client1.dut_iface.exec_command('#') except Exception, e: self.logger.debug('[Step 1.1]: Failed to Configure the DUT') self.break_test('[Step 1.1]: %s' % (e)) # [Step 1.2]: delete default streamblocks self.logger.info('[Step 1.2]: deleting default streamblocks...') stc.Create.Delete('stc', port1.streamblock.getstreamblockhandle()) stc.Create.Delete('stc', port2.streamblock.getstreamblockhandle()) stc.Create.Delete('stc', port3.streamblock.getstreamblockhandle()) stc.Create.Delete('stc', port4.streamblock.getstreamblockhandle()) stc.Create.Delete('stc', port5.streamblock.getstreamblockhandle()) # [Step 1.2]: create streamblock1 NS_match self.logger.info('[Step 1.2]: creating streamblock1...') frame_1 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble minByteLength="8" >fb555555555555d5</preamble><dstMac>33:33:FF:00:00:11</dstMac><srcMac>00:00:00:00:00:01</srcMac></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>2001::1</sourceAddr><destAddr>FF02::1:FF00:11</destAddr></pdu><pdu name="NeighborSolicitation_1" pdu="icmpv6:NeighborSolicitation"><targetAddress>2001::11</targetAddress></pdu></pdus></config></frame>' streamblock1 = port1.addstreamblock() streamblock1.SetAutoFrameLength_ratebased() streamblock1.SetInsertSig_ratebased('TRUE') streamblock1.SetFrameConfig_ratebased(frameconfig=frame_1) # [Step 1.2]: create streamblock2 NS_mac_not_match self.logger.info('[Step 1.2]: creating streamblock2...') frame_2 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble minByteLength="8" >fb555555555555d5</preamble><dstMac>33:33:FF:00:00:11</dstMac><srcMac>00:00:00:00:00:0A</srcMac></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>2001::1</sourceAddr><destAddr>FF02::1:FF00:11</destAddr></pdu><pdu name="NeighborSolicitation_1" pdu="icmpv6:NeighborSolicitation"><targetAddress>2001::11</targetAddress></pdu></pdus></config></frame>' streamblock2 = port1.addstreamblock() streamblock2.SetAutoFrameLength_ratebased() streamblock2.SetInsertSig_ratebased('TRUE') streamblock2.SetFrameConfig_ratebased(frameconfig=frame_2) # [Step 1.2]: create streamblock3 NS_ip_not_match self.logger.info('[Step 1.2]: creating streamblock3...') frame_3 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble minByteLength="8" >fb555555555555d5</preamble><dstMac>33:33:FF:00:00:11</dstMac><srcMac>00:00:00:00:00:01</srcMac></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>2001::a</sourceAddr><destAddr>FF02::1:FF00:11</destAddr></pdu><pdu name="NeighborSolicitation_1" pdu="icmpv6:NeighborSolicitation"><targetAddress>2001::11</targetAddress></pdu></pdus></config></frame>' streamblock3 = port1.addstreamblock() streamblock3.SetAutoFrameLength_ratebased() streamblock3.SetInsertSig_ratebased('TRUE') streamblock3.SetFrameConfig_ratebased(frameconfig=frame_3) # [Step 1.2]: create streamblock4 NS_vlan_not_match self.logger.info('[Step 1.2]: creating streamblock4...') frame_4 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble minByteLength="8" >fb555555555555d5</preamble><dstMac>33:33:FF:00:00:11</dstMac><srcMac>00:00:00:00:00:01</srcMac><vlans name="anon_20694"><Vlan name="Vlan"><pri>000</pri><id>4094</id></Vlan></vlans></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>2001::1</sourceAddr><destAddr>FF02::1:FF00:11</destAddr></pdu><pdu name="NeighborSolicitation_1" pdu="icmpv6:NeighborSolicitation"><targetAddress>2001::11</targetAddress></pdu></pdus></config></frame>' streamblock4 = port1.addstreamblock() streamblock4.SetAutoFrameLength_ratebased() streamblock4.SetInsertSig_ratebased('TRUE') streamblock4.SetFrameConfig_ratebased(frameconfig=frame_4) # [Step 1.2]: create streamblock5 IP_match self.logger.info('[Step 1.2]: creating streamblock5...') frame_5 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble>fb555555555555d5</preamble><dstMac>00:00:00:00:00:99</dstMac><srcMac>00:00:00:00:00:01</srcMac></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>2001::1</sourceAddr><destAddr>2001::11</destAddr></pdu></pdus></config></frame>' streamblock5 = port1.addstreamblock() streamblock5.SetAutoFrameLength_ratebased() streamblock5.SetInsertSig_ratebased('TRUE') streamblock5.SetFrameConfig_ratebased(frameconfig=frame_5) # [Step 1.2]: create streamblock6 IP_not_match self.logger.info('[Step 1.2]: creating streamblock6...') frame_6 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble>fb555555555555d5</preamble><dstMac>00:00:00:00:00:99</dstMac><srcMac>00:00:00:00:00:0A</srcMac></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>2001::1</sourceAddr><destAddr>2001::11</destAddr></pdu></pdus></config></frame>' streamblock6 = port1.addstreamblock() streamblock6.SetAutoFrameLength_ratebased() streamblock6.SetInsertSig_ratebased('TRUE') streamblock6.SetFrameConfig_ratebased(frameconfig=frame_6) # [Step 1.2]: create streamblock7 NA_match self.logger.info('[Step 1.2]: creating streamblock7...') frame_7 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble minByteLength="8" >fb555555555555d5</preamble><dstMac>33:33:FF:00:00:22</dstMac><srcMac>00:00:00:00:00:02</srcMac><vlans name="anon_20703"><Vlan name="Vlan"><pri>000</pri><id>4094</id></Vlan></vlans></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>2001::2</sourceAddr><destAddr>2001::22</destAddr></pdu><pdu name="NeighborAdvertisement_1" pdu="icmpv6:NeighborAdvertisement"><targetAddress>2001::22</targetAddress></pdu></pdus></config></frame>' streamblock7 = port1.addstreamblock() streamblock7.SetAutoFrameLength_ratebased() streamblock7.SetInsertSig_ratebased('TRUE') streamblock7.SetFrameConfig_ratebased(frameconfig=frame_7) # [Step 1.2]: create streamblock8 NA_mac_not_match self.logger.info('[Step 1.2]: creating streamblock8...') frame_8 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble minByteLength="8" >fb555555555555d5</preamble><dstMac>33:33:FF:00:00:22</dstMac><srcMac>00:00:00:00:00:0B</srcMac><vlans name="anon_20712"><Vlan name="Vlan"><pri>000</pri><id>4094</id></Vlan></vlans></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>2001::2</sourceAddr><destAddr>2001::22</destAddr></pdu><pdu name="NeighborAdvertisement_1" pdu="icmpv6:NeighborAdvertisement"><targetAddress>2001::22</targetAddress></pdu></pdus></config></frame>' streamblock8 = port1.addstreamblock() streamblock8.SetAutoFrameLength_ratebased() streamblock8.SetInsertSig_ratebased('TRUE') streamblock8.SetFrameConfig_ratebased(frameconfig=frame_8) # [Step 1.2]: create streamblock9 NA_ip_not_match self.logger.info('[Step 1.2]: creating streamblock9...') frame_9 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble minByteLength="8" >fb555555555555d5</preamble><dstMac>33:33:FF:00:00:22</dstMac><srcMac>00:00:00:00:00:02</srcMac><vlans name="anon_20721"><Vlan name="Vlan"><pri>000</pri><id>4094</id></Vlan></vlans></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>2001::b</sourceAddr><destAddr>2001::22</destAddr></pdu><pdu name="NeighborAdvertisement_1" pdu="icmpv6:NeighborAdvertisement"><targetAddress>2001::22</targetAddress></pdu></pdus></config></frame>' streamblock9 = port1.addstreamblock() streamblock9.SetAutoFrameLength_ratebased() streamblock9.SetInsertSig_ratebased('TRUE') streamblock9.SetFrameConfig_ratebased(frameconfig=frame_9) # [Step 1.2]: create streamblock10 NA_vlan_not_match self.logger.info('[Step 1.2]: creating streamblock10...') frame_10 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble minByteLength="8" >fb555555555555d5</preamble><dstMac>33:33:FF:00:00:22</dstMac><srcMac>00:00:00:00:00:02</srcMac><vlans name="anon_20730"><Vlan name="Vlan"><pri>000</pri><id>1</id></Vlan></vlans></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>2001::2</sourceAddr><destAddr>2001::22</destAddr></pdu><pdu name="NeighborAdvertisement_1" pdu="icmpv6:NeighborAdvertisement"><targetAddress>2001::22</targetAddress></pdu></pdus></config></frame>' streamblock10 = port1.addstreamblock() streamblock10.SetAutoFrameLength_ratebased() streamblock10.SetInsertSig_ratebased('TRUE') streamblock10.SetFrameConfig_ratebased(frameconfig=frame_10) # [Step 1.2]: create streamblock11 IP_match self.logger.info('[Step 1.2]: creating streamblock11...') frame_11 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble minByteLength="8" >fb555555555555d5</preamble><dstMac>00:00:00:00:00:22</dstMac><srcMac>00:00:00:00:00:02</srcMac><vlans name="anon_20739"><Vlan name="Vlan"><pri>000</pri><id>4094</id></Vlan></vlans></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>2001::2</sourceAddr><destAddr>2001::22</destAddr></pdu></pdus></config></frame>' streamblock11 = port1.addstreamblock() streamblock11.SetAutoFrameLength_ratebased() streamblock11.SetInsertSig_ratebased('TRUE') streamblock11.SetFrameConfig_ratebased(frameconfig=frame_11) # [Step 1.2]: create streamblock12 IP_not_match self.logger.info('[Step 1.2]: creating streamblock12...') frame_12 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble minByteLength="8" >fb555555555555d5</preamble><dstMac>00:00:00:00:00:22</dstMac><srcMac>00:00:00:00:00:0A</srcMac><vlans name="anon_20746"><Vlan name="Vlan"><pri>000</pri><id>4094</id></Vlan></vlans></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>2001::2</sourceAddr><destAddr>2001::22</destAddr></pdu></pdus></config></frame>' streamblock12 = port1.addstreamblock() streamblock12.SetAutoFrameLength_ratebased() streamblock12.SetInsertSig_ratebased('TRUE') streamblock12.SetFrameConfig_ratebased(frameconfig=frame_12) # [Step 1.2]: create streamblock13 RS_match self.logger.info('[Step 1.2]: creating streamblock13...') frame_13 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble>fb555555555555d5</preamble><dstMac>33:33:00:00:00:02</dstMac><srcMac>00:00:00:00:00:01</srcMac></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>FE80::0200:00FF:FE00:0001</sourceAddr><destAddr>FF02::2</destAddr></pdu><pdu name="RouterSolicitation_1" pdu="icmpv6:RouterSolicitation"><linkLayerOption name="anon_22242"><LinkLayerAddress name="LinkLayerAddress_0"><value>000000000001</value></LinkLayerAddress></linkLayerOption></pdu></pdus></config></frame>' streamblock13 = port1.addstreamblock() streamblock13.SetAutoFrameLength_ratebased() streamblock13.SetInsertSig_ratebased('TRUE') streamblock13.SetFrameConfig_ratebased(frameconfig=frame_13) # [Step 1.2]: create streamblock14 RS_not_match self.logger.info('[Step 1.2]: creating streamblock14...') frame_14 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble>fb555555555555d5</preamble><dstMac>33:33:00:00:00:02</dstMac><srcMac>00:00:00:00:00:11</srcMac></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>FE80::0200:00FF:FE00:0011</sourceAddr><destAddr>FF02::2</destAddr></pdu><pdu name="RouterSolicitation_1" pdu="icmpv6:RouterSolicitation"><linkLayerOption name="anon_22373"><LinkLayerAddress name="LinkLayerAddress_0"><value>000000000011</value></LinkLayerAddress></linkLayerOption></pdu></pdus></config></frame>' streamblock14 = port1.addstreamblock() streamblock14.SetAutoFrameLength_ratebased() streamblock14.SetInsertSig_ratebased('TRUE') streamblock14.SetFrameConfig_ratebased(frameconfig=frame_14) # [Step 1.2]: create streamblock15 RA_MATCH_not_pass self.logger.info('[Step 1.2]: creating streamblock15...') frame_15 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble>fb555555555555d5</preamble><dstMac>33:33:00:00:00:01</dstMac><srcMac>00:00:00:00:00:01</srcMac></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>FE80::0200:00FF:FE00:0001</sourceAddr><destAddr>FF02::1</destAddr></pdu><pdu name="RouterAdvertisement_1" pdu="icmpv6:RouterAdvertisement"><routerLifetime>3600</routerLifetime><reachableTime>3600</reachableTime><prefixOption name="anon_23046"><PrefixInformation name="PrefixInformation_0"><validLifetime>3600</validLifetime><preferredLifetime>3600</preferredLifetime><prefix>3001::</prefix></PrefixInformation></prefixOption></pdu></pdus></config></frame>' streamblock15 = port1.addstreamblock() streamblock15.SetAutoFrameLength_ratebased() streamblock15.SetInsertSig_ratebased('TRUE') streamblock15.SetFrameConfig_ratebased(frameconfig=frame_15) # [Step 1.2]: create streamblock16 RR_MATCH_not_pass self.logger.info('[Step 1.2]: creating streamblock16...') frame_16 = '<frame><config><pdus><pdu name="eth1" pdu="ethernet:EthernetII"><preamble>fb555555555555d5</preamble><dstMac>33:33:00:00:00:01</dstMac><srcMac>00:00:00:00:00:01</srcMac></pdu><pdu name="proto1" pdu="ipv6:IPv6"><payloadLength>0</payloadLength><sourceAddr>FE80::0200:00FF:FE00:0001</sourceAddr><destAddr>FF02::1</destAddr></pdu><pdu name="Redirect_1" pdu="icmpv6:Redirect"></pdu></pdus></config></frame>' streamblock16 = port1.addstreamblock() streamblock16.SetAutoFrameLength_ratebased() streamblock16.SetInsertSig_ratebased('TRUE') streamblock16.SetFrameConfig_ratebased(frameconfig=frame_16) # [Step 1.2]: save stc config self.logger.info('[Step 1.2]: saving stc config...') stc.StcControl.Apply('stc') stc.StcControl.SaveToTcc('stc', 'ts887553.tcc') ########################################################发流测试############################################################ step_2 = 'Step 2. glabal : disable, vlan_1: disable, vlan_1_log: disable, vlan_4094: disable, vlan_4094_log: disable, send: S1-12' self.logger.info(step_2) client1.dut_iface.exec_command('no ipv6 nd detection') client1.dut_iface.exec_command('no ipv6 nd detection vlan 1,4094') client1.dut_iface.exec_command('no ipv6 nd detection vlan 1,4094 logging') network_security_global_config.send_streamblock_and_check(stc, result, [streamblock1, streamblock2, streamblock3, streamblock4, streamblock5, streamblock6, streamblock7, streamblock8, streamblock9, streamblock10, streamblock11, streamblock12], port1, port2,{port2.port: '12'}, step_2) # log check step_3 = 'Step 3. glabal : disable, vlan_1: disable, vlan_1_log: disable, vlan_4094: enable, vlan_4094_log: enable, send: S1-12' self.logger.info(step_2) client1.dut_iface.exec_command('no ipv6 nd detection') client1.dut_iface.exec_command('no ipv6 nd detection vlan 1') client1.dut_iface.exec_command('no ipv6 nd detection vlan 1 logging') client1.dut_iface.exec_command('ipv6 nd detection vlan 4094') client1.dut_iface.exec_command('ipv6 nd detection vlan 4094 logging') network_security_global_config.send_streamblock_and_check(stc, result, [streamblock1, streamblock2, streamblock3, streamblock4, streamblock5, streamblock6, streamblock7, streamblock8, streamblock9, streamblock10, streamblock11, streamblock12], port1, port2, {port2.port: '12'}, step_2) # log check except Exception as e: # break test by exception result.add_result(passfail=ResultInfo.FAIL, test_comment='Test fail: %s' % e) finally: return result def clean_test(self): try: self.logger.info('[clean_test] start to clean test...') except Exception as e: self.logger.error('[clean_test] clean test failed: %s' % e) raise e 下发完输入2中的CLI,我们应该可以创流发流了,我给的这个参考代码是一个standalone代码,但是这个代码的流和我的用例中的16条流一致,而且创流发流这个操作controller和standalone应该没有区别,你参考这个来帮我接着写吧,写到输入2中发完16条流为止,从step3下发完CLI开始
09-01
<think>嗯,用户让我介绍或者回答关于<STX><CodeContent><CR><LF>的内容。首先,我需要确定这几个符号和标签的含义和用途。 先拆解每个部分。STX是ASCII中的控制字符,代表Start of Text,通常用于数据流的开始。CodeContent可能指代码内容,但具体格式不明确。CR和LF分别是回车和换行符,常见于不同操作系统的换行处理。 用户可能是在问这些字符在编程或数据传输中的应用。比如,在通信协议中,STX可能用来标识数据段的开始,后面跟着实际内容,然后以CRLF结束。例如,某些串口通信或文件格式会使用这些控制字符来分隔数据段。 需要进一步考虑用户的使用场景。可能是遇到了数据传输解析的问题,或者对协议格式有疑问。比如,当处理来自传感器的数据时,数据包可能以STX开头,包含具体信息,以CRLF结尾。解析时需识别这些控制字符来正确提取内容。 还要检查是否有常见的误解。例如,CR和LF在不同系统(如Windows和Unix)中的换行表示差异,可能导致文本处理问题。或者,在解析数据时未正确处理STX和ETX(End of Text),导致数据截断或包含多余字符。 另外,用户提供的系统级指令要求数学公式用$...$和$$...$$格式,但当前问题不涉及数学内容,可能需要确认用户是否有其他意图,或者是否在传输过程中遇到了编码问题,比如特殊字符被错误解析为LaTeX公式。 总结,用户可能需要了解这些控制字符在特定上下文中的作用,比如数据传输协议中的使用,或者处理相关问题时的方法。需要给出结构清晰的解释,包括每个符号的定义、常见应用场景以及可能遇到的问题和解决方法。</think>关于您提到的`<STX><CodeContent><CR><LF>`,这是涉及通信协议或数据传输中常见的控制字符组合。以下是逐步解释: --- ### 1. **各字符的定义** - **`<STX>`**(Start of Text): ASCII 控制字符(十六进制 `0x02`),标记数据内容的开始,用于分隔数据包头和实际传输内容。 - **`<CodeContent>`**: 需要传输的实际数据内容,可能是文本、二进制数据或特定编码格式的信息。 - **`<CR><LF>`**(Carriage Return + Line Feed): 组合控制符(十六进制 `0x0D 0x0A`),表示回车换行。常见于Windows系统文本文件的行尾标记。 --- ### 2. **典型应用场景** #### 示例:串口通信协议 假设某传感器通过串口发送数据,协议格式可能如下: ``` <STX>温度:25.5℃,湿度:60%<CR><LF> ``` - **`<STX>`** 表示数据开始,接收端通过检测此字符确认数据起点。 - **`温度:25.5℃,湿度:60%`** 是实际传输的内容(`<CodeContent>`)。 - **`<CR><LF>`** 表示数据结束,帮助接收端识别数据边界。 --- ### 3. **常见问题与解决方法** #### 问题1:数据解析错误 - **现象**:接收端未正确提取 `<CodeContent>`。 - **原因**:未正确处理 `<STX>` 和 `<CR><LF>` 的分隔符。 - **解决**: 使用状态机解析数据流: 1. 等待 `<STX>` 字符。 2. 捕获后续字符直至遇到 `<CR><LF>`。 3. 提取中间内容作为有效数据。 #### 问题2:跨平台换行符差异 - **现象**:Linux/Mac 系统解析 Windows 生成的文本时出现乱码。 - **原因**:Linux 使用 `<LF>`,Mac 旧版本使用 `<CR>` 作为换行符。 - **解决**: 统一使用 `<CR><LF>` 或在解析时兼容多种换行符。 --- ### 4. **代码示例(Python)** 假设从串口读取数据并解析 `<STX>...<CR><LF>` 格式: ```python import serial ser = serial.Serial('/dev/ttyUSB0', 9600) buffer = "" while True: char = ser.read().decode('ascii', errors='ignore') if char == '\x02': # 检测到 <STX> buffer = "" elif char == '\r': # 检测到 <CR> next_char = ser.read().decode('ascii', errors='ignore') if next_char == '\n': # 检测到 <LF> print("收到数据:", buffer) buffer = "" else: buffer += char ``` --- ### 5. **扩展知识** - **`<ETX>`**(End of Text,`0x03`):标记数据结束,与 `<STX>` 配对使用。 - **转义字符**:若 `<CodeContent>` 中包含 `<STX>` 或 `<CR><LF>`,需定义转义规则(如使用 `<DLE>`)。 如需更具体的应用场景分析,请提供更多上下文信息!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值