ethertap.hh revision 56
18012Ssaidi@eecs.umich.edu/*
28029Snate@binkert.org * Copyright (c) 2003 The Regents of The University of Michigan
38029Snate@binkert.org * All rights reserved.
48013Sbinkertn@umich.edu *
58029Snate@binkert.org * Redistribution and use in source and binary forms, with or without
68029Snate@binkert.org * modification, are permitted provided that the following conditions are
78029Snate@binkert.org * met: redistributions of source code must retain the above copyright
88029Snate@binkert.org * notice, this list of conditions and the following disclaimer;
98029Snate@binkert.org * redistributions in binary form must reproduce the above copyright
108029Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
118029Snate@binkert.org * documentation and/or other materials provided with the distribution;
128029Snate@binkert.org * neither the name of the copyright holders nor the names of its
138029Snate@binkert.org * contributors may be used to endorse or promote products derived from
148029Snate@binkert.org * this software without specific prior written permission.
158013Sbinkertn@umich.edu *
168029Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
178029Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
188029Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
198029Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
208029Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
218029Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
228029Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
238029Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
248029Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
258029Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
268029Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
278013Sbinkertn@umich.edu */
288013Sbinkertn@umich.edu
298012Ssaidi@eecs.umich.edu/* @file
308019Sbenash@umich.edu * Interface to connect a simulated ethernet device to the real world
318019Sbenash@umich.edu */
328019Sbenash@umich.edu
338019Sbenash@umich.edu#ifndef __ETHERTAP_HH__
348019Sbenash@umich.edu#define __ETHERTAP_HH__
358019Sbenash@umich.edu
368019Sbenash@umich.edu#include <queue>
378019Sbenash@umich.edu#include <string>
388019Sbenash@umich.edu
398019Sbenash@umich.edu#include "dev/etherint.hh"
408019Sbenash@umich.edu#include "dev/etherpkt.hh"
418019Sbenash@umich.edu#include "sim/eventq.hh"
428019Sbenash@umich.edu#include "base/pollevent.hh"
438019Sbenash@umich.edu#include "sim/sim_object.hh"
448019Sbenash@umich.edu
458019Sbenash@umich.edu/*
468019Sbenash@umich.edu * Interface to connect a simulated ethernet device to the real world
478019Sbenash@umich.edu */
488019Sbenash@umich.educlass EtherTap : public EtherInt
498019Sbenash@umich.edu{
508019Sbenash@umich.edu  protected:
518019Sbenash@umich.edu    friend class TapEvent;
528019Sbenash@umich.edu    TapEvent *event;
538019Sbenash@umich.edu
548019Sbenash@umich.edu  protected:
558019Sbenash@umich.edu    friend class TapListener;
568019Sbenash@umich.edu    TapListener *listener;
577977Shsul@eecs.umich.edu    int socket;
587977Shsul@eecs.umich.edu    char *buffer;
597977Shsul@eecs.umich.edu    int buflen;
607977Shsul@eecs.umich.edu    int32_t buffer_offset;
617977Shsul@eecs.umich.edu    int32_t data_len;
627977Shsul@eecs.umich.edu
637977Shsul@eecs.umich.edu    EtherDump *dump;
647977Shsul@eecs.umich.edu
657977Shsul@eecs.umich.edu    void attach(int fd);
667977Shsul@eecs.umich.edu    void detach();
677977Shsul@eecs.umich.edu
687977Shsul@eecs.umich.edu  protected:
697977Shsul@eecs.umich.edu    std::string device;
707977Shsul@eecs.umich.edu    std::queue<PacketPtr> packetBuffer;
717977Shsul@eecs.umich.edu
727977Shsul@eecs.umich.edu    void process(int revent);
737977Shsul@eecs.umich.edu    void enqueue(EtherPacket *packet);
747977Shsul@eecs.umich.edu    void retransmit();
757977Shsul@eecs.umich.edu
767977Shsul@eecs.umich.edu    /*
777977Shsul@eecs.umich.edu     */
787977Shsul@eecs.umich.edu    class TxEvent : public Event
797977Shsul@eecs.umich.edu    {
807977Shsul@eecs.umich.edu      protected:
817977Shsul@eecs.umich.edu        EtherTap *tap;
827977Shsul@eecs.umich.edu
837977Shsul@eecs.umich.edu      public:
847977Shsul@eecs.umich.edu        TxEvent(EtherTap *_tap)
857977Shsul@eecs.umich.edu            : Event(&mainEventQueue), tap(_tap) {}
867977Shsul@eecs.umich.edu        void process() { tap->retransmit(); }
877977Shsul@eecs.umich.edu        virtual const char *description() { return "retransmit event"; }
887977Shsul@eecs.umich.edu    };
897977Shsul@eecs.umich.edu
907977Shsul@eecs.umich.edu    friend class TxEvent;
917977Shsul@eecs.umich.edu    TxEvent txEvent;
927977Shsul@eecs.umich.edu
937977Shsul@eecs.umich.edu  public:
947977Shsul@eecs.umich.edu    EtherTap(const std::string &name, EtherDump *dump, int port, int bufsz);
957977Shsul@eecs.umich.edu    virtual ~EtherTap();
967977Shsul@eecs.umich.edu
977977Shsul@eecs.umich.edu    virtual bool recvPacket(PacketPtr packet);
987977Shsul@eecs.umich.edu    virtual void sendDone();
998013Sbinkertn@umich.edu};
1007977Shsul@eecs.umich.edu
1017977Shsul@eecs.umich.edu#endif // __ETHERTAP_HH__
1027977Shsul@eecs.umich.edu