ethertap.hh revision 2665
12968SN/A/*
22968SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan
32968SN/A * All rights reserved.
49988Snilay@cs.wisc.edu *
58835SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without
69988Snilay@cs.wisc.edu * modification, are permitted provided that the following conditions are
77935SN/A * met: redistributions of source code must retain the above copyright
87935SN/A * notice, this list of conditions and the following disclaimer;
97935SN/A * redistributions in binary form must reproduce the above copyright
102968SN/A * notice, this list of conditions and the following disclaimer in the
112968SN/A * documentation and/or other materials provided with the distribution;
122968SN/A * neither the name of the copyright holders nor the names of its
1310315Snilay@cs.wisc.edu * contributors may be used to endorse or promote products derived from
144463SN/A * this software without specific prior written permission.
152968SN/A *
169885Sstever@gmail.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
179885Sstever@gmail.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1810315Snilay@cs.wisc.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
199988Snilay@cs.wisc.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202968SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2110315Snilay@cs.wisc.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2210315Snilay@cs.wisc.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
237670SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2410315Snilay@cs.wisc.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252968SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
269481Snilay@cs.wisc.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
278721SN/A *
2810736Snilay@cs.wisc.edu * Authors: Nathan Binkert
298721SN/A */
3010315Snilay@cs.wisc.edu
3110315Snilay@cs.wisc.edu/* @file
323140SN/A * Interface to connect a simulated ethernet device to the real world
332968SN/A */
342968SN/A
357935SN/A#ifndef __ETHERTAP_HH__
367935SN/A#define __ETHERTAP_HH__
377935SN/A
387935SN/A#include <queue>
397935SN/A#include <string>
407935SN/A
417935SN/A#include "dev/etherint.hh"
428983Snate@binkert.org#include "dev/etherpkt.hh"
432968SN/A#include "sim/eventq.hh"
442968SN/A#include "base/pollevent.hh"
452968SN/A#include "sim/sim_object.hh"
469885Sstever@gmail.com
474463SN/Aclass TapEvent;
489988Snilay@cs.wisc.educlass TapListener;
498721SN/A
508721SN/A/*
518721SN/A * Interface to connect a simulated ethernet device to the real world
528983Snate@binkert.org */
538983Snate@binkert.orgclass EtherTap : public EtherInt
542968SN/A{
559885Sstever@gmail.com  protected:
569885Sstever@gmail.com    friend class TapEvent;
579885Sstever@gmail.com    TapEvent *event;
5810315Snilay@cs.wisc.edu
599988Snilay@cs.wisc.edu  protected:
6010315Snilay@cs.wisc.edu    friend class TapListener;
619885Sstever@gmail.com    TapListener *listener;
629885Sstever@gmail.com    int socket;
632968SN/A    char *buffer;
642968SN/A    int buflen;
659481Snilay@cs.wisc.edu    int32_t buffer_offset;
6610315Snilay@cs.wisc.edu    int32_t data_len;
675876SN/A
689885Sstever@gmail.com    EtherDump *dump;
693171SN/A
703638SN/A    void attach(int fd);
713638SN/A    void detach();
723638SN/A
732968SN/A  protected:
749988Snilay@cs.wisc.edu    std::string device;
758983Snate@binkert.org    std::queue<EthPacketPtr> packetBuffer;
762968SN/A
772968SN/A    void process(int revent);
785723SN/A    void enqueue(EthPacketData *packet);
799481Snilay@cs.wisc.edu    void retransmit();
802968SN/A
812968SN/A    /*
822968SN/A     */
832968SN/A    class TxEvent : public Event
842968SN/A    {
855575SN/A      protected:
862968SN/A        EtherTap *tap;
873140SN/A
889885Sstever@gmail.com      public:
895509SN/A        TxEvent(EtherTap *_tap)
905509SN/A            : Event(&mainEventQueue), tap(_tap) {}
9110315Snilay@cs.wisc.edu        void process() { tap->retransmit(); }
929481Snilay@cs.wisc.edu        virtual const char *description() { return "retransmit event"; }
932968SN/A    };
944938SN/A
952968SN/A    friend class TxEvent;
968835SAli.Saidi@ARM.com    TxEvent txEvent;
974463SN/A
984463SN/A  public:
994463SN/A    EtherTap(const std::string &name, EtherDump *dump, int port, int bufsz);
1004463SN/A    virtual ~EtherTap();
10111103Snilay@cs.wisc.edu
1029885Sstever@gmail.com    virtual bool recvPacket(EthPacketPtr packet);
1038983Snate@binkert.org    virtual void sendDone();
1044463SN/A
1059885Sstever@gmail.com    virtual void serialize(std::ostream &os);
10610636Snilay@cs.wisc.edu    virtual void unserialize(Checkpoint *cp, const std::string &section);
1079988Snilay@cs.wisc.edu};
1086123SN/A
1099481Snilay@cs.wisc.edu#endif // __ETHERTAP_HH__
11011103Snilay@cs.wisc.edu