From f5ba0d66459c1c035d4613376d1d39af08e483de Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Wed, 6 Mar 2019 17:29:43 -0800 Subject: [PATCH] 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 Maintainer: Andreas Sandberg --- src/dev/net/Ethernet.py | 20 +++++++-------- src/dev/net/SConscript | 1 + src/dev/net/dist_etherlink.cc | 2 +- src/dev/net/dist_etherlink.hh | 6 ++--- src/dev/net/etherbus.cc | 2 +- src/dev/net/etherbus.hh | 4 +-- src/dev/net/etherlink.cc | 2 +- src/dev/net/etherlink.hh | 2 +- src/dev/net/etherobject.hh | 25 +++++------------- src/dev/net/etherswitch.cc | 2 +- src/dev/net/etherswitch.hh | 3 ++- src/dev/net/ethertap.cc | 2 +- src/dev/net/ethertap.hh | 2 +- src/dev/net/python.cc | 48 +++++++++++++++++++++++++++++++++++ 14 files changed, 79 insertions(+), 42 deletions(-) create mode 100644 src/dev/net/python.cc diff --git a/src/dev/net/Ethernet.py b/src/dev/net/Ethernet.py index 7c3c766bc..6e900e0e8 100644 --- a/src/dev/net/Ethernet.py +++ b/src/dev/net/Ethernet.py @@ -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") diff --git a/src/dev/net/SConscript b/src/dev/net/SConscript index 908dd44e6..0bb6bbf01 100644 --- a/src/dev/net/SConscript +++ b/src/dev/net/SConscript @@ -45,6 +45,7 @@ Import('*') SimObject('Ethernet.py') +Source('python.cc', add_tags='python') # Basic Ethernet infrastructure Source('etherbus.cc') diff --git a/src/dev/net/dist_etherlink.cc b/src/dev/net/dist_etherlink.cc index 01f21d136..477ad61b3 100644 --- a/src/dev/net/dist_etherlink.cc +++ b/src/dev/net/dist_etherlink.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); diff --git a/src/dev/net/dist_etherlink.hh b/src/dev/net/dist_etherlink.hh index 83f28f2b2..51852a519 100644 --- a/src/dev/net/dist_etherlink.hh +++ b/src/dev/net/dist_etherlink.hh @@ -53,6 +53,7 @@ #include #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(_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; diff --git a/src/dev/net/etherbus.cc b/src/dev/net/etherbus.cc index 7e086bfb0..dee772cc0 100644 --- a/src/dev/net/etherbus.cc +++ b/src/dev/net/etherbus.cc @@ -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) { diff --git a/src/dev/net/etherbus.hh b/src/dev/net/etherbus.hh index 1b264533c..8c1260fc5 100644 --- a/src/dev/net/etherbus.hh +++ b/src/dev/net/etherbus.hh @@ -43,7 +43,7 @@ class EtherDump; class EtherInt; -class EtherBus : public EtherObject +class EtherBus : public SimObject, public EtherObject { protected: typedef std::list 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__ diff --git a/src/dev/net/etherlink.cc b/src/dev/net/etherlink.cc index 9a11018bb..b160e29d5 100644 --- a/src/dev/net/etherlink.cc +++ b/src/dev/net/etherlink.cc @@ -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); diff --git a/src/dev/net/etherlink.hh b/src/dev/net/etherlink.hh index 7a9870817..37fa16859 100644 --- a/src/dev/net/etherlink.hh +++ b/src/dev/net/etherlink.hh @@ -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; diff --git a/src/dev/net/etherobject.hh b/src/dev/net/etherobject.hh index 55cfa97e6..638c50667 100644 --- a/src/dev/net/etherobject.hh +++ b/src/dev/net/etherobject.hh @@ -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 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(_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__ diff --git a/src/dev/net/etherswitch.cc b/src/dev/net/etherswitch.cc index 0e1d6f3ac..c03b59435 100644 --- a/src/dev/net/etherswitch.cc +++ b/src/dev/net/etherswitch.cc @@ -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); diff --git a/src/dev/net/etherswitch.hh b/src/dev/net/etherswitch.hh index 0887d94e5..36a0c686a 100644 --- a/src/dev/net/etherswitch.hh +++ b/src/dev/net/etherswitch.hh @@ -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; diff --git a/src/dev/net/ethertap.cc b/src/dev/net/ethertap.cc index 4e32a8c46..bf2dc6885 100644 --- a/src/dev/net/ethertap.cc +++ b/src/dev/net/ethertap.cc @@ -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") { diff --git a/src/dev/net/ethertap.hh b/src/dev/net/ethertap.hh index 9b4e175e1..7db73c5b4 100644 --- a/src/dev/net/ethertap.hh +++ b/src/dev/net/ethertap.hh @@ -56,7 +56,7 @@ class TapEvent; class EtherTapInt; -class EtherTapBase : public EtherObject +class EtherTapBase : public SimObject, public EtherObject { public: typedef EtherTapBaseParams Params; diff --git a/src/dev/net/python.cc b/src/dev/net/python.cc new file mode 100644 index 000000000..a012074c1 --- /dev/null +++ b/src/dev/net/python.cc @@ -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>( + m, "EtherObject"); +} +EmbeddedPyBind embed_("ethernet", ðernet_pybind); + +} // anonymous namespace -- 2.30.2