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

📄 print.cc

📁 COPE the first practical network coding scheme which is developped on click
💻 CC
字号:
/* * print.{cc,hh} -- element prints packet contents to system log * John Jannotti, Eddie Kohler * * Copyright (c) 1999-2000 Massachusetts Institute of Technology * * 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 "print.hh"#include <click/glue.hh>#include <click/confparse.hh>#include <click/error.hh>#include <click/straccum.hh>#ifdef CLICK_LINUXMODULE# include <click/cxxprotect.h>CLICK_CXX_PROTECT# include <linux/sched.h>CLICK_CXX_UNPROTECT# include <click/cxxunprotect.h>#endifCLICK_DECLSPrint::Print()  : Element(1, 1){}Print::~Print(){}intPrint::configure(Vector<String> &conf, ErrorHandler* errh){  bool timestamp = false;#ifdef CLICK_LINUXMODULE  bool print_cpu = false;#endif  bool print_anno = false;  String label;  unsigned bytes = 24;    if (cp_va_parse(conf, this, errh,		  cpOptional,		  cpString, "label", &label,		  cpInteger, "max bytes to print", &bytes,		  cpKeywords,		  "NBYTES", cpInteger, "max bytes to print", &bytes,		  "TIMESTAMP", cpBool, "print packet timestamps?", &timestamp,		  "PRINTANNO", cpBool, "print packet annotation bytes?", &print_anno,#ifdef CLICK_LINUXMODULE		  "CPU", cpBool, "print CPU IDs?", &print_cpu,#endif		  cpEnd) < 0)    return -1;    _label = label;  _bytes = bytes;  _timestamp = timestamp;  _print_anno = print_anno;#ifdef CLICK_LINUXMODULE  _cpu = print_cpu;#endif  return 0;}Packet *Print::simple_action(Packet *p){    StringAccum sa(_label.length() + 2 // label:		   + 6		// (processor)		   + 28		// timestamp:		   + 9		// length |		   + Packet::USER_ANNO_SIZE*2 + 3 // annotations |		   + 3 * _bytes);    if (sa.out_of_memory()) {	click_chatter("no memory for Print");	return p;    }  sa << _label;#ifdef CLICK_LINUXMODULE  if (_cpu)    sa << '(' << click_current_processor() << ')';#endif  if (_label)    sa << ": ";  if (_timestamp)    sa << p->timestamp_anno() << ": ";  // sa.reserve() must return non-null; we checked capacity above  int len;  len = sprintf(sa.reserve(9), "%4d | ", p->length());  sa.forward(len);  if (_print_anno) {    char *buf = sa.reserve(Packet::USER_ANNO_SIZE*2);    int pos = 0;    for (unsigned j = 0; j < Packet::USER_ANNO_SIZE; j++, pos += 2)       sprintf(buf + pos, "%02x", p->user_anno_c(j));    sa.forward(pos);        len = sprintf(sa.reserve(3), " | ");    sa.forward(len);  }  char *buf = sa.data() + sa.length();  int pos = 0;  for (unsigned i = 0; i < _bytes && i < p->length(); i++) {    sprintf(buf + pos, "%02x", p->data()[i] & 0xff);    pos += 2;    if ((i % 4) == 3) buf[pos++] = ' ';  }  sa.forward(pos);  click_chatter("%s", sa.cc());  return p;}CLICK_ENDDECLSEXPORT_ELEMENT(Print)ELEMENT_MT_SAFE(Print)

⌨️ 快捷键说明

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