Ejemplo n.º 1
0
    def collect_nodes(self):
        """Return network information scraped from CloudTrax"""

        for network in self.network['networks']:
            parameters = {'id': network,
                          'showall': '1',
                          'details': '1'}
    
            logging.info('Requesting network status') 

            request = self.session.get(self.url['data'], params=parameters)

            logging.info('Received network status ok') 

            if request.status_code == 200:
                for raw_values in distill_html(request.content, 'table',
                                               {'id': 'mytable'}):

                    node = Node(raw_values,
                                self.get_checkin_data(raw_values[2][0]),
                                network)

                    if node.is_alerting():
                        logging.info('%s is alerting' % (node))
                        self.alerting.append(node)

                    self.nodes[node.get_mac()] = node

            else:
                logging.error('Request failed') 
                exit(request.status_code)

        return self.nodes
Ejemplo n.º 2
0
def url(request, project, env):
    from lib.node import Node
    from lib.common import Common

    result = ""

    n = Node(project, env)
    ip = []
    for row in n.get():
        if row["hostname"].startswith("Controltier"):
            continue
        ip.append(row["hostname"])

    for vrow in Validation.objects.filter(project=project).values():
        for server in ip:
            if vrow["url"].startswith("ip"):
                url = re.sub("ip", server, vrow["url"])
                return_code = Common().get_return_code(url, vrow["port"])
                result += """
                <tr>
                    <th>{url}</th>
                    <th>{return_code}</th>
                </tr>
                """.format(
                    url=url, return_code=return_code
                )

    return HttpResponse(result)
Ejemplo n.º 3
0
def url(request, project, env):
    from lib.node import Node
    from lib.common import Common

    result = ""

    n = Node(project, env)
    ip = []
    for row in n.get():
        if row['hostname'].startswith("Controltier"):
            continue
        ip.append(row['hostname'])

    for vrow in Validation.objects.filter(project=project).values():
        for server in ip:
            if vrow['url'].startswith("ip"):
                url = re.sub("ip", server, vrow['url'])
                return_code = Common().get_return_code(url, vrow['port'])
                result += """
                <tr>
                    <th>{url}</th>
                    <th>{return_code}</th>
                </tr>
                """.format(
                    url=url,
                    return_code=return_code,
                )

    return HttpResponse(result)
Ejemplo n.º 4
0
 def decode_headers(self, bitStream: 'BitStream', char_size: int):
     if bitStream.read(1).bin == '1':
         encoded_char: str = bitStream.read(char_size).bin
         int_char: int = int(encoded_char, 2)
         return Node(symbol=chr(int_char)[0], count=1)
     else:
         left = self.decode_headers(bitStream, char_size)
         right = self.decode_headers(bitStream, char_size)
         return Node(left=left, right=right, count=1)
Ejemplo n.º 5
0
 def __init__(self, component_class, name="ctrl", max_callbacks=0):
     Node.__init__(self, name, 0)
     ctxt = Context(self)
     self.component_object = component_class(ctxt=ctxt)
     self.connection_count = 0
     self.in_connections = {}
     self.callbacks = []
     self.start_callbacks = []
     self.max_callbacks = max_callbacks
Ejemplo n.º 6
0
 def __init__(self, component_class, name="ctrl", max_callbacks=0):
     Node.__init__(self, name, 0)
     ctxt = Context(self)
     self.component_object = component_class(ctxt=ctxt)
     self.connection_count = 0
     self.in_connections = {}
     self.callbacks = []
     self.start_callbacks = []
     self.max_callbacks = max_callbacks
Ejemplo n.º 7
0
def test_position_validity():
    for i in range(1000):
        rdn = random.random()
        if rdn > 0.5:
            pos = -1 * (random.randint(1, 1000))
            node = Node(State.DEAD, pos)
            assert (node.valid_node == False)
        else:
            pos = random.randint(1, 1000)
            node = Node(State.DEAD, pos)
            assert (node.valid_node == True)
Ejemplo n.º 8
0
    def copyNode(self, node):
        """Copy a node object add it on manager list nodes and set it not include.
           Return the new node object.
        """
#        newNode = copy.copy(node)
#        newNode.homeId = 0
        nodeId = self.getFirstFreeNodeIdBeforeInclude()
        newNode = Node(self,  0,  nodeId, node.GetXmlData)
        newNode.ClearAddingNode()
        newNode.Reset()
        self._nodes.append(newNode)
        self._log.write(LogLevel.Info, self, "Manager create new node by copy node {0}.{1}.".format(node.homeId, node.nodeId))
        return newNode
Ejemplo n.º 9
0
 def __init__(self, name, port_count, of_id, expire_entries=False):
     Node.__init__(self, name, port_count)
     self.log = logging.getLogger("nice.mc.%s" % self.name)
     self.flow_table_object = []
     self.openflow_id = of_id
     self.buffers = []
     self.next_buffer_id = 0
     self.packet_store = {}
     self.command_queue = []
     self.fault_injection_count = 0
     self.state_cnt = 0
     self.expire_entries = expire_entries
     self.ports_to_fail = []
     self.this_switch_is_offline = False
Ejemplo n.º 10
0
    def __init__(self, start, target, allow_diagonals, World):
        self.start = Node(start, target, 0, None, World, False,
                          allow_diagonals)
        self.target = Node(target, target, 0, None, World, False,
                           allow_diagonals)
        self.reached = False
        self.stack = [self.start]
        self.visited = []
        self.path = []

        while (not (self.start.is_accessible())):
            stdout.write("\033[;1m" + "\033[1;31m")
            stdout.write('START Tile have no children, choose another one ! ')
            stdout.write("\033[0;0m")
            start = int(input("New START Tile --->  "))
            self.start = Node(start, target, 0, None, World, False,
                              allow_diagonals, True)
        while (not (self.target.is_accessible())):
            stdout.write("\033[;1m" + "\033[1;31m")
            stdout.write('TARGET Tile have no children, choose another one ! ')
            stdout.write("\033[0;0m")
            target = int(input("New TARGET Tile --->  "))
            self.target = Node(target, target, 0, None, World, False,
                               allow_diagonals, True)

        self.path = [self.start.tile_pos]
        self.costs = [0]
Ejemplo n.º 11
0
 def __init__(self, name, port_count, of_id, expire_entries=False):
     Node.__init__(self, name, port_count)
     self.log = logging.getLogger("nice.mc.%s" % self.name)
     self.flow_table_object = []
     self.openflow_id = of_id
     self.buffers = []
     self.next_buffer_id = 0
     self.packet_store = {}
     self.command_queue = []
     self.fault_injection_count = 0
     self.state_cnt = 0
     self.expire_entries = expire_entries
     self.ports_to_fail = []
     self.this_switch_is_offline = False
Ejemplo n.º 12
0
    def __init__(self, start, target, allow_diagonals, World):
        self.start = Node(start, target, 0, None, World,
                          False, allow_diagonals)
        self.target = Node(target, target, -1, None, World,
                           False, allow_diagonals)

        self.open_nodes = [self.start]
        self.closed_nodes = []

        self.last_node = None

        self.reached = False
        self.available_tiles = World.list_available_tiles()

        while (not(self.start.is_accessible())):
            stdout.write("\033[;1m" + "\033[1;31m")
            stdout.write('START Tile have no children, choose another one ! ')
            stdout.write("\033[0;0m")
            start = int(input("New START Tile --->  "))
            self.start = Node(start, target, 0, None, World,
                              False, allow_diagonals)
        while (not(self.target.is_accessible())):
            stdout.write("\033[;1m" + "\033[1;31m")
            stdout.write('TARGET Tile have no children, choose another one ! ')
            stdout.write("\033[0;0m")
            target = int(input("New TARGET Tile --->  "))
            self.target = Node(target, target, -1, None, World,
                               False, allow_diagonals)

        self.path = [self.start.tile_pos]
        self.costs = [0]
Ejemplo n.º 13
0
def test_state_validity():
    for i in range(1000):
        rdn = random.random()
        if rdn > 0.5:
            state = random.choice(State.ALLOWED_)
            node = Node(state, 0)
            assert (node.valid_node == True)
        else:
            state = random.randint(-1000, 1000)
            if state in State.ALLOWED_:
                pass
            else:
                node = Node(state, 0)
                assert (node.valid_node == False)
Ejemplo n.º 14
0
    def getInfoMock(self, return_value):
        Node._infoCInfo.return_value = return_value
        Node._infoTelnet.return_value = return_value

        n = Node("127.0.0.1")

        return n
Ejemplo n.º 15
0
    def add_node(self, node_name, children=None):
        if node_name in self.nodes:
            raise GraphDuplicateNodeNameError(
                "Attempting to create a duplicately-named node in the same graph."
            )

        self.nodes[node_name] = Node(node_name, children)
Ejemplo n.º 16
0
    def setUp(self):
        self.cluster_patch = patch('lib.cluster.Cluster')
        #self.view_patch = patch('lib.view.CliView')

        real_stdoup = sys.stdout
        sys.stdout = StringIO()

        self.addCleanup(patch.stopall)
        self.addCleanup(reset_stdout)

        self.MockCluster = self.cluster_patch.start()
        #self.MockView = self.view_patch.start()
        Cluster._crawl = classmethod(lambda self: None)
        Cluster._callNodeMethod = classmethod(
            lambda self, nodes, method_name, *args, **kwargs:
            {"test":IOError("test error")})

        n = Node("172.99.99.99")
        Cluster.getNode = classmethod(
            lambda self, key: [n])

        pd = PrefixDict()
        pd['test'] = 'test'

        Cluster.getPrefixes = classmethod(lambda self: pd)

        self.rc = RootController()
Ejemplo n.º 17
0
def test_outofbounds():
    env = World(10, 10, 0.2)
    free_tiles = env.list_available_tiles()
    new_node = [Node(i, 84, 0, None, env) for i in free_tiles]

    for elem in new_node:
        assert (elem.tile_pos >= 0 and elem.tile_pos <= (env.L * env.H))
Ejemplo n.º 18
0
    def prepare(self):
        """Create a router with its nodes."""
        debug('Creating {}:'.format(self.role), self.name)
        self.nodes = []
        for hypervisor in self.hypervisors:
            if self.deployment.high_available:
                suffix = self.suffixes[self.hypervisors.index(hypervisor)]
                self.nodes.append(Node(self, hypervisor, suffix))
            else:
                self.nodes.append(Node(self, hypervisor))
                break

        for i, node in enumerate(self.nodes):
            if len(self.nodes) == 2:
                node.peer_node = self.nodes[(i + 1) % 2]
                if i == 1:
                    node.is_secondary = True
Ejemplo n.º 19
0
def test_availability():
    env = World(10, 10, 0.2)
    free_tiles = env.list_available_tiles()

    new_node = [Node(i, 84, 0, None, env) for i in free_tiles]

    for elem in new_node:
        assert (env.w[elem.tile_pos] != 1)
Ejemplo n.º 20
0
 def addXmlNode(self, homeId, nodeId, xmlNode):
     for n in self._nodes:
         if n.homeId == homeId and n.nodeId == nodeId:
             self._log.write(LogLevel.Warning, self, "Node {0} on homeId {1} from xml config file allready exist, abording add.".format(nodeId,  homeId))
             return None
     node = Node(self,  homeId,  nodeId, xmlNode)
     self._nodes.append(node)
     self._log.write(LogLevel.Info, self, "Node {0} on homeId {1} added from xml config file.".format(nodeId,  homeId))
Ejemplo n.º 21
0
class NodeTest(unittest.TestCase):
    def setUp(self):
        self.node = Node(movie_score=60, movie_title="Hot Tub Time Machine")

    def test_it_exists(self):
        self.assertIsInstance(self.node, Node)

    def test_attributes(self):
        self.assertEqual(self.node.movie_score, 60)
        self.assertEqual(self.node.movie_title, "Hot Tub Time Machine")

    def test_left_is_none_by_default(self):
        self.assertEqual(self.node.left, None)

    def test_right_is_none_by_default(self):
        self.assertEqual(self.node.right, None)

    def test_depth_is_none_by_default(self):
        self.assertEqual(self.node.depth, 0)

    def test_insert_left(self):
        self.node.insert(56, "Bill & Ted's Excellent Adventure")

        self.assertEqual(self.node.left.movie_score, 56)

        self.node.insert(50, "Die Hard")

        self.assertEqual(self.node.left.left.movie_score, 50)
        self.assertEqual(
            self.node.insert(50, "Jingle Bells"),
            "That movie score has already been used. Please submit another one"
        )

    def test_insert_right(self):
        self.node.insert(64, "Bill & Ted's Excellent Adventure")

        self.assertEqual(self.node.right.movie_score, 64)

        self.node.insert(70, "Die Hard")

        self.assertEqual(self.node.right.right.movie_score, 70)
        self.assertEqual(
            self.node.insert(60, "Jingle Bells"),
            "That movie score has already been used. Please submit another one"
        )
Ejemplo n.º 22
0
    def dump_equivalent_state(self):
        filtered_dict = Node.dump_equivalent_state(self)
        filtered_dict["command_queue"] = []
        for c in self.command_queue:
            utils.copy_state(c)
        filtered_dict["flow_table"] = utils.copy_state(self.flow_table)
        filtered_dict["packet_store"] = utils.copy_state(self.packet_store)

        if self.ALWAYS_NEW_STATE:
            filtered_dict["state_cnt"] = utils.copy_state(self.state_cnt)

        return filtered_dict
Ejemplo n.º 23
0
    def dump_equivalent_state(self):
        filtered_dict = Node.dump_equivalent_state(self)
        filtered_dict["command_queue"] = []
        for c in self.command_queue:
            utils.copy_state(c)
        filtered_dict["flow_table"] = utils.copy_state(self.flow_table)
        filtered_dict["packet_store"] = utils.copy_state(self.packet_store)

        if self.ALWAYS_NEW_STATE:
            filtered_dict["state_cnt"] = utils.copy_state(self.state_cnt)

        return filtered_dict
Ejemplo n.º 24
0
    def get_node_tree(self, frequencies: List['Node']) -> 'Node':
        priority_queue = PriorityQueue(frequencies)

        while True:
            left_node = priority_queue.get_and_remove_first_element()
            right_node = priority_queue.get_and_remove_first_element()

            parent = Node(left=left_node, right=right_node)

            if (len(priority_queue) == 0):
                return parent

            priority_queue.add(parent)
Ejemplo n.º 25
0
    def dump_equivalent_state(self):
        filtered_dict = Node.dump_equivalent_state(self)
        filtered_dict["component"] = utils.copy_state(self.component)

        filtered_dict["in_connections"] = {}
        keys = self.in_connections.keys()
        keys.sort()
        for j in keys:
            filtered_dict["in_connections"][j] = []
            for m in self.in_connections[j][1]:
                filtered_dict["in_connections"][j].append(utils.copy_state(m)) # get only the buffer

        return filtered_dict
Ejemplo n.º 26
0
    def _registerNode(self, ip_port):
        """
        Instantiate and return a new node

        If cannot instantiate node, return None.
        Creates a new node if:
           1) node.key doesn't already exist
           2) node.key exists but existing node is not alive
        """
        try:
            ip, port = ip_port
        except Exception as e:
            print "ip_port is expected to be a tuple of len 2, " + \
                "instead it is of type %s and str value of %s"%(type(ip_port)
                                                                , str(ip_port))
            return None

        try:
            node_key = Node.createKey(ip, port)
            if node_key in self.nodes:
                existing = self.nodes[node_key]
            else:
                existing = None

            if not existing or not existing.alive:
                new_node = Node(ip,
                                port,
                                use_telnet=self.use_telnet,
                                user=self.user,
                                password=self.password)

                if existing and not new_node.alive:
                    new_node = existing
            self.updateNode(new_node)

            return new_node
        except:
            return None
Ejemplo n.º 27
0
    def dump_equivalent_state(self):
        filtered_dict = Node.dump_equivalent_state(self)
        filtered_dict["component"] = utils.copy_state(self.component)

        filtered_dict["in_connections"] = {}
        keys = self.in_connections.keys()
        keys.sort()
        for j in keys:
            filtered_dict["in_connections"][j] = []
            for m in self.in_connections[j][1]:
                filtered_dict["in_connections"][j].append(
                    utils.copy_state(m))  # get only the buffer

        return filtered_dict
Ejemplo n.º 28
0
def test_uniqueness():
    env = World(10, 10, 0.2)
    free_tiles = env.list_available_tiles()
    nodes = [Node(i, 84, 0, None, env) for i in free_tiles]

    # list of positions
    pos = []
    for elem in nodes:
        pos.append(elem.tile_pos)

    # check uniqueness
    seen = set()
    uniqueness = not any(k in seen or seen.add(k) for k in pos)

    assert (uniqueness == True)
Ejemplo n.º 29
0
    def __initNodes(self, map):
        self.nodes = []

        for x in range(self.pNum):
            self.nodes.append([])
            for y in range(self.pNum):
                startPos = (x * self.pWidth, y * self.pHeight)
                nodeState = 0

                if map == maps.zebra:
                    nodeState = states.empty if y % 2 == 0 else states.wall

                elif map == maps.windows:
                    pLast = self.pNum - 1
                    if (x + 1) % 3 == 0 and y != pLast:
                        nodeState = states.empty
                    elif (y % 2 == 0 or y == pLast) and (x, y) not in [
                        (0, 0), (1, 0), (pLast, pLast - 1),
                        (pLast - 1, pLast - 1)
                    ]:
                        nodeState = states.wall

                elif map == maps.coolerWindows:
                    if (x + 1) % 3 == 0:
                        nodeState = states.empty
                    elif y % 2 == 0:
                        if 0 in [x % 6, (x - 1) % 6]:
                            nodeState = states.wall
                    else:
                        if 0 in [(x + 3) % 6, (x + 2) % 6]:
                            nodeState = states.wall

                elif map == maps.yourComputerWillCrash:
                    if (x, y) != (0, 0) or (y != self.pNum or x != self.pNum):
                        if x % 4 == 0 and y == 0:
                            nodeState = states.empty
                        elif x % 2 == 0 and y <= x:
                            nodeState = states.wall

                        if (y + 2) % 4 == 0 and x == 0:
                            nodeState = states.empty
                        elif y % 2 == 0 and y > x:
                            nodeState = states.wall

                self.nodes[-1].append(
                    Node(startPos, (self.pWidth, self.pHeight),
                         state=nodeState))
 def test_testcase1(self):
     """
     测试用例如下:
     implementation:s0 -act1?-> s1
     specification: s0 -act1?-> s1
     :return: None
     """
     imp_root = Node(None, State("s0"))
     imp_root.children = [
         Node(Action("act1", ActionEnum.INPUT), State("s1"))
     ]
     spec_root = Node(None, State("s0"))
     spec_root.children = [
         Node(Action("act1", ActionEnum.INPUT), State("s1"))
     ]
     imp = LTSTree(imp_root)
     spec = LTSTree(spec_root)
     self.assertTrue(imp.io_conform(spec), msg="io not conform")
Ejemplo n.º 31
0
    def create_node(self,e):
        nodeList = get_variable("nodeList")
        properties = get_variable("properties")

        #check position
        x = e.x
        y = e.y
        for item in nodeList:
            iX = item._x
            iY = item._y
            if( x > iX - 20 and x < iX + 50 and y > iY - 20 and y < iY + 50):
                return
        
        #create new node
        newNode = Node(self._canvas,"",0,x-15,y-15,30)
        nodeList.append(newNode)
        properties.target_node(newNode)
Ejemplo n.º 32
0
    def create_new_child(self):
        if(self.target == None):
            return

        nodeList = get_variable("nodeList")
        children = self.target._childNodes
        x = None
        y = None
        if(children == []):
            x = self.target._x + 20
            y = self.target._y + 80
        else:
            x = children[-1]["Node"]._x + 50
            y = children[-1]["Node"]._y
        
        newChild = Node(self.target._canvas,"",0,x,y,30)
        nodeList.append(newChild)
        self.target.add_child(newChild,0)
        self.target_node(newChild)
Ejemplo n.º 33
0
    def _registerNode(self, ip_port):
        """
        Instantiate and return a new node

        If cannot instantiate node, return None.
        Creates a new node if:
           1) node.key doesn't already exist
           2) node.key exists but existing node is not alive
        """
        try:
            ip, port = ip_port
        except Exception as e:
            print "ip_port is expected to be a tuple of len 2, " + \
                "instead it is of type %s and str value of %s"%(type(ip_port)
                                                                , str(ip_port))
            return None

        try:
            node_key = Node.createKey(ip, port)
            if node_key in self.nodes:
                existing = self.nodes[node_key]
            else:
                existing = None

            if not existing or not existing.alive:
                new_node = Node(ip
                              , port
                              , use_telnet=self.use_telnet
                              , user=self.user
                              , password=self.password)

                if existing and not new_node.alive:
                    new_node = existing
            self.updateNode(new_node)

            return new_node
        except:
            return None
Ejemplo n.º 34
0
class Root:
    # region 用户自定义函数区域
    def __init__(self):
        self.sub_demo = Node(SubDemo)
        pass

    @staticmethod
    def demo(args):
        form = request.form.to_dict()
        except_keys = ['argument1', 'argument2']
        real_keys = form.keys()
        attachment = request.files.get("attachment")
        if except_keys == list(real_keys) and attachment is not None:
            return
        else:
            print(args)
            print(form)
            return {'code': 500, 'msg': '参数错误'}

    @staticmethod
    def data_demo(args):
        print('headers:', request.headers)
        print('args:', request.args)  # params
        print('cookies:', request.cookies)
        print('data:', request.data)  # json
        print('form:', request.form)  # form
        return f'This is a demo url return!\n{str(args)}'

    def sub_demo(self, args):
        form = request.form.to_dict()
        except_keys = ['argument1', 'argument2']
        real_keys = form.keys()
        if except_keys == list(real_keys):
            return {'code': 200, 'msg': '参数错误', 'data': 1000}
        else:
            print(form)
            return self.sub_demo.action(*args)
Ejemplo n.º 35
0
 def start(self, model_checker):
     Node.start(self, model_checker)
     for callback in self.start_callbacks:
         callback()
     self.start_callbacks = None
Ejemplo n.º 36
0
 def start(self, model_checker):
     Node.start(self, model_checker)
     for callback in self.start_callbacks:
         callback()
     self.start_callbacks = None
Ejemplo n.º 37
0
 def getInfoMock(self, return_value):
     Node.info = mock.Mock()
     n = Node("127.0.0.1")
     return n
Ejemplo n.º 38
0
    def __init__(self,
                 epochs,
                 population,
                 infectProb,
                 healProb,
                 deathProb,
                 World,
                 n_infected=1,
                 spreadRange=1):
        self.epochs = epochs
        self.hardstop = 0
        self.spreadRange = spreadRange
        self.population = population
        self.infectProb = infectProb
        self.healProb = healProb
        self.deathProb = deathProb
        self.world = World

        self.worldHistory = []
        self.n_infected = n_infected
        self.has_spread = False

        self.nodes = dict()
        self.deaths_n = 0
        self.healthy = []
        self.cured = []
        self.infected = []
        self.dead = []

        free_tiles = World.list_available_tiles()
        free_tiles_n = len(free_tiles)

        if not (isinstance(population, int)):
            print(
                ColorsBook.WARNING +
                "Careful, population has to be an INT : forcing it at closest number"
                + ColorsBook.ENDC)
            population = int(population)

        if population > free_tiles_n:
            print(
                ColorsBook.WARNING +
                "Careful, population higher than allocated space : forcing it at maximum"
                + ColorsBook.ENDC)
            population = free_tiles_n

        if population < 0:
            print(
                ColorsBook.WARNING +
                "Careful, population can't be negative : forcing it at random number"
                + ColorsBook.ENDC)
            population = random.randint(1, free_tiles_n)

        self.population = population

        if epochs <= 0 or not (isinstance(epochs, int)):
            print(
                ColorsBook.FAIL +
                "Negative or Zero number of EPOCHS is not allowed, terminating..."
                + ColorsBook.ENDC)
            sys.exit()

        if (infectProb or healProb or deathProb) < 0 or (infectProb or healProb
                                                         or deathProb) > 1:
            print(
                ColorsBook.FAIL +
                "Probabilities not included between [0, 1] interval, terminating..."
                + ColorsBook.ENDC)
            sys.exit()

        if (spreadRange > 1):
            print(ColorsBook.WARNING +
                  "Careful, spreading range unsupported, forcing it at 1" +
                  ColorsBook.ENDC)
            self.spreadRange = 1

        elif (spreadRange < 0):
            print(ColorsBook.WARNING +
                  "Careful, spreading range unsupported, forcing it at 0" +
                  ColorsBook.ENDC)
            self.spreadRange = 0

        elif (not (isinstance(spreadRange, int))):
            print(
                ColorsBook.WARNING +
                "Careful, spreading range unsupported (should be int), forcing to random choice between 0 and 1"
                + ColorsBook.ENDC)
            self.spreadRange = round(random.random())

        if (n_infected < 0):
            print(
                ColorsBook.WARNING +
                "Careful, initial number of infected can't be negative, forcing it at 1"
                + ColorsBook.ENDC)
            self.n_infected = 1

        elif (not (isinstance(n_infected, int))):
            print(
                ColorsBook.WARNING +
                "Careful, initial number of infected must be int, forcing it at closest int"
                + ColorsBook.ENDC)
            self.n_infected = int(n_infected)

        # Generates Nodes at random available spot
        for i in range(self.population):
            random.shuffle(free_tiles)
            picked_spot = free_tiles.pop()
            self.world.pos_matrix[picked_spot] = State.UNAFFECTED
            self.nodes[picked_spot] = Node(State.UNAFFECTED, picked_spot)
Ejemplo n.º 39
0
Archivo: host.py Proyecto: mcanini/nice
 def dump_equivalent_state(self):
     filtered_dict = Node.dump_equivalent_state(self)
     filtered_dict["arp_table"] = utils.copy_state(self.arp_table)
     return filtered_dict
Ejemplo n.º 40
0
Archivo: host.py Proyecto: mcanini/nice
 def __init__(self, name, mymac, myip):
     Node.__init__(self, name, 1)
     self.mymac = MacAddress(mymac)
     self.myip = IpAddress(myip)
     self.arp_table = {}
Ejemplo n.º 41
0
 def start(self, model_checker):
     Node.start(self, model_checker)
     for p in self.ports_to_fail:
         self.enableAction("link_fault_down", p)
Ejemplo n.º 42
0
Archivo: host.py Proyecto: mcanini/nice
 def start(self, model_checker):
     Node.start(self, model_checker)