Explicit congestion notification
显式拥塞通知。
ECN支持端到端的网络拥塞通知来防止丢包。如果一个终端支持ECN,它会将ipv4.ecn的值设为1或2.对这样的包,每一个switch可能改变它的值为3,如果队列长度大于一个阈值。接受者会将值复制给发送者,并且发送者会减慢发送速度。
在这个实验中,我们要完成:
-
把ipv包头中的8bits tos域改成6 bits diffserv和2 bits ecn
-
在出路由中对比当前的queue length和ECN_THRESHOLD,如果队列长度大于这个阈值,那么就会设置ecn = 3,而不是1和2.
-
修改checksum对应部分,将tos改成diffserv和ecn。
修改包头
如英文注释,只需要把tos部分改成diffserv和ecn
header ipv4_t {
bit<4> version;
bit<4> ihl;
bit<6> diffserv; //transform tos into these two lines: diffserv and ecn
bit<2> ecn;
bit<16> totalLen;
bit<16> identification;
bit<3> flags;
bit<13> fragOffset;
bit<8> ttl;
bit<8> protocol;
bit<16> hdrChecksum;
ip4Addr_t srcAddr;
ip4Addr_t dstAddr;
}
修改出路由
语法和C语言很像,下面if部分都是我们添加的。
control MyEgress(inout headers hdr,
inout metadata meta,
inout standard_metadata_t standard_metadata) {
apply {
/*
* TODO:
* - if ecn is 1 or 2
* - compare standard_metadata.enq_qdepth with threshold
* and set hdr.ipv4.ecn to 3 if larger
*/
if (hdr.ipv4.ecn == 1 || hdr.ipv4.ecn == 2) { //these 4 lines are added.
if (standard_metadata.enq_qdepth > ECN_THRESHOLD)
hdr.ipv4.ecn = 3;
}
}
}
修改checksum
照着改就行了,没什么难的
control MyComputeChecksum(inout headers hdr, inout metadata meta) {
apply {
/* TODO: replace tos with diffserve and ecn */
update_checksum(
hdr.ipv4.isValid(),
{ hdr.ipv4.version,
hdr.ipv4.ihl,
hdr.ipv4.diffserv, //trans tos into ~
hdr.ipv4.ecn, //trans tos into ~
hdr.ipv4.totalLen,
hdr.ipv4.identification,
hdr.ipv4.flags,
hdr.ipv4.fragOffset,
hdr.ipv4.ttl,
hdr.ipv4.protocol,
hdr.ipv4.srcAddr,
hdr.ipv4.dstAddr },
hdr.ipv4.hdrChecksum,
HashAlgorithm.csum16);
}
}
改完,对着readme运行就行了,可以看到其中的确有一段tos变成了0x3,说明网络的确发生了拥塞。