⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 markipce.cc

📁 COPE the first practical network coding scheme which is developped on click
💻 CC
字号:
/* * markipce.{cc,hh} -- element marks IP header ECN CE bit * Eddie Kohler * * Copyright (c) 2001 International Computer Science Institute * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, subject to the conditions * listed in the Click LICENSE file. These conditions include: you must * preserve this copyright notice, and you cannot mention the copyright * holders in advertising related to the Software without their permission. * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This * notice is a summary of the Click LICENSE file; the license in that file is * legally binding. */#include <click/config.h>#include "markipce.hh"#include <clicknet/ip.h>#include <click/confparse.hh>#include <click/error.hh>CLICK_DECLSMarkIPCE::MarkIPCE()  : Element(1, 1){}MarkIPCE::~MarkIPCE(){}intMarkIPCE::initialize(ErrorHandler *){  _drops = 0;  return 0;}inline Packet *MarkIPCE::smaction(Packet *p){  const click_ip *iph = p->ip_header();  if (!iph || (iph->ip_tos & IP_ECNMASK) == IP_ECN_NOT_ECT) {    p->kill();    return 0;  } else if ((iph->ip_tos & IP_ECNMASK) == IP_ECN_CE)    return p;  else {    WritablePacket *q = p->uniqueify();    click_ip *q_iph = q->ip_header();      // incrementally update IP checksum    // new_sum = ~(~old_sum + ~old_halfword + new_halfword)    //         = ~(~old_sum + ~old_halfword + (old_halfword + 0x0001))    //         = ~(~old_sum + ~old_halfword + old_halfword + 0x0001)    //         = ~(~old_sum + ~0 + 0x0001)    //         = ~(~old_sum + 0x0001)    if ((q_iph->ip_tos & IP_ECNMASK) == IP_ECN_ECT2) {      unsigned sum = (~ntohs(q_iph->ip_sum) & 0xFFFF) + 0x0001;      q_iph->ip_sum = ~htons(sum + (sum >> 16));    } else {      unsigned sum = (~ntohs(q_iph->ip_sum) & 0xFFFF) + 0x0002;      q_iph->ip_sum = ~htons(sum + (sum >> 16));    }    q_iph->ip_tos |= IP_ECN_CE;        return q;  }}voidMarkIPCE::push(int, Packet *p){  if ((p = smaction(p)) != 0)    output(0).push(p);}Packet *MarkIPCE::pull(int){  Packet *p = input(0).pull();  if (p)    p = smaction(p);  return p;}StringMarkIPCE::read_handler(Element *e, void *){  MarkIPCE *m = (MarkIPCE *)e;  return String(m->_drops) + "\n";}voidMarkIPCE::add_handlers(){  add_read_handler("drops", read_handler, (void *)0);}CLICK_ENDDECLSEXPORT_ELEMENT(MarkIPCE)ELEMENT_MT_SAFE(MarkIPCE)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -