base,python: Add a param type for host sockets.
These can either be set to an integer, in which case it's interpreted as a TCP port, or a string, in which case it's treated as a unix domain socket. If the unix domain socket is prefixed with a "@", it will be treated as an abstract socket. When stored in the ini file, there is always a prefix added to make parsing the string more systematic and less ambiguous. A port number is prefixed with "#", an abstract socket with "@", and a socket file with the prefix "P" for "path". Change-Id: I1fc7a579074e849b3becd936238c62fb0d9a2087 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/69165 Reviewed-by: Yu-hsin Wang <yuhsingw@google.com> Maintainer: Gabe Black <gabeblack@google.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -1085,6 +1085,65 @@ class Bool(ParamValue):
|
||||
code(f"{ret} to_bool({src}, {dest});")
|
||||
|
||||
|
||||
class HostSocket(ParamValue):
|
||||
cxx_type = "ListenSocketConfig"
|
||||
|
||||
@classmethod
|
||||
def cxx_predecls(cls, code):
|
||||
code('#include "base/socket.hh"')
|
||||
|
||||
def __init__(self, value):
|
||||
if isinstance(value, HostSocket):
|
||||
self.value = value.value
|
||||
else:
|
||||
self.value = value
|
||||
|
||||
def getValue(self):
|
||||
from _m5.socket import listenSocketEmptyConfig
|
||||
from _m5.socket import listenSocketInetConfig
|
||||
from _m5.socket import listenSocketUnixFileConfig
|
||||
from _m5.socket import listenSocketUnixAbstractConfig
|
||||
|
||||
if isinstance(self.value, str):
|
||||
if self.value[0] == "@":
|
||||
return listenSocketUnixAbstractConfig(self.value[1:])
|
||||
else:
|
||||
d, f = os.path.split(self.value)
|
||||
return listenSocketUnixFileConfig(d, f)
|
||||
else:
|
||||
if self.value == 0:
|
||||
return listenSocketEmptyConfig()
|
||||
else:
|
||||
return listenSocketInetConfig(self.value)
|
||||
|
||||
def __call__(self, value):
|
||||
self.__init__(value)
|
||||
return value
|
||||
|
||||
def __str__(self):
|
||||
if isinstance(self.value, str):
|
||||
return self.value
|
||||
else:
|
||||
return "#" + str(self.value)
|
||||
|
||||
def ini_str(self):
|
||||
if isinstance(self.value, str):
|
||||
if self.value[0] == "@":
|
||||
return self.value
|
||||
else:
|
||||
return "P" + self.value
|
||||
else:
|
||||
return "#" + str(self.value)
|
||||
|
||||
@classmethod
|
||||
def cxx_ini_predecls(cls, code):
|
||||
code('#include "base/socket.hh"')
|
||||
|
||||
@classmethod
|
||||
def cxx_ini_parse(cls, code, src, dest, ret):
|
||||
code(f"{ret} ListenSocketConfig::parseIni({src}, {dest});")
|
||||
|
||||
|
||||
def IncEthernetAddr(addr, val=1):
|
||||
bytes = [int(x, 16) for x in addr.split(":")]
|
||||
bytes[5] += val
|
||||
|
||||
Reference in New Issue
Block a user