dev: Turn EtherObject into an interface class.
This class used to drive from SimObject so that it could be derived from to get both the interface and SimObject while still using single inheritance. With this change, EtherObject is now just an interface class with only one pure virtual function which can be inherited alongside SimObject. This makes it more flexible so that it can be used in places where you might want a different inheritance hierarchy, for instance to inherit from MemObject. Change-Id: I0f07664d104eed012cf4ce6e30c416ada19505a7 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/17028 Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
This commit is contained in:
@@ -44,14 +44,10 @@ from m5.params import *
|
||||
from m5.proxy import *
|
||||
from m5.objects.PciDevice import PciDevice
|
||||
|
||||
class EtherObject(SimObject):
|
||||
type = 'EtherObject'
|
||||
abstract = True
|
||||
cxx_header = "dev/net/etherobject.hh"
|
||||
|
||||
class EtherLink(EtherObject):
|
||||
class EtherLink(SimObject):
|
||||
type = 'EtherLink'
|
||||
cxx_header = "dev/net/etherlink.hh"
|
||||
cxx_extra_bases = [ "EtherObject" ]
|
||||
int0 = SlavePort("interface 0")
|
||||
int1 = SlavePort("interface 1")
|
||||
delay = Param.Latency('0us', "packet transmit delay")
|
||||
@@ -59,9 +55,10 @@ class EtherLink(EtherObject):
|
||||
speed = Param.NetworkBandwidth('1Gbps', "link speed")
|
||||
dump = Param.EtherDump(NULL, "dump object")
|
||||
|
||||
class DistEtherLink(EtherObject):
|
||||
class DistEtherLink(SimObject):
|
||||
type = 'DistEtherLink'
|
||||
cxx_header = "dev/net/dist_etherlink.hh"
|
||||
cxx_extra_bases = [ "EtherObject" ]
|
||||
int0 = SlavePort("interface 0")
|
||||
delay = Param.Latency('0us', "packet transmit delay")
|
||||
delay_var = Param.Latency('0ns', "packet transmit delay variability")
|
||||
@@ -77,16 +74,18 @@ class DistEtherLink(EtherObject):
|
||||
dist_sync_on_pseudo_op = Param.Bool(False, "Start sync with pseudo_op")
|
||||
num_nodes = Param.UInt32('2', "Number of simulate nodes")
|
||||
|
||||
class EtherBus(EtherObject):
|
||||
class EtherBus(SimObject):
|
||||
type = 'EtherBus'
|
||||
cxx_header = "dev/net/etherbus.hh"
|
||||
cxx_extra_bases = [ "EtherObject" ]
|
||||
loopback = Param.Bool(True, "send packet back to the sending interface")
|
||||
dump = Param.EtherDump(NULL, "dump object")
|
||||
speed = Param.NetworkBandwidth('100Mbps', "bus speed in bits per second")
|
||||
|
||||
class EtherSwitch(EtherObject):
|
||||
class EtherSwitch(SimObject):
|
||||
type = 'EtherSwitch'
|
||||
cxx_header = "dev/net/etherswitch.hh"
|
||||
cxx_extra_bases = [ "EtherObject" ]
|
||||
dump = Param.EtherDump(NULL, "dump object")
|
||||
fabric_speed = Param.NetworkBandwidth('10Gbps', "switch fabric speed in bits "
|
||||
"per second")
|
||||
@@ -96,10 +95,11 @@ class EtherSwitch(EtherObject):
|
||||
delay_var = Param.Latency('0ns', "packet transmit delay variability")
|
||||
time_to_live = Param.Latency('10ms', "time to live of MAC address maping")
|
||||
|
||||
class EtherTapBase(EtherObject):
|
||||
class EtherTapBase(SimObject):
|
||||
type = 'EtherTapBase'
|
||||
abstract = True
|
||||
cxx_header = "dev/net/ethertap.hh"
|
||||
cxx_extra_bases = [ "EtherObject" ]
|
||||
bufsz = Param.Int(10000, "tap buffer size")
|
||||
dump = Param.EtherDump(NULL, "dump object")
|
||||
tap = SlavePort("Ethernet interface to connect to gem5's network")
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
Import('*')
|
||||
|
||||
SimObject('Ethernet.py')
|
||||
Source('python.cc', add_tags='python')
|
||||
|
||||
# Basic Ethernet infrastructure
|
||||
Source('etherbus.cc')
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
using namespace std;
|
||||
|
||||
DistEtherLink::DistEtherLink(const Params *p)
|
||||
: EtherObject(p), linkDelay(p->delay)
|
||||
: SimObject(p), linkDelay(p->delay)
|
||||
{
|
||||
DPRINTF(DistEthernet,"DistEtherLink::DistEtherLink() "
|
||||
"link delay:%llu ticksPerByte:%f\n", p->delay, p->speed);
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "dev/net/etherlink.hh"
|
||||
#include "dev/net/etherobject.hh"
|
||||
#include "params/DistEtherLink.hh"
|
||||
|
||||
class DistIface;
|
||||
@@ -61,7 +62,7 @@ class EthPacketData;
|
||||
/**
|
||||
* Model for a fixed bandwidth full duplex ethernet link.
|
||||
*/
|
||||
class DistEtherLink : public EtherObject
|
||||
class DistEtherLink : public SimObject, public EtherObject
|
||||
{
|
||||
protected:
|
||||
class LocalIface;
|
||||
@@ -223,8 +224,7 @@ class DistEtherLink : public EtherObject
|
||||
return dynamic_cast<const Params *>(_params);
|
||||
}
|
||||
|
||||
virtual EtherInt *getEthPort(const std::string &if_name,
|
||||
int idx) override;
|
||||
EtherInt *getEthPort(const std::string &if_name, int idx) override;
|
||||
|
||||
virtual void init() override;
|
||||
virtual void startup() override;
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
using namespace std;
|
||||
|
||||
EtherBus::EtherBus(const Params *p)
|
||||
: EtherObject(p), ticksPerByte(p->speed), loopback(p->loopback),
|
||||
: SimObject(p), ticksPerByte(p->speed), loopback(p->loopback),
|
||||
event([this]{ txDone(); }, "ethernet bus completion"),
|
||||
sender(0), dump(p->dump)
|
||||
{
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
class EtherDump;
|
||||
class EtherInt;
|
||||
class EtherBus : public EtherObject
|
||||
class EtherBus : public SimObject, public EtherObject
|
||||
{
|
||||
protected:
|
||||
typedef std::list<EtherInt *> devlist_t;
|
||||
@@ -72,7 +72,7 @@ class EtherBus : public EtherObject
|
||||
void reg(EtherInt *dev);
|
||||
bool busy() const { return (bool)packet; }
|
||||
bool send(EtherInt *sender, EthPacketPtr &packet);
|
||||
virtual EtherInt *getEthPort(const std::string &if_name, int idx);
|
||||
EtherInt *getEthPort(const std::string &if_name, int idx) override;
|
||||
};
|
||||
|
||||
#endif // __DEV_NET_ETHERBUS_HH__
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
using namespace std;
|
||||
|
||||
EtherLink::EtherLink(const Params *p)
|
||||
: EtherObject(p)
|
||||
: SimObject(p)
|
||||
{
|
||||
link[0] = new Link(name() + ".link0", this, 0, p->speed,
|
||||
p->delay, p->delay_var, p->dump);
|
||||
|
||||
@@ -62,7 +62,7 @@ class Checkpoint;
|
||||
/*
|
||||
* Model for a fixed bandwidth full duplex ethernet link
|
||||
*/
|
||||
class EtherLink : public EtherObject
|
||||
class EtherLink : public EtherObject, public SimObject
|
||||
{
|
||||
protected:
|
||||
class Interface;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2007 The Regents of The University of Michigan
|
||||
* Copyright 2019 Google, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -26,6 +27,7 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Authors: Ali Saidi
|
||||
* Gabe Black
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -36,32 +38,17 @@
|
||||
#ifndef __DEV_NET_ETHEROBJECT_HH__
|
||||
#define __DEV_NET_ETHEROBJECT_HH__
|
||||
|
||||
#include "params/EtherObject.hh"
|
||||
#include "sim/sim_object.hh"
|
||||
#include <string>
|
||||
|
||||
class EtherInt;
|
||||
|
||||
/**
|
||||
* The base EtherObject class, allows for an accesor function to a
|
||||
* simobj that returns the Port.
|
||||
* The base EtherObject interface.
|
||||
*/
|
||||
class EtherObject : public SimObject
|
||||
class EtherObject
|
||||
{
|
||||
public:
|
||||
typedef EtherObjectParams Params;
|
||||
EtherObject(const Params *params)
|
||||
: SimObject(params) {}
|
||||
|
||||
const Params *
|
||||
params() const
|
||||
{
|
||||
return dynamic_cast<const Params *>(_params);
|
||||
}
|
||||
|
||||
public:
|
||||
/** Additional function to return the Port of a memory object. */
|
||||
virtual EtherInt *getEthPort(const std::string &if_name, int idx = -1) = 0;
|
||||
|
||||
virtual EtherInt *getEthPort(const std::string &if_name, int idx=-1) = 0;
|
||||
};
|
||||
|
||||
#endif // __DEV_NET_ETHEROBJECT_HH__
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
using namespace std;
|
||||
|
||||
EtherSwitch::EtherSwitch(const Params *p)
|
||||
: EtherObject(p), ttl(p->time_to_live)
|
||||
: SimObject(p), ttl(p->time_to_live)
|
||||
{
|
||||
for (int i = 0; i < p->port_interface_connection_count; ++i) {
|
||||
std::string interfaceName = csprintf("%s.interface%d", name(), i);
|
||||
|
||||
@@ -47,8 +47,9 @@
|
||||
#include "dev/net/pktfifo.hh"
|
||||
#include "params/EtherSwitch.hh"
|
||||
#include "sim/eventq.hh"
|
||||
#include "sim/sim_object.hh"
|
||||
|
||||
class EtherSwitch : public EtherObject
|
||||
class EtherSwitch : public SimObject, public EtherObject
|
||||
{
|
||||
public:
|
||||
typedef EtherSwitchParams Params;
|
||||
|
||||
@@ -92,7 +92,7 @@ class TapEvent : public PollEvent
|
||||
};
|
||||
|
||||
EtherTapBase::EtherTapBase(const Params *p)
|
||||
: EtherObject(p), buflen(p->bufsz), dump(p->dump), event(NULL),
|
||||
: SimObject(p), buflen(p->bufsz), dump(p->dump), event(NULL),
|
||||
interface(NULL),
|
||||
txEvent([this]{ retransmit(); }, "EtherTapBase retransmit")
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
class TapEvent;
|
||||
class EtherTapInt;
|
||||
|
||||
class EtherTapBase : public EtherObject
|
||||
class EtherTapBase : public SimObject, public EtherObject
|
||||
{
|
||||
public:
|
||||
typedef EtherTapBaseParams Params;
|
||||
|
||||
48
src/dev/net/python.cc
Normal file
48
src/dev/net/python.cc
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2019 Google, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met: redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer;
|
||||
* redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution;
|
||||
* neither the name of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Authors: Gabe Black
|
||||
*/
|
||||
|
||||
#include "python/pybind11/pybind.hh"
|
||||
|
||||
#include "dev/net/etherobject.hh"
|
||||
#include "sim/init.hh"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void
|
||||
ethernet_pybind(pybind11::module &m_internal)
|
||||
{
|
||||
pybind11::module m = m_internal.def_submodule("ethernet");
|
||||
pybind11::class_<
|
||||
EtherObject, std::unique_ptr<EtherObject, pybind11::nodelete>>(
|
||||
m, "EtherObject");
|
||||
}
|
||||
EmbeddedPyBind embed_("ethernet", ðernet_pybind);
|
||||
|
||||
} // anonymous namespace
|
||||
Reference in New Issue
Block a user