/// <summary> /// 创建 /// </summary> /// <param name="ethernetFrameType">ethernetFrameType</param> /// <param name="bytes">数据</param> /// <returns></returns> public static Octets Create(EthernetFrameType ethernetFrameType, Memory <Byte> bytes) { if (EthernetFrameTypeMap.ContainsKey(ethernetFrameType)) { return(EthernetFrameTypeMap[ethernetFrameType](bytes)); } return(Default(bytes)); }
public void Get(EthernetFrameType input, Type excepted) { var ethernetFrame = new EthernetFrame { Bytes = new Byte[64] }; ethernetFrame.Type = input; ethernetFrame.Payload.GetType().Should().Be(excepted); }
public void Get(EthernetFrameType input, Type excepted) { var vlanFrame = new VLANFrame { Bytes = new Byte[32] }; vlanFrame.Type = input; vlanFrame.Payload.GetType().Should().Be(excepted); }
public void Get(Byte[] input, EthernetFrameType expected) { var ethernetFrame = new EthernetFrame { Bytes = new Byte[14] }; ethernetFrame.SetBytes(12, 2, input); ethernetFrame.Type.Should().Be(expected); }
public void Get(Byte[] input, EthernetFrameType expected) { var vlanFrame = new VLANFrame { Bytes = new Byte[4] }; vlanFrame.SetBytes(2, 2, input); vlanFrame.Type.Should().Be(expected); }
public void Set(Byte[] expected, EthernetFrameType input) { var ethernetFrame = new EthernetFrame { Bytes = new Byte[14] }; ethernetFrame.Type = input; ethernetFrame.GetBytes(12, 2).ToArray().Should().Equal(expected); ethernetFrame.Type.Should().Be(input); }
public void Set(Byte[] expected, EthernetFrameType input) { var vlanFrame = new VLANFrame { Bytes = new Byte[4] }; vlanFrame.Type = input; vlanFrame.GetBytes(2, 2).ToArray().Should().Equal(expected); vlanFrame.Type.Should().Be(input); }
public void Set(Byte[] expected, EthernetFrameType input) { var arpFrame = new ARPFrame { Bytes = new Byte[28] }; arpFrame.ProtocolType = input; arpFrame.GetBytes(2, 2).ToArray().Should().Equal(expected); arpFrame.ProtocolType.Should().Be(input); }
public void Get(Byte[] input, EthernetFrameType expected) { var arpFrame = new ARPFrame { Bytes = new Byte[28] }; arpFrame.SetBytes(2, 2, input); arpFrame.ProtocolType.Should().Be(expected); }
/// <summary> /// 构建负载部分 /// </summary> /// <param name="ethernetFrameType"></param> /// <param name="payloadBytes"></param> /// <returns></returns> public static Octets BuildPayload(EthernetFrameType ethernetFrameType, Memory <Byte> payloadBytes) { switch (ethernetFrameType) { case EthernetFrameType.IPv4: return(new IPv4Packet { Bytes = payloadBytes }); case EthernetFrameType.IPv6: return(new IPv6Packet { Bytes = payloadBytes }); case EthernetFrameType.ARP: return(new ARPFrame { Bytes = payloadBytes }); case EthernetFrameType.VLAN: return(new VLANFrame { Bytes = payloadBytes }); case EthernetFrameType.PPPoEDiscoveryStage: case EthernetFrameType.PPPoESessionStage: return(new PPPoEFrame { Bytes = payloadBytes }); default: return(new Octets { Bytes = payloadBytes }); } }