ethertap.hh revision 11263
12SN/A/* 21762SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665SN/A * 282665SN/A * Authors: Nathan Binkert 292SN/A */ 302SN/A 312SN/A/* @file 322SN/A * Interface to connect a simulated ethernet device to the real world 332SN/A */ 342SN/A 3511263Sandreas.sandberg@arm.com#ifndef __DEV_NET_ETHERTAP_HH__ 3611263Sandreas.sandberg@arm.com#define __DEV_NET_ETHERTAP_HH__ 372SN/A 382SN/A#include <queue> 392SN/A#include <string> 402SN/A 414981SN/A#include "base/pollevent.hh" 4211263Sandreas.sandberg@arm.com#include "dev/net/etherint.hh" 4311263Sandreas.sandberg@arm.com#include "dev/net/etherobject.hh" 4411263Sandreas.sandberg@arm.com#include "dev/net/etherpkt.hh" 454981SN/A#include "params/EtherTap.hh" 4656SN/A#include "sim/eventq.hh" 4756SN/A#include "sim/sim_object.hh" 482SN/A 491872SN/Aclass TapEvent; 501872SN/Aclass TapListener; 514981SN/Aclass EtherTapInt; 521872SN/A 532SN/A/* 542SN/A * Interface to connect a simulated ethernet device to the real world 552SN/A */ 564981SN/Aclass EtherTap : public EtherObject 572SN/A{ 582SN/A protected: 592SN/A friend class TapEvent; 602SN/A TapEvent *event; 612SN/A 622SN/A protected: 632SN/A friend class TapListener; 642SN/A TapListener *listener; 652SN/A int socket; 662SN/A char *buffer; 672SN/A int buflen; 686227SN/A uint32_t buffer_offset; 696227SN/A uint32_t data_len; 702SN/A 712SN/A EtherDump *dump; 722SN/A 732SN/A void attach(int fd); 742SN/A void detach(); 752SN/A 762SN/A protected: 772SN/A std::string device; 782566SN/A std::queue<EthPacketPtr> packetBuffer; 794981SN/A EtherTapInt *interface; 802SN/A 812SN/A void process(int revent); 822566SN/A void enqueue(EthPacketData *packet); 832SN/A void retransmit(); 842SN/A 852SN/A /* 862SN/A */ 872SN/A class TxEvent : public Event 882SN/A { 892SN/A protected: 902SN/A EtherTap *tap; 912SN/A 922SN/A public: 935606SN/A TxEvent(EtherTap *_tap) : tap(_tap) {} 942SN/A void process() { tap->retransmit(); } 955336SN/A virtual const char *description() const 965336SN/A { return "EtherTap retransmit"; } 972SN/A }; 982SN/A 992SN/A friend class TxEvent; 1002SN/A TxEvent txEvent; 1012SN/A 1022SN/A public: 1034981SN/A typedef EtherTapParams Params; 1044981SN/A EtherTap(const Params *p); 1052SN/A virtual ~EtherTap(); 1062SN/A 1074981SN/A const Params * 1084981SN/A params() const 1094981SN/A { 1104981SN/A return dynamic_cast<const Params *>(_params); 1114981SN/A } 1124981SN/A 11311169SN/A EtherInt *getEthPort(const std::string &if_name, int idx) override; 1144981SN/A 1152566SN/A virtual bool recvPacket(EthPacketPtr packet); 1162SN/A virtual void sendDone(); 117253SN/A 11811168SN/A void serialize(CheckpointOut &cp) const override; 11911168SN/A void unserialize(CheckpointIn &cp) override; 1202SN/A}; 1212SN/A 1224981SN/Aclass EtherTapInt : public EtherInt 1234981SN/A{ 1244981SN/A private: 1254981SN/A EtherTap *tap; 1264981SN/A public: 1274981SN/A EtherTapInt(const std::string &name, EtherTap *t) 1284981SN/A : EtherInt(name), tap(t) 1294981SN/A { } 1304981SN/A 1314981SN/A virtual bool recvPacket(EthPacketPtr pkt) { return tap->recvPacket(pkt); } 1324981SN/A virtual void sendDone() { tap->sendDone(); } 1334981SN/A}; 1344981SN/A 1354981SN/A 13611263Sandreas.sandberg@arm.com#endif // __DEV_NET_ETHERTAP_HH__ 137