# Source code for pacman.model.routing_table_by_partition.multicast_routing_table_by_partition_entry

# Copyright (c) 2017-2019 The University of Manchester
#
# This program is free software: you can redistribute it and/or modify
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from pacman.exceptions import PacmanInvalidParameterException

[docs]class MulticastRoutingTableByPartitionEntry(object):
""" An entry in a path of a multicast route.
"""

__slots__ = [
# the edges this path entry goes down

# the processors this path entry goes to
"_out_going_processors",

# the direction this entry came from in link

# the direction this entry came from
"_incoming_processor"
]

"""
the edges this path entry goes down, each of which is between
0 and 5
:param iterable(int) outgoing_processors:
the processors this path entry goes to, each of which is between
0 and 17
:param int incoming_processor:
the direction this entry came from (between 0 and 17)
the direction this entry came from in link (between 0 and 5)
:raises PacmanInvalidParameterException:
"""
else:

if isinstance(outgoing_processors, int):
self._out_going_processors = set()
elif outgoing_processors is not None:
self._out_going_processors = set(
int(p) for p in outgoing_processors)
else:
self._out_going_processors = set()

if incoming_link is not None and incoming_processor is not None:
raise PacmanInvalidParameterException(
"The incoming direction for a path can only be from either "
"one link or one processors, not both",
if (incoming_processor is not None
and not isinstance(incoming_processor, int)):
raise PacmanInvalidParameterException(
"The incoming direction for a path can only be from either "
"one link or one processors, not both",
raise PacmanInvalidParameterException(
"The incoming direction for a path can only be from either "
"one link or one processors, not both",
self._incoming_processor = (
None if incoming_processor is None else int(incoming_processor))

@property
def processor_ids(self):
""" The destination processors of the entry

:rtype: set(int)
"""
return self._out_going_processors

@property
""" The destination links of the entry

:rtype: set(int)
"""

@property
""" The source link for this path entry

:rtype: int or None
"""

if self._incoming_processor is not None:
raise Exception(
"Entry already has an incoming processor {}".format(
self._incoming_processor))
if (self._incoming_link is not None and
raise Exception(

@property
def incoming_processor(self):
""" The source processor

:rtype: int or None
"""
return self._incoming_processor

@incoming_processor.setter
def incoming_processor(self, incoming_processor):
if (self._incoming_processor is not None and
self._incoming_processor != incoming_processor):
raise Exception(
"Entry already has an incoming processor {}".format(
self._incoming_processor))
raise Exception(
self._incoming_processor = int(incoming_processor)

@property
def defaultable(self):
""" The defaultable status of the entry
"""
or self._incoming_processor is not None
or self._out_going_processors):
return False

@staticmethod
def __merge_noneables(p1, p2, name):
if p1 is None:
return p2
if p2 is None or p1 == p2:
return p1
raise PacmanInvalidParameterException(
name, "invalid merge",
"The two MulticastRoutingTableByPartitionEntry have different " +
name + "s, and so can't be merged")

[docs]    def merge_entry(self, other):
""" Merges the another entry with this one and returns a new\
MulticastRoutingTableByPartitionEntry

:param MulticastRoutingTableByPartitionEntry other:
the entry to merge into this one
:return: a merged MulticastRoutingTableByPartitionEntry
:raises PacmanInvalidParameterException:
"""
if not isinstance(other, MulticastRoutingTableByPartitionEntry):
raise PacmanInvalidParameterException(
"other", "type error",
"The other parameter is not an instance of "
"MulticastRoutingTableByPartitionEntry, and therefore cannot "
"be merged.")

# validate and merge
valid_incoming_processor = self.__merge_noneables(
self._incoming_processor, other.incoming_processor,
"incoming_processor")
merged_outgoing_processors = self._out_going_processors.union(
other.processor_ids)