Beispiel #1
0
        public TlfNet GetIPNet(uint prefix, string number)
        {
            TlfNet net = null;

            if (prefix == Cd40Cfg.ATS_DST)
            {
                ulong num;
                if (ulong.TryParse(number, out num))
                {
                    // Se comprueba si existe un equipo externo con capacidad
                    // para dar servicio a números ATS, un encaminamiento tipo central IP
                    foreach (Scv scv in _OtrosScv.Values)
                    {
                        if (scv.EsCentralIp && scv.IsInRangeScv(num))
                        {
                            net = CreateIpNet(number, scv);
                        }
                    }
                    //Puede ser el caso de una numeración que pertenece a mi SCV (y no sea un puesto de operación)
                    if ((net == null) && _MiScv.EsCentralIp && _MiScv.IsInRangeScv(num))
                    {
                        net = CreateIpNet(number, _MiScv);
                    }
                }
            }
            return(net);
        }
Beispiel #2
0
        private static TlfNet CreateIpNet(string number, Scv scv)
        {
            TlfNet net = new TlfNet();

            net.Id = "Net_ATS_IP_" + scv.Id;

            Rs <GwTlfRs> rs = Top.Registry.GetRs <GwTlfRs>(number);
            string       ScvIp;

            if (rs.Content == null)
            {
                //Si el recurso no tiene contenido actualizado, la IP es de los datos de configuración (principal)
                string id;
                ScvIp = scv.GetProxyIp(out id);
                if (rs.IsUnreferenced)
                {
                    //Para que recién creado por defecto aparezca sin aspa, le añado un recurso
                    GwTlfRs proxyRs = new GwTlfRs();
                    proxyRs.GwIp = ScvIp;
                    rs.Reset(null, proxyRs);
                }
            }
            else
            {
                //Utilizo los datos del recurso (actualizado con el activo)
                ScvIp = ((GwTlfRs)rs.Content).GwIp;
            }
            SipLine line = new SipLine(rs, ScvIp, true);

            net.Lines.Add(line);
            net.RsTypes.Add(new RsIdxType(net.Lines.Count - 1, 0, TipoInterface.TI_IP_PROXY));
            net.Routes.Add(0);
            return(net);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cfg"></param>
        public void Reset(CfgEnlaceInterno cfg)
        {
            _Literal     = cfg.Literal;
            _LastChannel = 0;
            _Channels.Clear();

            foreach (CfgRecursoEnlaceInterno dst in cfg.ListaRecursos)
            {
                switch (dst.Prefijo)
                {
                case Cd40Cfg.INT_DST:
                    string hostId = Top.Cfg.GetUserHost(dst.NombreRecurso);

                    if (_Channels.Find(delegate(SipChannel channel)
                                       { return((channel.Prefix == dst.Prefijo) && (channel.Id == hostId)); }) == null)
                    {
                        SipChannel ch = new IntChannel(cfg.OrigenR2, hostId, dst.NombreRecurso, dst.Prefijo);
                        ch.RsChanged += OnRsChanged;

                        _Channels.Insert(0, ch);
                    }
                    break;

                case Cd40Cfg.PP_DST:
                    if (_Channels.Find(delegate(SipChannel channel)
                                       { return((channel.Prefix == dst.Prefijo) && (channel.Id == dst.NombreRecurso)); }) == null)
                    {
                        SipChannel ch = dst.Interface == TipoInterface.TI_LCEN ?
                                        (SipChannel) new LcChannel(cfg.OrigenR2, dst.NombreRecurso, dst.Prefijo) :
                                        (SipChannel) new TlfPPChannel(cfg.OrigenR2, dst.NumeroAbonado, dst.NombreRecurso, dst.Prefijo, dst.Interface);
                        ch.RsChanged += OnRsChanged;

                        _Channels.Add(ch);
                    }

                    if (cfg.Dependencia != string.Empty)
                    {
                        _Dependencia = cfg.Dependencia;
                        _Groups.Add(_Dependencia);
                    }
                    break;

                case Cd40Cfg.ATS_DST:
                    string[] userId = Top.Cfg.GetUserFromAddress(dst.Prefijo, dst.NumeroAbonado);
                    if (userId != null)
                    {
                        dst.NombreRecurso = userId[1];
                        dst.Prefijo       = Cd40Cfg.INT_DST;
                        goto case Cd40Cfg.INT_DST;
                    }

                    TlfNet net = Top.Cfg.GetIPNet(dst.Prefijo, dst.NumeroAbonado);

                    if (net != null)
                    {
                        SipChannel ch = _Channels.Find(delegate(SipChannel channel) { return((channel.Prefix == dst.Prefijo) && (channel.Id == net.Id)); });

                        if (ch == null)
                        {
                            // Para Linea caliente en destinos ATS_DST,
                            // solo se utilizan las lineas que vienen de un encaminamiento IP
                            List <SipLine> listLines = net.Lines.FindAll(line => line.centralIP == false);
                            foreach (SipLine line in listLines)
                            {
                                int index = net.Lines.IndexOf(line);
                                net.Lines.RemoveAt(index);
                                net.Routes.RemoveAt(index);
                                net.RsTypes.RemoveAt(index);
                            }
                            //Caso de destino ATS de central no IP: no tiene canal ATS (no lo añado), solo canal LC
                            if (net.Lines.Count > 0)
                            {
                                ch            = new TlfNetChannel(net, cfg.OrigenR2, dst.NumeroAbonado, null, dst.Prefijo);
                                ch.RsChanged += OnRsChanged;

                                _Channels.Add(ch);
                            }
                        }
                        else
                        {
                            ch.AddRemoteDestination(dst.NumeroAbonado, null);
                        }
                    }

                    break;
                }
            }

            if ((_SipCallRx != null) && !_SipCallRx.IsValid(_Channels))
            {
                MakeHangUpRx();
            }
            if ((_SipCallTx != null) && !_SipCallTx.IsValid(_Channels))
            {
                MakeHangUpTx();
            }

            LcRxState rxSt = _RxState;
            LcTxState txSt = _TxState;

            if ((_SipCallRx == null) || (_SipCallTx == null))
            {
                GetState(out rxSt, out txSt);
            }

            if (_SipCallRx != null)
            {
                rxSt = _RxState;
            }
            if (_SipCallTx != null)
            {
                txSt = _TxState;
            }

            SetState(rxSt, txSt);
        }
Beispiel #4
0
        public TlfNet GetNet(uint prefix, string number, ref StrNumeroAbonado altRoute)
        {
            string idEquipo;

            if (prefix == Cd40Cfg.ATS_DST)
            {
                ulong num;

                if (ulong.TryParse(number, out num))
                {
                    int centralId = -1;

                    foreach (NumeracionATS centralAts in _SystemCfg.PlanNumeracionATS)
                    {
                        bool foundCentralAts = false;
                        centralId++;

                        foreach (RangosSCV range in centralAts.RangosOperador)
                        {
                            if ((range.Inicial <= num) && (range.Final >= num))
                            {
                                if (!string.IsNullOrEmpty(range.IdAbonado))
                                {
                                    altRoute               = new StrNumeroAbonado();
                                    altRoute.Prefijo       = range.IdPrefijo;
                                    altRoute.NumeroAbonado = range.IdAbonado;
                                }

                                foundCentralAts = true;
                                break;
                            }
                        }

                        if (!foundCentralAts)
                        {
                            foreach (RangosSCV range in centralAts.RangosPrivilegiados)
                            {
                                if ((range.Inicial <= num) && (range.Final >= num))
                                {
                                    if (!string.IsNullOrEmpty(range.IdAbonado))
                                    {
                                        altRoute               = new StrNumeroAbonado();
                                        altRoute.Prefijo       = range.IdPrefijo;
                                        altRoute.NumeroAbonado = range.IdAbonado;
                                    }

                                    foundCentralAts = true;
                                    break;
                                }
                            }
                        }

                        if (foundCentralAts)
                        {
                            int    route = 0;
                            TlfNet net   = new TlfNet();
                            net.Id = "Net_ATS_" + centralId;

                            foreach (PlanRutas ruta in centralAts.ListaRutas)
                            {
                                // Primero van las rutas directas y luego el resto
                                route = (ruta.TipoRuta == "D") ? route : ++route;

                                foreach (string trunk in ruta.ListaTroncales)
                                {
                                    foreach (PlanRecursos recurso in _SystemCfg.GetTrunkResources(trunk))
                                    {
                                        Rs <GwTlfRs> rs   = Top.Registry.GetRs <GwTlfRs>(recurso.IdRecurso);
                                        string       rsIp = GetGwRsIp(recurso.IdRecurso, out idEquipo);
                                        SipLine      line = new SipLine(rs, rsIp);

                                        net.Lines.Add(line);
                                        net.RsTypes.Add(new RsIdxType(net.Lines.Count - 1, route, recurso.Tipo));
                                        net.Routes.Add(route);
                                    }
                                }
                            }

                            /*
                             *
                             *  Los recursos dentro de un troncal ya no se ordenan primero los de R2
                             *  y luego los de N-5 (tal y como se hizo para ACC). Se ordenan primero lado A
                             *  y luego lado B (Según Encamina (02/06) ).
                             *  Incidencia #2521
                             * net.RsTypes.Sort(delegate(RsIdxType a, RsIdxType b)
                             * {
                             *  if (a.ruta == b.ruta)
                             *      return a.TipoInteface - b.TipoInteface;
                             *  if (a.ruta < b.ruta)
                             *      return -1;
                             *
                             *  return 1;
                             * });
                             */
                            return(net);
                        }
                    }
                    //Devuelve una red vacía si no lo encuentra en la configuración
                    _Logger.Info("Linea no encontrada para prefijo {0} {1}", prefix, number);
                    TlfNet emptyNet = new TlfNet();
                    emptyNet.Id = "Net_ATS_" + centralId;
                    return(emptyNet);
                }
            }
            // Por acceso indirecto, el prefijo PP
            // se comporta como un abonado con marcación
            else if (prefix == Cd40Cfg.PP_DST)
            {
                TlfNet       net = new TlfNet();
                Rs <GwTlfRs> rs  = null;
                net.Id = "Net_" + "SEGURIDAD";
                //Busca el equipo que le da servicio, pasarela o proxy
                string rsIp = GetGwRsIp(number, out idEquipo);
                if (idEquipo != null)
                {
                    rs = Top.Registry.GetRs <GwTlfRs>(number);
                }
                if (rs == null)
                {
                    //o nuestro proxy si es un teléfono IP no configurado
                    if ((rsIp == null) || (idEquipo == null))
                    {
                        rsIp = GetProxyIp(out idEquipo);
                        rs   = Top.Registry.GetRs <GwTlfRs>(idEquipo);
                    }
                    _Logger.Warn("Number not found in configurated resources {0}, use {1} instead", number, idEquipo);
                }
                //rs.Reset(null, new GwTlfRs());
                if (rs != null)
                {
                    _Logger.Debug("Resource found for {0}: {1}", number, rs.Id);

                    SipLine line = new SipLine(rs, rsIp);
                    net.Lines.Add(line);
                    net.Routes.Add(0);
                    net.RsTypes.Add(new RsIdxType(net.Lines.Count - 1, 0, TipoInterface.TI_BL));
                }
                else
                {
                    _Logger.Error("{0} not found in conf resources {0} and proxy not found either.", number, idEquipo);
                }
                return(net);
            }
            else if (prefix == Cd40Cfg.UNKNOWN_DST) //Destinos entrantes que no están configurados
            {
                TlfNet net = new TlfNet();
                net.Id = "Net_" + "SEGURIDAD";
                string rsIp = GetProxyIp(out idEquipo);
                if (rsIp != null)
                {
                    Rs <GwTlfRs> rs      = Top.Registry.GetRs <GwTlfRs>(idEquipo);
                    GwTlfRs      proxyRs = new GwTlfRs();
                    proxyRs.GwIp = rsIp;
                    rs.Reset(null, proxyRs);

                    SipLine line = new SipLine(rs, rsIp);
                    net.Lines.Add(line);
                    net.Routes.Add(0);
                    net.RsTypes.Add(new RsIdxType(net.Lines.Count - 1, 0, TipoInterface.TI_BL));

                    return(net);
                }
            }
            else if (prefix == Cd40Cfg.IP_DST)
            {
                TlfNet net = new TlfNet();
                net.Id = "Net_" + "SEGURIDAD";
                string rsIp = GetProxyIp(out idEquipo);
                if (rsIp != null)
                {
                    Rs <GwTlfRs> rs      = Top.Registry.GetRs <GwTlfRs>(idEquipo);
                    GwTlfRs      proxyRs = new GwTlfRs();
                    proxyRs.GwIp = rsIp;
                    rs.Reset(null, proxyRs);

                    SipLine line = new SipLine(rs, rsIp);
                    net.Lines.Add(line);
                    net.Routes.Add(0);
                    net.RsTypes.Add(new RsIdxType(net.Lines.Count - 1, 0, TipoInterface.TI_BL));

                    return(net);
                }
            }
            else
            {
                foreach (ListaRedes red in _SystemCfg.PlanRedes)
                {
                    if (red.Prefijo == prefix)
                    {
                        TlfNet net = new TlfNet();
                        net.Id = "Net_" + red.IdRed;

                        foreach (PlanRecursos recurso in red.ListaRecursos)
                        {
                            string       rsIp;
                            Rs <GwTlfRs> rs = Top.Registry.GetRs <GwTlfRs>(recurso.IdRecurso);
                            rsIp = GetGwRsIp(recurso.IdRecurso, out idEquipo);
                            SipLine line = new SipLine(rs, rsIp);

                            net.Lines.Add(line);
                            net.RsTypes.Add(new RsIdxType(net.Lines.Count - 1, altRoute != null ? 1000 : 0, TipoInterface.TI_AB));
                            // Si altRoute es distinto de null es que estamos obteniendo la red
                            // de salida alternativa para un numero ATS. Esta red sólo se tiene
                            // que usar cuando no podemos salir por la propia red ATS, por eso
                            // ponemos un valor elevado de ruta de modo que se coja en GetDetourPath
                            net.Routes.Add(altRoute != null ? 1000 : 0);
                        }

                        return(net);
                    }
                }
            }

            return(null);
        }