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

📄 unqueue.cc

📁 COPE the first practical network coding scheme which is developped on click
💻 CC
字号:
// -*- c-basic-offset: 4 -*-/* * unqueue.{cc,hh} -- element pulls as many packets as possible from * its input, pushes them out its output * Eddie Kohler * * Copyright (c) 1999-2000 Massachusetts Institute of Technology * Copyright (c) 2002 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 "unqueue.hh"#include <click/confparse.hh>#include <click/error.hh>#include <click/standard/scheduleinfo.hh>CLICK_DECLSUnqueue::Unqueue()    : Element(1, 1), _task(this){}Unqueue::~Unqueue(){}intUnqueue::configure(Vector<String> &conf, ErrorHandler *errh){    _burst = 1;    _active = true;    return cp_va_parse(conf, this, errh,		       cpOptional,		       cpInteger, "burst size", &_burst,		       cpKeywords,		       "ACTIVE", cpBool, "is active?", &_active,		       cpEnd);}intUnqueue::initialize(ErrorHandler *errh){    _count = 0;    ScheduleInfo::initialize_task(this, &_task, _active, errh);    _signal = Notifier::upstream_empty_signal(this, 0, &_task);    if (_burst < 0)	_burst = 0x7FFFFFFFU;    else if (_burst == 0)	errh->warning("BURST size 0, no packets will be pulled");    return 0;}boolUnqueue::run_task(){    if (!_active)	return false;    int worked = 0;    while (worked < _burst) {	if (Packet *p = input(0).pull()) {	    worked++;	    output(0).push(p);	} else {	    if (!_signal) {		_count += worked;		return worked > 0;	    }	    break;	}    }        _task.fast_reschedule();    _count += worked;    return worked > 0;}#if 0 && defined(CLICK_LINUXMODULE)#if __i386__ && HAVE_INTEL_CPU/* Old prefetching code from run_task(). */  if (p_next) {    struct sk_buff *skb = p_next->skb();    asm volatile("prefetcht0 %0" : : "m" (skb->len));    asm volatile("prefetcht0 %0" : : "m" (skb->cb[0]));  }#endif#endifenum { H_COUNT, H_ACTIVE };StringUnqueue::read_param(Element *e, void *thunk){    Unqueue *u = (Unqueue *)e;    switch ((uintptr_t) thunk) {      case H_COUNT:	return String(u->_count) + "\n";      case H_ACTIVE:	return String(u->_active) + "\n";      default:	return "<error>\n";    }}int Unqueue::write_param(const String &conf, Element *e, void *thunk, ErrorHandler *errh){    Unqueue *u = (Unqueue *)e;    String s = cp_uncomment(conf);    switch ((uintptr_t) thunk) {      case H_ACTIVE:		// active	if (!cp_bool(s, &u->_active))	    return errh->error("active parameter must be boolean");    	if (u->_active && !u->_task.scheduled())	    u->_task.reschedule();	break;    }    return 0;}voidUnqueue::add_handlers(){    add_read_handler("count", read_param, (void *)H_COUNT);    add_read_handler("active", read_param, (void *)H_ACTIVE);    add_write_handler("active", write_param, (void *)H_ACTIVE);    add_task_handlers(&_task);}CLICK_ENDDECLSEXPORT_ELEMENT(Unqueue)ELEMENT_MT_SAFE(Unqueue)

⌨️ 快捷键说明

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