Exemplo n.º 1
0
    def create_scaled_endpoint(self, ip, backends):
        """
        Creates a scaled endpoint in the network.
        1. First create the endpoint object and add it to the set of
           endpoints
        2. Call update_endpoint on all transit switch of the
           network.
        """
        logger.info("[NETWORK {}]: create_scaled_endpoint {}".format(
            self.netid, ip))

        if ip in self.endpoints:
            raise ValueError("Endpoint IP {} is already in use.".format(ip))

        switches = list(self.transit_switches.values())

        self.endpoints[ip] = endpoint(self.vni,
                                      self.netid,
                                      ip=ip,
                                      vpc_cidr=self.vpc_cidr,
                                      net_cidr=self.cidr,
                                      gw_ip=self.get_gw_ip(),
                                      eptype=CONSTANTS.TRAN_SCALED_EP,
                                      host=None,
                                      backends=backends)

        # Now update the endpoint on the remaining switches
        for switch in switches:
            switch.update_scaled_endpoint(self.endpoints[ip])

        # Update the endpoint again with the full switches
        self.endpoints[ip].update(self)

        return self.endpoints[ip]
Exemplo n.º 2
0
    def create_vxlan_endpoint(self, ip, host):
        """
        Creates a vxlan endpoint
        """
        logger.info("[NETWORK {}]: create_vxlan_endpoint {}".format(
            self.netid, ip))
        br = self.get_ovs_bridge_name()
        if (not host.ovs_is_exist(br)):
            host.ovs_add_bridge(br)
        self.endpoints[ip] = endpoint(self.vni,
                                      self.netid,
                                      ip=ip,
                                      vpc_cidr=self.vpc_cidr,
                                      net_cidr=self.cidr,
                                      gw_ip=self.get_gw_ip(),
                                      host=host,
                                      tuntype='vxn',
                                      bridge=br)

        # Create a geneve tunnel interface to one of the switches
        transit_itf = 'vxn_transit'
        switch = list(self.transit_switches.values())[0]
        transit_port = host.ovs_create_geneve_tun_itf(br, transit_itf,
                                                      self.vni, switch.ip)
        host.ovs_add_transit_flow(br, self.endpoints[ip].bridge_port,
                                  transit_port)

        # We now tell the transit switch about the endpoint
        for s in self.transit_switches.values():
            s.update_endpoint(self.endpoints[ip])

        # Create vxlan tunnel interface to all vxlan endpoints
        for ep_i in self.endpoints.values():
            if ep_i.host is None or ep_i.tuntype != 'vxn':
                continue

            for ep_j in self.endpoints.values():
                if ep_j.host is None:
                    continue

                if ep_i.host.ip == ep_j.host.ip:
                    continue

                if ep_j.tuntype == 'vxn':
                    remote_ip = ep_j.host.ip
                    out_port = ep_i.host.ovs_create_vxlan_tun_itf(
                        br, ep_j.tunitf, self.vni, remote_ip)
                    ep_i.host.add_vxlan_ofrule(br, ep_i.bridge_port, out_port,
                                               ep_j.ip)

        return self.endpoints[ip]
Exemplo n.º 3
0
    def create_simple_endpoint(self, ip, host):
        """
        Creates a simple endpoint in the network.
        1. First create the endpoint object and add it to the set of
           endpoints
        2. Call update_endpoint on at least one transit switch of the
           network (two or three switches may be a good idea in production!).
        3. Call update on each endpoint's transit agent within the
           network. The endpoint becomes ready to send  packets.
        """
        logger.info("[NETWORK {}]: create_simple_endpoint {}".format(
            self.netid, ip))

        if ip in self.endpoints:
            raise ValueError("Endpoint IP {} is already in use.".format(ip))

        switches = list(self.transit_switches.values())

        # Create a temp network object of only one switch
        temp_net = network(self.vni, self.netid, self.cidr, self.vpc_cidr)
        temp_net.transit_switches[switches[0].id] = switches[0]

        start = time.time()

        self.endpoints[ip] = endpoint(self.vni,
                                      self.netid,
                                      ip=ip,
                                      vpc_cidr=self.vpc_cidr,
                                      net_cidr=self.cidr,
                                      gw_ip=self.get_gw_ip(),
                                      host=host)

        switches[0].update_endpoint(self.endpoints[ip])
        self.endpoints[ip].update(temp_net)

        end = time.time()
        ep_ready_time = end - start
        logger.info(
            "[NETWORK {}]: endpoint {} provisioned and ready in {:5.4f} seconds (O(1)!)."
            .format(self.netid, ip, ep_ready_time))

        # Now update the endpoint on the remaining switches
        for switch in switches[1:]:
            switch.update_endpoint(self.endpoints[ip])

        # Update the endpoint again with the full switches
        self.endpoints[ip].update(self)

        return self.endpoints[ip]
Exemplo n.º 4
0
    def create_host_endpoint(self, ip, host):
        logger.info("[NETWORK {}]: create_host_endpoint {}".format(
            self.netid, ip))
        self.endpoints[ip] = endpoint(self.vni,
                                      self.netid,
                                      ip=ip,
                                      prefixlen=self.cidr.prefixlen,
                                      gw_ip=self.get_gw_ip(),
                                      host=host,
                                      netip=self.cidr.ip,
                                      host_ep="yes")

        # Now update the endpoint on the remaining switches
        for switch in self.transit_switches.values():
            switch.update_endpoint(self.endpoints[ip])
        self.endpoints[ip].update(self)
Exemplo n.º 5
0
    def create_host_endpoint(self, ip, host):
        logger.info("[NETWORK {}]: create_host_endpoint {}".format(
            self.netid, ip))
        self.endpoints[ip] = endpoint(self.vni,
                                      self.netid,
                                      ip=ip,
                                      vpc_cidr=self.vpc_cidr,
                                      net_cidr=self.cidr,
                                      gw_ip=self.get_gw_ip(),
                                      host=host,
                                      host_ep=True)

        # Now update the endpoint on the remaining switches
        for switch in self.transit_switches.values():
            switch.update_endpoint(self.endpoints[ip])
        self.endpoints[ip].update(self)
        return self.endpoints[ip]
Exemplo n.º 6
0
    def create_gw_endpoint(self):
        """
        Allocates the first IP of the network CIDR range and
        Creates a phantom endpoint (without a host).
        """
        ip = self.get_gw_ip()

        if ip in self.endpoints:
            raise ValueError("Endpoint IP {} is already in use.".format(ip))

        logger.info("[NETWORK {}]: create_gw_endpoint {}".format(
            self.netid, ip))

        self.endpoints[ip] = endpoint(
            self.vni, self.netid, ip=ip, prefixlen=self.cidr.prefixlen, gw_ip=None, host=None)

        # Now update the endpoint on the remaining switches
        for switch in self.transit_switches.values():
            switch.update_endpoint(self.endpoints[ip])