Ejemplo n.º 1
0
    def reroute_intents(self, topoManager):
        self.retrieve_monitored_intents_from_ONOS()
        reroute_msg = {'routingList': []}
        topo = topoManager.get_net_active_topology().copy()

        for link in topo.edges():
            logging.info(
                "link %s-%s with availability %d" %
                (link[0], link[1], topo[link[0]][link[1]]["availability"]))
            topo[link[0]][link[1]]["weight"] = 1 if topo[link[0]][
                link[1]]["availability"] >= 90 else 100

        for link in topo.edges():
            logging.info("link %s-%s with weight %d" %
                         (link[0], link[1], topo[link[0]][link[1]]["weight"]))
        """
        print("*"*30)
        print("HOST:", topoManager.hosts)
        print("ITEMS:", self.intentKey_to_inOutElements.items())
        print("NODES:", topo.nodes())
        print("EDGES:", topo.edges())
        print("FULL:", topoManager.get_net_full_topology().edges())
        print("*" * 30)
        """

        for flow_id, elems in self.intentKey_to_inOutElements.items():
            intent_key, app_id, app_name = flow_id
            in_elem, out_elem = elems
            if self.verbose:
                print '\nTrying to route demand %s -> %s' % (in_elem, out_elem)
            try:
                path = nx.shortest_path(topo, topoManager.hosts[in_elem],
                                        topoManager.hosts[out_elem], 'weight')
                if self.verbose:
                    print 'Found path %s' % path
                reroute_msg['routingList'].append({
                    'key':
                    intent_key,
                    'appId': {
                        'id': app_id,
                        'name': app_name
                    },
                    'paths': [{
                        'path': path,
                        'weight': 1.0
                    }]
                })
            except:
                if self.verbose:
                    print 'No path found'
                    print(topoManager.hosts[in_elem],
                          topoManager.hosts[out_elem])

        if self.verbose:
            logging.info('reroute_msg config:')
            pprint(reroute_msg)
        json_post_req(('http://%s:%d/onos/v1/imr/imr/reRouteIntents' %
                       (ONOS_IP, ONOS_PORT)), json.dumps(reroute_msg))
Ejemplo n.º 2
0
    def reroute_intents_max_availability(self, topoManager):
        self.retrieve_monitored_intents_from_ONOS()
        reroute_msg = {'routingList': []}
        topo = topoManager.get_net_active_topology().copy()
        for link in topo.edges():
            topo[link[0]][link[1]]["availability"] = -log10(
                topo[link[0]][link[1]]["availability"] / 100)
        for link in topo.edges():
            print("link", link[0], link[1], "availability",
                  topo[link[0]][link[1]]["availability"])

        for flow_id, elems in self.intentKey_to_inOutElements.items():
            intent_key, app_id, app_name = flow_id
            in_elem, out_elem = elems
            if self.verbose:
                print '\nTrying to route demand %s -> %s' % (in_elem, out_elem)
            try:
                path = nx.shortest_path(topo, topoManager.hosts[in_elem],
                                        topoManager.hosts[out_elem],
                                        'availability')
                if self.verbose:
                    print 'Found path %s' % path
                reroute_msg['routingList'].append({
                    'key':
                    intent_key,
                    'appId': {
                        'id': app_id,
                        'name': app_name
                    },
                    'paths': [{
                        'path': path,
                        'weight': 1.0
                    }]
                })
            except:
                if self.verbose:
                    print 'No path found'
                    print(topoManager.hosts[in_elem],
                          topoManager.hosts[out_elem])

        if self.verbose:
            logging.info('reroute_msg config:')
            pprint(reroute_msg)
        json_post_req(('http://%s:%d/onos/v1/imr/imr/reRouteIntents' %
                       (ONOS_IP, ONOS_PORT)), json.dumps(reroute_msg))
Ejemplo n.º 3
0
    def monitor_intent(self):
        msg = dict()
        msg['name'] = self.tracked_intent['app_name']
        msg['intentKey'] = self.tracked_intent['key']

        result = json_post_req(
            ('http://%s:%d/onos/v1/imrx/imrx/startMonitorIntent' %
             (ONOS_IP, ONOS_PORT)), json.dumps(msg))
        return 'Failed' not in json.dumps(result)
Ejemplo n.º 4
0
    def reroute_monitored_intents(self, tm, topoManager):
        reroute_msg = {'routingList': []}

        topo = topoManager.G.copy()

        # iterate over flows (sorted by amount, in decreasing order)
        for flow_id, amount in sorted(tm.items(),
                                      key=lambda x: x[1],
                                      reverse=True):
            intent_key, app_id, app_name = flow_id
            in_elem, out_elem = self.intentKey_to_inOutElements[flow_id]
            if self.verbose:
                print '\nTrying to route %s for demand %s -> %s' % (
                    bps_to_human_string(amount), in_elem, out_elem)

            # build a reduced_topo keeping just links with enough capacity to accomodate the current demand
            reduced_topo = reduced_capacity_topo(topo, amount)
            try:
                path = nx.shortest_path(reduced_topo, in_elem, out_elem)
                if self.verbose:
                    print 'Found path %s' % path
                # update the topology
                topo = reduced_capacity_on_path(topo, amount, path)
                reroute_msg['routingList'].append({
                    'key':
                    intent_key,
                    'appId': {
                        'id': app_id,
                        'name': app_name
                    },
                    'paths': [{
                        'path': path,
                        'weight': 1.0
                    }]
                })
            except nx.NetworkXNoPath:
                if self.verbose:
                    print 'No path found'

        if self.verbose:
            logging.info('reroute_msg config:')
            pprint(reroute_msg)
        json_post_req(('http://%s:%d/onos/v1/imr/imr/reRouteIntents' %
                       (ONOS_IP, ONOS_PORT)), json.dumps(reroute_msg))
Ejemplo n.º 5
0
 def __send_paths(self, reroute_msg):
     routes = reroute_msg['paths']
     if routes == []:
         logging.info("[Warning] no paths to send")
         return
     # add paths in reverse direction
     reversed_paths = []
     for route in routes:
         reversed_path = {'path': route['path'][::-1]}
         if reversed_path not in routes and reversed_path not in reversed_paths:  
             reversed_paths.append(reversed_path)
     routes.extend(reversed_paths)   
     # send paths for rerouting   
     logging.info("Start rerouting...")
     for msg in reroute_msg['paths']:
         logging.info(msg['path'])
     reply = json_post_req('http://%s:%d/reroute' % (ONOS_IP, ONOS_PORT), json.dumps(reroute_msg))
     if reply != '':
         logging.info(reply)
Ejemplo n.º 6
0
import json
from config import ONOS_IP, ONOS_PORT
from utils import json_get_req, json_post_req
import logging

data = {
    'paths': [{
        'path': [
            "00:00:00:00:00:02/None", "of:0000000000000001",
            "of:0000000000000002", "00:00:00:00:00:04/None"
        ]
    }, {
        'path': [
            "00:00:00:00:00:04/None", "of:0000000000000002",
            "of:0000000000000001", "00:00:00:00:00:02/None"
        ]
    }]
}

reply = json_post_req('http://%s:%d/reroute' % (ONOS_IP, ONOS_PORT),
                      json.dumps(data))
print reply

reply = json_get_req('http://%s:%d/bandwidth/topology' % (ONOS_IP, ONOS_PORT))
print reply

reply = json_get_req('http://%s:%d/state/connectivity' % (ONOS_IP, ONOS_PORT))
print reply
Ejemplo n.º 7
0
    def step(self, indexs_path):
        if not self.validate_path(indexs_path):
            return self.now_s, -1.0

        r = 1.0
        path = []
        # add src host mac
        path.append(self.tracked_intent['src_host'])

        # add switch
        for i in range(len(indexs_path)):
            index = self.arrayIndex_to_deviceId[indexs_path[i]]
            path.append(index)

        # add dst host mac
        path.append(self.tracked_intent['dst_host'])

        reroute_msg = {'routingList': []}
        reroute_msg['routingList'].append({
            'key':
            self.tracked_intent['key'],
            'appId': {
                'name': self.tracked_intent['app_name']
            },
            'paths': [{
                'path': path,
                'weight': 1.0
            }]
        })
        # here shuold add get now load, change to get last recently load in future
        old_intent_load = self.update_intent_load()
        json_post_req(('http://%s:%d/onos/v1/imrx/imrx/reRouteIntents' %
                       (ONOS_IP, ONOS_PORT)), json.dumps(reroute_msg))

        # avoid run to long time
        soldier = 0
        devices = dict()
        flag = False
        req_str = 'http://%s:%d/onos/v1/imrx/imrx/intentStatsNew/%s/%s' \
                  % (ONOS_IP,
                     ONOS_PORT,
                     self.tracked_intent['app_name'],
                     self.tracked_intent['url_key'])
        # new path
        # print(req_str)
        while soldier < 5:
            # every retry wait 2s
            time.sleep(2)
            devices.clear()
            reply = json_get_req(req_str)
            # valid exits statistics
            if 'statistics' not in reply or len(reply['statistics']) != 1:
                soldier += 1
                continue
            # only one object
            app_stat = reply['statistics'][0]
            intent_stat = app_stat['intents'][0]
            (key, items), = intent_stat.items()
            # here have some problem
            # if one flow is not added break and start next try
            for stat in items:
                device = stat['deviceId']
                if stat['state'] != 'ADDED' \
                        or self.deviceId_to_arrayIndex.get(device) is None:
                    break
                # collect stats device id
                else:
                    devices[device] = device

            # valid path node not in path
            if len(devices) == len(indexs_path):
                internalFlag = True
                for index in indexs_path:
                    pathDevice = self.arrayIndex_to_deviceId[index]
                    # path node is not in the flow stats
                    if devices.get(pathDevice) is None:
                        internalFlag = False
                        break
                if internalFlag:
                    flag = True
                    break
            soldier += 1

        if flag:
            # wait 60 second ,make flow stable
            time.sleep(60)
            new_intent_load = self.update_intent_load()
            change = new_intent_load - old_intent_load
            if old_intent_load > 0:
                r += change / old_intent_load

        self.update_network_load()
        embeddinged_route_args = self.get_embeddinged_route_args(
            indexs_path[-1])
        # flattened traffic
        now_traffic = self.env_loads.flatten()
        # s = route_args + network state
        s_ = np.append(embeddinged_route_args, now_traffic)
        return s_, r