Example #1
0
    def getHopsToCore(self, srcHost, dstHost):
        """
        Gets the distance to the core router in a Fat tree topology. For inter-pod communications
        the distance is always 3 hops, for intra-pod communication 2
        :param src:
        :param dst:
        :return:
        """
        if srcHost not in self._network:
            raise HostDoesNotExist("{0} does not exist".format(srcHost))

        if dstHost not in self._network:
            raise HostDoesNotExist("{0} does not exist".format(dstHost))

        if self.inSameSubnetwork(srcHost, dstHost):
            return 0

        elif dstHost in self.hosts_in_same_pod:
            return 2

        elif dstHost in self.hosts_in_other_pod:
            return 3

        else:
            # should never happen
            return -1
Example #2
0
    def numberDevicesInPath(self, src, dst):
        # returns the number of devices between two nodes in the network

        if src not in self._network:
            raise HostDoesNotExist("{0} does not exist".format(src))

        if dst not in self._network:
            raise HostDoesNotExist("{0} does not exist".format(dst))

        return len(nx.shortest_path(self.networkGraph.graph, src, dst))
Example #3
0
    def getHopsBetweenHosts(self, src, dst):

        if src not in self._network:
            raise HostDoesNotExist("{0} does not exist".format(src))

        if dst not in self._network:
            raise HostDoesNotExist("{0} does not exist".format(dst))

        return self.numberDevicesInPath(self.getGatewayRouter(src),
                                        self.getGatewayRouter(dst))
Example #4
0
    def getPathsBetweenHosts(self, srcHost, dstHost):
        """
        Returns all the possible paths with same cost between two hosts
        :param srcHost:
        :param dstHost:
        :return:
        """

        if srcHost not in self._network:
            raise HostDoesNotExist("{0} does not exist".format(srcHost))

        if dstHost not in self._network:
            raise HostDoesNotExist("{0} does not exist".format(dstHost))

        edgeSrc = self.getGatewayRouter(srcHost)
        edgeDst = self.getGatewayRouter(dstHost)

        return self.networkGraph.getPathsBetweenHosts(edgeSrc, edgeDst)
Example #5
0
    def getHostsBehindRouter(self, router):
        """
        Returns a list with all the hosts that have router as a gateway
        :param router:
        :return:
        """

        if router not in self._network:
            raise HostDoesNotExist("{0} does not exist".format(router))

        return self.networkGraph.getHostsBehindRouter(router)
Example #6
0
    def getGatewayRouter(self, host):
        """
        Given a host it returns its gateway router
        :param host:
        :return:
        """
        if host not in self._network:
            raise HostDoesNotExist("{0} does not exist".format(host))

        #TODO: not all hosts have gateways
        return self._network[host]["gateway"]
Example #7
0
    def loadHostsPositionsRelativeToASource(self, src):
        """
        Loads hosts positions relative to a source. It stores the names of hosts that are in the same subnetwork,
        same pod or in another pod
        :param src:
        :return:
        """

        if src not in self._network:
            raise HostDoesNotExist("{0} does not exist".format(src))

        # save relative source
        self.hosts_in_src = src
        self.hosts_in_same_pod = set(self.getHostsInSamePod(src))
        self.hosts_in_other_pod = set(self.getHostsInOtherPods(src))
Example #8
0
    def getHostsInOtherSubnetworks(self, host):
        """
        Returns all the hosts from other subnetworks. This is used to generate traffic only to "remote" hosts
        :param host:
        :return:
        """

        if host not in self._network:
            raise HostDoesNotExist("{0} does not exist".format(host))

        # returns all the hosts that are in other subnetworks
        gatewayEdgeRouter = self.getGatewayRouter(host)
        edgeRouters = self.getEdgeRouters()

        otherHosts = []
        for edgeRouter in edgeRouters:
            if edgeRouter == gatewayEdgeRouter:
                continue
            otherHosts += self.getHostsBehindRouter(edgeRouter)

        return otherHosts
Example #9
0
    def getHostsInSamePod(self, host):

        # returns the name of all the hosts that are in the same pod but different subnetworks

        if host not in self._network:
            raise HostDoesNotExist("{0} does not exist".format(host))

        edgeRouters = self.getEdgeRouters()
        current_host_edge = self.getGatewayRouter(host)

        # filter and keep only edges with same pod number
        edgeInPod = [
            router for router in edgeRouters
            if router.split("_")[1] == current_host_edge.split("_")[1]
            and router != current_host_edge
        ]

        hosts = []
        for edgeRouter in edgeInPod:
            hosts += self.getHostsBehindRouter(edgeRouter)

        return hosts
Example #10
0
    def isOVS(self, node):

        if node not in self._network:
            raise HostDoesNotExist("{0} does not exist".format(node))

        return self._network[node]["type"] == "switch" and node[:3] == "ovs"