'''
Created on Jan 3, 2011
Modified on Apr 25, 2012
@author: Dilum Bandara
@version: 0.22
@license: Apache License v2.0

   Copyright 2012 H. M. N. Dilum Bandara and Anura P. Jayasumana, Colorado State
   University

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
'''

import math

NUM_RESOURCES_PHY = 5000 #No of physical resources - not all of them in overlay
NUM_RESOURCES_VIR = 100000 #No of virtual resources - different if indexing files
NUM_PEERS = 217 #No of nodes in overlay
NUM_ATTRIBS = 1
MANY_INIT_NODES = True

ATT_LIST = ['CSp']
#ATT_LIST = ['Loc', 'Lati', 'Longi', 'NType', 'KVer', 'FCName', 'CSp', \
#            'NCore', 'CorePC', 'MSize', 'DSize', 'BWLim' \
#            , 'CFree', 'DFree', 'Tx', 'MFree', 'RspT', 'UpT', '1mLd', 'TAve', 'Drift'\
#            , '5mLd', 'Boot', 'Rx']

THRES_MAX_QUE_LOAD = 1500 #Threshold query load
THRES_MIN_QUE_LOAD = 0.1 * THRES_MAX_QUE_LOAD #Minimum query contribution
THRES_IDX_SIZE = 500 #Threshold index size
QUE_RATE = 120.0 #Inter-arrival time between 2 queries
DELAY_BEFORE_QUE = 2.0
SAMPLING_INT = 1.0 #How frequently are resources sampled
FIRST_SAMPLE_END = 999999 #When will the 1st set of resources ads end
SECOND_SAMPLE_START = 999999 #When will the 1st set of resources ads end

LOAD_CHECK_INTERVAL = 30 #When to check load
WEIGHTING_FACTOR = 0.2 #[0, 1], if 0 no exponentially weighted moving average
PROXY_ASSIGN_INTERVAL = 180 #When to reassign a proxy to resources
FIX_FINGER_INTERVAL = 180

TRACK_ATT_COST = False #Track which attribute contribute to cost

#Next hop selection policy for load balancing  
NEXT_HOP_SELECTION = 'RoundRobin' #'RoundRobin' or 'Random'
FRAGMENT_METHOD = 'Uniform'#'half' or 'Uniform' How to fragment keys on local ring 
TTL_LOAD_SPLIT = 1 #TTL for load splitting messages
THRE_CPU_SUPERPEER = -1 #Threshold for selecting node as resourceful. Else -1

#Resource & packet size
IP_PORT_SIZE = 6 #IP address & poer no - In bytes
ATT_VALUE_SIZE = 4 #Size of an attribute value
MAX_PACKET_SIZE = 1500 #Largest packet size (bytes) -Set 0 if size doesn't matter

SIM_TIME = 2000
#Simulation type 'Chord', 'Chord+Split', 'Chord+Split+Add', 'Chord+RDSim'
SIMULATION_TYPE = 'Chord+Split'

assert(NUM_RESOURCES_PHY <= NUM_RESOURCES_VIR), \
                                        'No of physical nodes > virtual ones'
if SIMULATION_TYPE not in ['Chord', 'Chord+Split', 'Chord+RDSim']:
    assert(False), 'Unknown simulation type'
if (SIMULATION_TYPE != 'Chord+RDSim') and (THRE_CPU_SUPERPEER > -1):
    assert(False), 'Simulation type not Chord + RDSim but CPU speed set'
if (SIMULATION_TYPE == 'Chord+RDSim') and (MANY_INIT_NODES == False) and \
                                            (NUM_PEERS > 1): #>1 node in overlay
    assert(False), 'No of peers more than 1'

assert(NUM_ATTRIBS == len(ATT_LIST)), 'NUM_ATTRIBS & ATT_LIST don\'t match'
if NUM_RESOURCES_PHY != NUM_RESOURCES_VIR:
    assert(SAMPLING_INT <= 1.0), 'Phy & vir resource different. Interval != 1'

KEY_LENGTH = 32 #Default key length is 160-bits
MAX_KEY = long(math.pow(2, KEY_LENGTH) - 1)
