

def tunnel_new_handler(self, payload):
    ' Create a new tunnel (response side) '
    tunnel = self._get_tunnel(payload['from_rt_uuid'], payload['type'])
    ok = False
    _log.analyze(self.rt_id, '+', payload, peer_node_id=payload['from_rt_uuid'])
    if tunnel:
        _log.analyze(self.rt_id, '+ PENDING', payload, peer_node_id=payload['from_rt_uuid'])
        if (tunnel.status != CalvinTunnel.STATUS.WORKING):
            ok = True
            if (tunnel.id < payload['tunnel_id']):
                msg = {
                    'cmd': 'REPLY',
                    'msg_uuid': payload['msg_uuid'],
                    'value': response.CalvinResponse(ok, data={
                        'tunnel_id': payload['tunnel_id'],
                    }).encode(),
                }
                self.network.links[payload['from_rt_uuid']].send(msg)
                tunnel._setup_ack(response.CalvinResponse(True, data={
                    'tunnel_id': payload['tunnel_id'],
                }))
                _log.analyze(self.rt_id, '+ CHANGE ID', payload, peer_node_id=payload['from_rt_uuid'])
            else:
                msg = {
                    'cmd': 'REPLY',
                    'msg_uuid': payload['msg_uuid'],
                    'value': response.CalvinResponse(ok, data={
                        'tunnel_id': tunnel.id,
                    }).encode(),
                }
                self.network.links[payload['from_rt_uuid']].send(msg)
                tunnel._setup_ack(response.CalvinResponse(True, data={
                    'tunnel_id': tunnel.id,
                }))
                _log.analyze(self.rt_id, '+ KEEP ID', payload, peer_node_id=payload['from_rt_uuid'])
        else:
            _log.analyze(self.rt_id, '+ DROP FIXME', payload, peer_node_id=payload['from_rt_uuid'])
        return
    else:
        tunnel = CalvinTunnel(self.network.links, self.tunnels, payload['from_rt_uuid'], payload['type'], payload['policy'], rt_id=self.node.id, id=payload['tunnel_id'])
        _log.analyze(self.rt_id, '+ NO SMASH', payload, peer_node_id=payload['from_rt_uuid'])
        try:
            ok = self.tunnel_handlers[payload['type']](tunnel)
        except:
            pass
    msg = {
        'cmd': 'REPLY',
        'msg_uuid': payload['msg_uuid'],
        'value': response.CalvinResponse(ok, data={
            'tunnel_id': tunnel.id,
        }).encode(),
    }
    self.network.links[payload['from_rt_uuid']].send(msg)
    if (not ok):
        tunnel.close(local_only=True)

dataset/ETHPy150Open EricssonResearch/calvin-base/calvin/runtime/north/calvin_proto.py CalvinProto.tunnel_new_handler/original