etherlink.cc revision 195
11689SN/A/* 29783Sandreas.hansson@arm.com * Copyright (c) 2003 The Regents of The University of Michigan 310239Sbinhpham@cs.rutgers.edu * All rights reserved. 47598Sminkyu.jeong@arm.com * 57598Sminkyu.jeong@arm.com * Redistribution and use in source and binary forms, with or without 67598Sminkyu.jeong@arm.com * modification, are permitted provided that the following conditions are 77598Sminkyu.jeong@arm.com * met: redistributions of source code must retain the above copyright 87598Sminkyu.jeong@arm.com * notice, this list of conditions and the following disclaimer; 97598Sminkyu.jeong@arm.com * redistributions in binary form must reproduce the above copyright 107598Sminkyu.jeong@arm.com * notice, this list of conditions and the following disclaimer in the 117598Sminkyu.jeong@arm.com * documentation and/or other materials provided with the distribution; 127598Sminkyu.jeong@arm.com * neither the name of the copyright holders nor the names of its 137598Sminkyu.jeong@arm.com * contributors may be used to endorse or promote products derived from 147598Sminkyu.jeong@arm.com * this software without specific prior written permission. 152326SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271689SN/A */ 281689SN/A 291689SN/A/* @file 301689SN/A * Device module for modelling a fixed bandwidth full duplex ethernet link 311689SN/A */ 321689SN/A 331689SN/A#include <cmath> 341689SN/A#include <deque> 351689SN/A#include <string> 361689SN/A#include <vector> 371689SN/A 381689SN/A#include "base/trace.hh" 391689SN/A#include "dev/etherdump.hh" 402665Ssaidi@eecs.umich.edu#include "dev/etherint.hh" 412665Ssaidi@eecs.umich.edu#include "dev/etherlink.hh" 421689SN/A#include "dev/etherpkt.hh" 431689SN/A#include "sim/builder.hh" 449944Smatt.horsnell@ARM.com#include "sim/universe.hh" 459944Smatt.horsnell@ARM.com 469944Smatt.horsnell@ARM.comusing namespace std; 471060SN/A 481060SN/AEtherLink::EtherLink(const std::string &name, EtherInt *i1, EtherInt *i2, 491689SN/A Tick speed, EtherDump *dump) 501060SN/A : SimObject(name) 511060SN/A{ 521060SN/A double rate = ((double)ticksPerSecond * 8.0) / (double)speed; 538230Snate@binkert.org 546658Snate@binkert.org link1 = new Link(name + ".link1", rate, dump); 558887Sgeoffrey.blake@arm.com link2 = new Link(name + ".link2", rate, dump); 562292SN/A 571717SN/A int1 = new Interface(name + ".int1", link1, link2); 588229Snate@binkert.org int2 = new Interface(name + ".int2", link2, link1); 598232Snate@binkert.org 609444SAndreas.Sandberg@ARM.com int1->setPeer(i1); 618232Snate@binkert.org i1->setPeer(int1); 629527SMatt.Horsnell@arm.com int2->setPeer(i2); 635529Snate@binkert.org i2->setPeer(int2); 641060SN/A} 656221Snate@binkert.org 666221Snate@binkert.orgEtherLink::~EtherLink() 671681SN/A{ 685529Snate@binkert.org delete link1; 692873Sktlim@umich.edu delete link2; 704329Sktlim@umich.edu 714329Sktlim@umich.edu delete int1; 724329Sktlim@umich.edu delete int2; 732292SN/A} 742292SN/A 752292SN/AEtherLink::Interface::Interface(const std::string &name, Link *tx, Link *rx) 762292SN/A : EtherInt(name), txlink(tx) 772820Sktlim@umich.edu{ 782292SN/A tx->setTxInt(this); 792820Sktlim@umich.edu rx->setRxInt(this); 802820Sktlim@umich.edu} 819444SAndreas.Sandberg@ARM.com 821060SN/AEtherLink::Link::Link(const std::string &name, double rate, EtherDump *d) 8310172Sdam.sunwoo@arm.com : Serializeable(name), txint(NULL), rxint(NULL), ticks_per_byte(rate), 8410172Sdam.sunwoo@arm.com dump(d), event(&mainEventQueue, this) 8510172Sdam.sunwoo@arm.com{} 8610172Sdam.sunwoo@arm.com 8710172Sdam.sunwoo@arm.comvoid 8810172Sdam.sunwoo@arm.comEtherLink::Link::txDone() 8910172Sdam.sunwoo@arm.com{ 9010172Sdam.sunwoo@arm.com if (dump) 9110172Sdam.sunwoo@arm.com dump->dump(packet); 9210172Sdam.sunwoo@arm.com 9310172Sdam.sunwoo@arm.com DPRINTF(Ethernet, "EtherLink packet received: len=%d\n", packet->length); 9410172Sdam.sunwoo@arm.com DDUMP(EthernetData, packet->data, packet->length); 9510172Sdam.sunwoo@arm.com 962292SN/A rxint->sendPacket(packet); 972292SN/A 982292SN/A packet = 0; 991060SN/A assert(!busy()); 1001060SN/A 1011060SN/A txint->sendDone(); 1021060SN/A} 1031060SN/A 1041060SN/Abool 1051681SN/AEtherLink::Link::transmit(PacketPtr pkt) 1066221Snate@binkert.org{ 1076221Snate@binkert.org if (busy()) { 1086221Snate@binkert.org DPRINTF(Ethernet, "EtherLink packet not sent, link busy\n"); 1096221Snate@binkert.org return false; 1102292SN/A } 1112292SN/A 1122820Sktlim@umich.edu DPRINTF(Ethernet, "EtherLink packet sent: len=%d\n", pkt->length); 1132820Sktlim@umich.edu DDUMP(EthernetData, pkt->data, pkt->length); 1142292SN/A 1152292SN/A packet = pkt; 1162820Sktlim@umich.edu int delay = (int)ceil(((double)pkt->length * ticks_per_byte) + 1.0); 1172820Sktlim@umich.edu DPRINTF(Ethernet, "EtherLink scheduling packet: delay=%d, (rate=%f)\n", 1182292SN/A delay, ticks_per_byte); 1192292SN/A event.schedule(curTick + delay); 1202292SN/A 1212292SN/A return true; 1222292SN/A} 1232292SN/A 1242292SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(EtherLink) 1252292SN/A 1261060SN/A SimObjectParam<EtherInt *> interface1; 1271060SN/A SimObjectParam<EtherInt *> interface2; 1281681SN/A Param<int> link_speed; 1291062SN/A SimObjectParam<EtherDump *> packet_dump; 13010023Smatt.horsnell@ARM.com 13110023Smatt.horsnell@ARM.comEND_DECLARE_SIM_OBJECT_PARAMS(EtherLink) 13210023Smatt.horsnell@ARM.com 13310023Smatt.horsnell@ARM.comBEGIN_INIT_SIM_OBJECT_PARAMS(EtherLink) 13410023Smatt.horsnell@ARM.com 13510023Smatt.horsnell@ARM.com INIT_PARAM(interface1, "interface 1"), 13610023Smatt.horsnell@ARM.com INIT_PARAM(interface2, "interface 2"), 13710023Smatt.horsnell@ARM.com INIT_PARAM_DFLT(link_speed, "link speed in bits per second", 100000000), 1382292SN/A INIT_PARAM_DFLT(packet_dump, "object to dump network packets to", NULL) 1391062SN/A 1402301SN/AEND_INIT_SIM_OBJECT_PARAMS(EtherLink) 1412301SN/A 1421062SN/ACREATE_SIM_OBJECT(EtherLink) 1432727Sktlim@umich.edu{ 1441062SN/A return new EtherLink(getInstanceName(), interface1, interface2, link_speed, 1451062SN/A packet_dump); 1461062SN/A} 1471062SN/A 1481062SN/AREGISTER_SIM_OBJECT("EtherLink", EtherLink) 1491062SN/A