IP优先级、TOS优先级、DSCP优先级和802.1p优先级的区别

IP优先级、TOS优先级、DSCP优先级和802.1p优先级的区别

 

相关版本: NULL

关键字:IP优先级、TOS优先级、DSCP优先级和802.1p优先级的区别

作者:anyu

问题描述:

 以太网交换机可为特定报文提供优先级标记的服务,优先级的种类包括Precedence,TOS、DSCP、802.1p prioriy等,这些优先级分别适用于不同的QoS 模型,在不同的模型中被定义。Precedence、TOS和DSCP优先级是定义在三层IP头中的TOS字段;802.1p用户优先级定义在二层802.1Q 标签头中的TCI字段中。



IP header 有一个8-bit的TOS(服务类型)优先级区域,它通常被分为precedence部分(IP优先级)和TOS部分,最后一位作保留;它的具体定义如下:


由于对区分服务类型的多样化的要求,在之后的RFC文档中对这个区域进行了重新的分配,命名为DSCP:也就是IP包头的区分服务标记域。DSCP优先级是把整个8位的前6位重新定义了一下,称为DSCP优先级;


数据帧里有4个字节的802。1q标签头,包含2字节的标签和2字节的控制信息,在控制信息(vlan tag的TCI区域)的前3位,就定义为802.1p优先级。它指明帧的优先级。一共有8 种优先级,主要用于当交换机阻塞时,优先发送优先级高的数据包。


  • 3
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要经过TCP/IP协议栈发送802.1Q报文,需要在数据包中添加802.1Q VLAN标签,并将其发送到网络接口。以下是一个简单的示例程序,演示如何使用TCP/IP协议栈发送带有802.1Q VLAN标签的数据包: ```c++ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <arpa/inet.h> #include <net/ethernet.h> #include <net/if.h> #include <netinet/in.h> #include <netinet/ip.h> #include <netinet/tcp.h> #include <netinet/udp.h> #include <netinet/ip_icmp.h> #include <linux/if_packet.h> #include <linux/if_ether.h> #include <linux/if_vlan.h> int main() { int sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); if (sock < 0) { perror("socket"); exit(1); } char ifname[IFNAMSIZ] = "eth0"; struct ifreq ifr; strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1); if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0) { perror("ioctl"); exit(1); } struct sockaddr_ll addr; memset(&addr, 0, sizeof(addr)); addr.sll_family = AF_PACKET; addr.sll_ifindex = ifr.ifr_ifindex; // 构造802.1Q VLAN标签 struct vlan_tag { uint16_t tci; uint16_t ether_type; } __attribute__((packed)); struct vlan_tag vlan; vlan.tci = htons(0x100); vlan.ether_type = htons(ETH_P_IP); // 构造IP数据包 char ip_packet[ETH_FRAME_LEN]; struct iphdr *iph = (struct iphdr *)ip_packet; iph->version = 4; iph->ihl = 5; iph->tos = 0; iph->tot_len = htons(sizeof(struct iphdr) + sizeof(struct udphdr)); iph->id = htons(0); iph->frag_off = htons(0); iph->ttl = 64; iph->protocol = IPPROTO_UDP; iph->check = htons(0); iph->saddr = inet_addr("192.168.1.100"); iph->daddr = inet_addr("192.168.1.1"); // 构造UDP数据包 char udp_packet[ETH_FRAME_LEN]; struct udphdr *udph = (struct udphdr *)udp_packet; udph->source = htons(1234); udph->dest = htons(5678); udph->len = htons(sizeof(struct udphdr)); udph->check = htons(0); // 将IP头和UDP数据拷贝到数据包中 memcpy(ip_packet + sizeof(struct iphdr), udph, sizeof(struct udphdr)); // 将802.1Q VLAN标签和IP/UDP数据拷贝到数据包中 char packet[ETH_FRAME_LEN]; memcpy(packet, "\xff\xff\xff\xff\xff\xff", ETH_ALEN); memcpy(packet + ETH_ALEN, "\x00\x11\x22\x33\x44\x55", ETH_ALEN); memcpy(packet + 2 * ETH_ALEN, &vlan, sizeof(struct vlan_tag)); memcpy(packet + 2 * ETH_ALEN + sizeof(struct vlan_tag), ip_packet, sizeof(struct iphdr) + sizeof(struct udphdr)); // 发送数据包 if (sendto(sock, packet, 2 * ETH_ALEN + sizeof(struct vlan_tag) + sizeof(struct iphdr) + sizeof(struct udphdr), 0, (struct sockaddr *)&addr, sizeof(addr)) < 0) { perror("sendto"); exit(1); } close(sock); return 0; } ``` 该程序使用socket API创建了一个PF_PACKET类型的socket,并将其绑定到网络接口上。然后,程序构造了一个带有802.1Q VLAN标签的IP/UDP数据包,并将其封装成一个以太网帧。在构造802.1Q VLAN标签时,程序使用了vlan_tag结构体来定义标签格式,并将其添加到数据包的头部。最后,程序调用sendto函数将数据包发送到目标MAC地址。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值