Beispiel #1
0
    def add_entity(self, entity_type, *properties):
        entity_class = LogicalEntityZoo.logical_entity_types.get(entity_type)
        if entity_class is None:
            logger.warning('unknow entity_type %s', entity_type)
            return

        entity_id = properties[0]
        entity_group = self.entity_set[entity_type]
        with self.lock:
            if entity_group.has_key(entity_id) and \
               entity_group[entity_id].is_same(*properties):
                logger.info(
                    'entity_set[%s] has same property entity '
                    'exist entity:%s, conflict entity:%s', entity_type,
                    entity_group[entity_id], properties)
                return
            try:
                e = entity_class(*properties)
            except Exception as err:
                logger.exception(
                    "hit error in adding entity %s, "
                    "property:%s, err:%s", entity_type, properties, err)
                return
        self._add_entity_in_zoo(entity_type, e)

        # a chassis which a LR pin on should be touch to generate
        # tunnel. This tunnel was use to redirect traffic.
        if not get_extra()['options'].has_key('ONDEMAND'):
            return
        # a LR pin on a remote chassis means this chassis s a
        # gateway or agent. The tunnel should be generated immediately.
        if entity_type == LOGICAL_ENTITY_TYPE_LR:
            self._touch_gateway_by_LR(e)
        if entity_type == LOGICAL_ENTITY_TYPE_CHASSIS:
            self._touch_gateway_by_chassis(e)
Beispiel #2
0
def process_trace(trace_msg_seg):
    table_id = trace_msg_seg[1]
    datapath_id = trace_msg_seg[2]
    cmd_id = int(trace_msg_seg[3]) >> 16
    src_port_id = trace_msg_seg[4]
    dst_port_id = trace_msg_seg[5]
    tun_src = int(trace_msg_seg[6])
    seq_n = trace_msg_seg[7]
    logger.info(
        'tracing packets, table_id:%s, datapath_id:%s, '
        'cmd_id:%d, src_port_id:%s, dst_port_id:%s, seq:%s, tun_src:%d',
        table_id, datapath_id, cmd_id, src_port_id, dst_port_id, seq_n,
        tun_src)
    ttl = 30
    chassis_id = get_extra()['system_id']
    key = "cmd_result/{}/{}/{}".format(cmd_id, seq_n, chassis_id)
    value = "cmd_type=pkt_trace,table_id={},datapath_id={},src_port_id={},dst_port_id={},tun_src={}".format(
        table_id, datapath_id, src_port_id, dst_port_id, tun_src)
    wmaster = extra['lm']
    wmaster.lease_communicate(key, value, ttl)
Beispiel #3
0
def init_entity_clause(options):

    local_bond_lsp(LSP_WITH_OFPORT, LS, State) <= (
        ovsport(PORT_NAME, UUID_LSP, OFPORT, State1) &
        (OFPORT > 0) & ls_array(LS, UUID_LS, State2)
        & lsp_array(UUID_LSP, LSP, UUID_LS, UUID_CHASSIS, UUID_LRP, State3)
        & local_system_id(UUID_CHASSIS) &
        (LSP_WITH_OFPORT == (LSP + [OFPORT])) &
        (State == State1 + State2 + State3))

    local_lsp(LSP, LS, State) <= ((UUID_LR_CHASSIS == None) & lsp_link_lrp(
        LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State))
    local_lsp(LSP, LS,
              State) <= (local_system_id(UUID_LR_CHASSIS) & lsp_link_lrp(
                  LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State))
    local_lsp(LSP, LS, State) <= (local_bond_lsp(LSP, LS, State))

    active_lsp(LSP, LS, UUID_LS,
               State) <= (ls_array(LS, UUID_LS, State1) & lsp_array(
                   UUID_LSP, LSP, UUID_LS, UUID_CHASSIS, UUID_LRP, State2)
                          & chassis_array(PHY_CHASSIS, UUID_CHASSIS, State3) &
                          (State == State1 + State2 + State3))
    active_lsp(LSP, LS, UUID_LS, State) <= (lsp_link_lrp(
        LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State))

    remote_chassis(UUID_CHASSIS, PHY_CHASSIS_WITH_OFPORT, State) <= (
        ovsport_chassis(PORT_NAME, UUID_CHASSIS, OFPORT, State1) &
        (OFPORT > 0) & chassis_array(PHY_CHASSIS, UUID_CHASSIS, State2) &
        (PHY_CHASSIS_WITH_OFPORT == PHY_CHASSIS + [OFPORT]) &
        (State == State1 + State2))

    local_chassis(PHY_CHASSIS,
                  State) <= (local_system_id(UUID_CHASSIS)
                             & chassis_array(PHY_CHASSIS, UUID_CHASSIS, State))

    remote_lsp(LSP, LS, PHY_CHASSIS, State) <= (
        remote_chassis(UUID_CHASSIS, PHY_CHASSIS, State1)
        & lsp_array(UUID_LSP, LSP, UUID_LS, UUID_CHASSIS, UUID_LRP, State2)
        & ls_array(LS, UUID_LS, State3) & (State == State1 + State2 + State3))

    remote_lsp(LSP, LS, PHY_CHASSIS, State) <= (lsp_link_lrp(
        LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS,
        State1) & remote_chassis(UUID_LR_CHASSIS, PHY_CHASSIS, State2) &
                                                (State == State1 + State2))

    lsp_link_lrp(
        LSP, LS, UUID_LS, LRP, LR, UUID_LR, UUID_LR_CHASSIS, State) <= (
            lrp_array(UUID_LRP, LRP, UUID_LR, UUID_LSP, State1)
            & exchange_lsp_array(UUID_LSP, LSP, UUID_LS, UUID_CHASSIS,
                                 UUID_LRP, State2)
            & ls_array(LS, UUID_LS, State3) & lr_array(LR, UUID_LR, State4) &
            (UUID_LR_CHASSIS == LR[LR_CHASSIS_UUID]) &
            (State == State1 + State2 + State3 + State4))

    next_hop_ovsport(UUID_LRP, OFPORT, State) <= (
        lrp_array(UUID_LRP, LRP, UUID_LR, UUID_LSP, State1)
        & exchange_lsp_array(UUID_LSP1, LSP1, UUID_LS, UUID_CHASSIS1, UUID_LRP,
                             State2)
        & exchange_lsp_array(UUID_LSP2, LSP2, UUID_LS, UUID_CHASSIS2,
                             UUID_LRP2, State3)
        & lrp_array(UUID_LRP2, LRP2, UUID_LR2, UUID_LSP2, State4) &
        (UUID_LR != UUID_LR2) & lr_array(LR2, UUID_LR2, State5)
        & ovsport_chassis(PORT_NAME, LR2[LR_CHASSIS_UUID], OFPORT, State6) &
        (State == State1 + State2 + State3 + State4 + State5 + State6))

    if not get_extra()['options'].has_key('ENABLE_PERFORMANCE_TESTING'):
        lnat_data(LNAT, LR, XLATE_TYPE, UUID_LR, State) <= (
            lr_array(LR, UUID_LR, State1) &
            # TODO local_system_id, UUID_CHASSIS here introduce
            # performance regression
            (UUID_CHASSIS == LR[LR_CHASSIS_UUID])
            & local_system_id(UUID_CHASSIS)
            & lnat_array(LNAT, UUID_LR, XLATE_TYPE, State2) &
            (State == State1 + State2))
    else:
        lnat_data(LNAT, LR, XLATE_TYPE, UUID_LR,
                  State) <= (lr_array(LR, UUID_LR, State1)
                             & lnat_array(LNAT, UUID_LR, XLATE_TYPE, State2) &
                             (State == State1 + State2))
Beispiel #4
0
 def _is_update_clause(self):
     if not get_extra()['options'].has_key('ONDEMAND'):
         return True
     if self.uuid == get_extra()['system_id']:
         return True
     return self.touched
Beispiel #5
0
import logging
import subprocess
import struct, socket
import flow_common
import run_env
from pyDatalog import pyDatalog
from commit_ovs import commit_flows
from onexit import on_parent_exit
from tp_utils import pipe
from run_env import get_extra
from tuplesync import update_ovs_side
from logicalview import LOGICAL_ENTITY_TYPE_LSP, LOGICAL_ENTITY_TYPE_CHASSIS

MAX_BUF_LEN = 10240

extra = run_env.get_extra()
logger = logging.getLogger(__name__)
entity_zoo = None


def int_to_ip(ip_int):
    return socket.inet_ntoa(struct.pack('I', socket.htonl(ip_int)))


def update_ovs_arp_ip_mac(mac_addr, ip_int):
    match = 'table={t},priority=1,ip,reg2={dst},'.format(
        t=flow_common.TABLE_SEARCH_IP_MAC, dst=ip_int)
    action = 'actions=mod_dl_dst:{}'.format(mac_addr)
    flow = match + action
    commit_flows([flow], [])
Beispiel #6
0
import pickle
import socket
import os
import logging
import threading
import run_env

options = run_env.get_extra()['options']
RUNNING_ENV_PATH = options['TUPLENET_RUNDIR']
PKT_CONTROLLER_PIPE_PATH = os.path.join(RUNNING_ENV_PATH,
                                        'pkt_controller_pipe')
DEBUG_PIPE_PATH = os.path.join(RUNNING_ENV_PATH, 'debug_pipe.sock')

logger = logging.getLogger(__name__)
logger.info('RUNNING_ENV_PATH:%s', RUNNING_ENV_PATH)

plock = threading.Lock()


def write_pipe(obj, path):
    with open(path, 'wb') as fd:
        pickle.dump(obj, fd)


def write_pipe_cb(cb, path):
    with open(path, 'wb') as fd:
        obj = cb()
        pickle.dump(obj, fd)


def read_pipe(path):
Beispiel #7
0
        ch = PhysicalChassis(
            chassis_id, "192.{}.{}.{}".format(random.randint(1, 254),
                                              random.randint(1, 254),
                                              random.randint(1, 254)),
            int(time.time()))
        chassis_set[chassis_id] = ch
        start_time = time.time()
        tunnel.tunnel_port_oper(A, B, C)
        tmp = A.data
        tmp = B.data
        tmp = C.data
        logger.info('tunnel_port_oper cost time:%s, num:%d',
                    time.time() - start_time, len(tmp))
        start_time = time.time()
        active_lsp(A, B, C, State)
        tmp = A.data
        logger.info('active_lsp cost time:%s', time.time() - start_time)

        logger.info('\n\n')


extra = get_extra()
extra['system_id'] = 'chassis-local'
extra['options'] = {}
extra['options']['ENABLE_REDIRECT'] = ''
extra['options']['ENABLE_PERFORMANCE_TESTING'] = ''
extra['options']['ONDEMAND'] = ''
entity_set = entity_zoo.entity_set
lflow.init_build_flows_clause(extra['options'])
test_rand_entity(entity_set, 200, 500, 5000)