params.py (7743:f440cdaf1c2d) params.py (7777:369f90d32e2e)
1# Copyright (c) 2004-2006 The Regents of The University of Michigan
2# Copyright (c) 2010 Advanced Micro Devices, Inc.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

--- 661 unchanged lines hidden (view full) ---

670
671 def getValue(self):
672 from m5.internal.params import EthAddr
673 return EthAddr(self.value)
674
675 def ini_str(self):
676 return self.value
677
1# Copyright (c) 2004-2006 The Regents of The University of Michigan
2# Copyright (c) 2010 Advanced Micro Devices, Inc.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

--- 661 unchanged lines hidden (view full) ---

670
671 def getValue(self):
672 from m5.internal.params import EthAddr
673 return EthAddr(self.value)
674
675 def ini_str(self):
676 return self.value
677
678# When initializing an IpAddress, pass in an existing IpAddress, a string of
679# the form "a.b.c.d", or an integer representing an IP.
680class IpAddress(ParamValue):
681 cxx_type = 'Net::IpAddress'
682
683 @classmethod
684 def cxx_predecls(cls, code):
685 code('#include "base/inet.hh"')
686
687 @classmethod
688 def swig_predecls(cls, code):
689 code('%include "python/swig/inet.i"')
690
691 def __init__(self, value):
692 if isinstance(value, IpAddress):
693 self.ip = value.ip
694 else:
695 try:
696 self.ip = convert.toIpAddress(value)
697 except TypeError:
698 self.ip = long(value)
699 self.verifyIp()
700
701 def verifyIp(self):
702 if self.ip < 0 or self.ip >= (1 << 32):
703 raise TypeError, "invalid ip address %#08x" % ip
704
705 def getValue(self):
706 from m5.internal.params import IpAddress
707 return IpAddress(self.ip)
708
709 def ini_str(self):
710 return self.ip
711
712# When initializing an IpNetmask, pass in an existing IpNetmask, a string of
713# the form "a.b.c.d/n" or "a.b.c.d/e.f.g.h", or an ip and netmask as
714# positional or keyword arguments.
715class IpNetmask(IpAddress):
716 cxx_type = 'Net::IpNetmask'
717
718 @classmethod
719 def cxx_predecls(cls, code):
720 code('#include "base/inet.hh"')
721
722 @classmethod
723 def swig_predecls(cls, code):
724 code('%include "python/swig/inet.i"')
725
726 def __init__(self, *args, **kwargs):
727 def handle_kwarg(self, kwargs, key, elseVal = None):
728 if key in kwargs:
729 setattr(self, key, kwargs.pop(key))
730 elif elseVal:
731 setattr(self, key, elseVal)
732 else:
733 raise TypeError, "No value set for %s" % key
734
735 if len(args) == 0:
736 handle_kwarg(self, kwargs, 'ip')
737 handle_kwarg(self, kwargs, 'netmask')
738
739 elif len(args) == 1:
740 if kwargs:
741 if not 'ip' in kwargs and not 'netmask' in kwargs:
742 raise TypeError, "Invalid arguments"
743 handle_kwarg(self, kwargs, 'ip', args[0])
744 handle_kwarg(self, kwargs, 'netmask', args[0])
745 elif isinstance(args[0], IpNetmask):
746 self.ip = args[0].ip
747 self.netmask = args[0].netmask
748 else:
749 (self.ip, self.netmask) = convert.toIpNetmask(args[0])
750
751 elif len(args) == 2:
752 self.ip = args[0]
753 self.netmask = args[1]
754 else:
755 raise TypeError, "Too many arguments specified"
756
757 if kwargs:
758 raise TypeError, "Too many keywords: %s" % kwargs.keys()
759
760 self.verify()
761
762 def verify(self):
763 self.verifyIp()
764 if self.netmask < 0 or self.netmask > 32:
765 raise TypeError, "invalid netmask %d" % netmask
766
767 def getValue(self):
768 from m5.internal.params import IpNetmask
769 return IpNetmask(self.ip, self.netmask)
770
771 def ini_str(self):
772 return "%08x/%d" % (self.ip, self.netmask)
773
774# When initializing an IpWithPort, pass in an existing IpWithPort, a string of
775# the form "a.b.c.d:p", or an ip and port as positional or keyword arguments.
776class IpWithPort(IpAddress):
777 cxx_type = 'Net::IpWithPort'
778
779 @classmethod
780 def cxx_predecls(cls, code):
781 code('#include "base/inet.hh"')
782
783 @classmethod
784 def swig_predecls(cls, code):
785 code('%include "python/swig/inet.i"')
786
787 def __init__(self, *args, **kwargs):
788 def handle_kwarg(self, kwargs, key, elseVal = None):
789 if key in kwargs:
790 setattr(self, key, kwargs.pop(key))
791 elif elseVal:
792 setattr(self, key, elseVal)
793 else:
794 raise TypeError, "No value set for %s" % key
795
796 if len(args) == 0:
797 handle_kwarg(self, kwargs, 'ip')
798 handle_kwarg(self, kwargs, 'port')
799
800 elif len(args) == 1:
801 if kwargs:
802 if not 'ip' in kwargs and not 'port' in kwargs:
803 raise TypeError, "Invalid arguments"
804 handle_kwarg(self, kwargs, 'ip', args[0])
805 handle_kwarg(self, kwargs, 'port', args[0])
806 elif isinstance(args[0], IpWithPort):
807 self.ip = args[0].ip
808 self.port = args[0].port
809 else:
810 (self.ip, self.port) = convert.toIpWithPort(args[0])
811
812 elif len(args) == 2:
813 self.ip = args[0]
814 self.port = args[1]
815 else:
816 raise TypeError, "Too many arguments specified"
817
818 if kwargs:
819 raise TypeError, "Too many keywords: %s" % kwargs.keys()
820
821 self.verify()
822
823 def verify(self):
824 self.verifyIp()
825 if self.port < 0 or self.port > 0xffff:
826 raise TypeError, "invalid port %d" % self.port
827
828 def getValue(self):
829 from m5.internal.params import IpWithPort
830 return IpWithPort(self.ip, self.port)
831
832 def ini_str(self):
833 return "%08x:%d" % (self.ip, self.port)
834
678time_formats = [ "%a %b %d %H:%M:%S %Z %Y",
679 "%a %b %d %H:%M:%S %Z %Y",
680 "%Y/%m/%d %H:%M:%S",
681 "%Y/%m/%d %H:%M",
682 "%Y/%m/%d",
683 "%m/%d/%Y %H:%M:%S",
684 "%m/%d/%Y %H:%M",
685 "%m/%d/%Y",

--- 626 unchanged lines hidden (view full) ---

1312 allParams = baseParams.copy()
1313
1314__all__ = ['Param', 'VectorParam',
1315 'Enum', 'Bool', 'String', 'Float',
1316 'Int', 'Unsigned', 'Int8', 'UInt8', 'Int16', 'UInt16',
1317 'Int32', 'UInt32', 'Int64', 'UInt64',
1318 'Counter', 'Addr', 'Tick', 'Percent',
1319 'TcpPort', 'UdpPort', 'EthernetAddr',
835time_formats = [ "%a %b %d %H:%M:%S %Z %Y",
836 "%a %b %d %H:%M:%S %Z %Y",
837 "%Y/%m/%d %H:%M:%S",
838 "%Y/%m/%d %H:%M",
839 "%Y/%m/%d",
840 "%m/%d/%Y %H:%M:%S",
841 "%m/%d/%Y %H:%M",
842 "%m/%d/%Y",

--- 626 unchanged lines hidden (view full) ---

1469 allParams = baseParams.copy()
1470
1471__all__ = ['Param', 'VectorParam',
1472 'Enum', 'Bool', 'String', 'Float',
1473 'Int', 'Unsigned', 'Int8', 'UInt8', 'Int16', 'UInt16',
1474 'Int32', 'UInt32', 'Int64', 'UInt64',
1475 'Counter', 'Addr', 'Tick', 'Percent',
1476 'TcpPort', 'UdpPort', 'EthernetAddr',
1477 'IpAddress', 'IpNetmask', 'IpWithPort',
1320 'MemorySize', 'MemorySize32',
1321 'Latency', 'Frequency', 'Clock',
1322 'NetworkBandwidth', 'MemoryBandwidth',
1323 'Range', 'AddrRange', 'TickRange',
1324 'MaxAddr', 'MaxTick', 'AllMemory',
1325 'Time',
1326 'NextEthernetAddr', 'NULL',
1327 'Port', 'VectorPort']
1328
1329import SimObject
1478 'MemorySize', 'MemorySize32',
1479 'Latency', 'Frequency', 'Clock',
1480 'NetworkBandwidth', 'MemoryBandwidth',
1481 'Range', 'AddrRange', 'TickRange',
1482 'MaxAddr', 'MaxTick', 'AllMemory',
1483 'Time',
1484 'NextEthernetAddr', 'NULL',
1485 'Port', 'VectorPort']
1486
1487import SimObject