public LSP(int idProyecto, int idLSP) { //Lee los datos de la tabla de LSP_Header Data.dsTopologiaTableAdapters.LSPsTableAdapter HeaderAdapter = new Data.dsTopologiaTableAdapters.LSPsTableAdapter(); Data.dsTopologia.LSPsDataTable hdt = HeaderAdapter.SeleccionarListaLSPs(idProyecto, idLSP); foreach(var dr in hdt) { this.idProyecto = dr.idProyecto; this.idLSP = dr.idLSP; if (!dr.IscNombreNull()) this.cNombre = dr.cNombre.Trim(); if (!dr.IsnBandwidthNull()) this.nBandwidth = dr.nBandwidth; this.idRouterOrigen = dr.idRouterOrigen; this.idRouterDestino = dr.idRouterDestino; if (!dr.IsnSetupPriorityNull()) this.nSetupPriority = dr.nSetupPriority; if (!dr.IsnHoldPriorityNull()) this.nHoldPriority = dr.nHoldPriority; } //Agrega router_origen al stack de nodos Stack<Router> stackNodos = new Stack<Router>(); stackNodos.Push(new LER(this.idRouterOrigen, this.idProyecto)); //Bucle que agrega los routers de la lista de enlaces Data.dsTopologiaTableAdapters.EnlacesLSPsTableAdapter DetailAdapter = new Data.dsTopologiaTableAdapters.EnlacesLSPsTableAdapter(); Data.dsTopologia.EnlacesLSPsDataTable ddt = DetailAdapter.SeleccionarListaEnlacesLSPs(idProyecto, idLSP); foreach(var dr in ddt) { Enlace temp = new Enlace(dr.idLSP, dr.idProyecto); Router lastNode = stackNodos.Peek(); //Agrega el router asociado al enlace que no esta en el tope del stack if (lastNode.idRouter != temp.idRouterA) stackNodos.Push(new LSR(temp.idRouterA, this.idProyecto)); else stackNodos.Push(new LSR(temp.idRouterB, this.idProyecto)); } //Finalmente, agrega router_destino al stack de nodos stackNodos.Push(new LER(this.idRouterDestino, this.idProyecto)); //Convierte el stack a una lista this.listaNodos = stackNodos.ToList(); //Populando los selectlists this.listaNodosOrigen = LSP.ConvertDropdownNodosDisponibles(LSP.SelectListaNodosDisponibles(idProyecto, null, 0)); this.listaNextHop = new List<SelectListItem>(); }
public EnlaceJson(int idProyecto, int idEnlace) { Enlace temp = new Enlace(idEnlace, idProyecto); this.idEnlace = temp.idEnlace; this.name = temp.cNombre; this.from = temp.idRouterA; this.to = temp.idRouterB; this.toArrow = ""; this.total_bw = temp.nBandwidth; this.weight = temp.nPesoAdministrativo; this.afinity = temp.idAfinidad; this.free_bw = temp.nBandwidthDisponible; this.id_proyecto = temp.idProyecto; }
public ActionResult selectNombresRouters(int idEnlace, int idProyecto) { Enlace e = new Enlace(idEnlace, idProyecto); var idRouterA = e.idRouterA; var idRouterB = e.idRouterB; Router routerA = new LSR(idRouterA, idProyecto); Router routerB = new LSR(idRouterB, idProyecto); return Json(new { nombreRouterA = routerA.cHostname, nombreRouterB = routerB.cHostname }, JsonRequestBehavior.AllowGet); }
/// <summary> /// Genera una lista de routers y enlaces en base a los contenidos de la tabla CSV /// </summary> /// <param name="tablaDatos"></param> public void GenerarTopologia(List<Tabla> tablaDatos) { tablaDatos = tablaDatos.GroupBy(x => x.Hostname).Select(x => x.First()).ToList(); List<Router> listaRouters = new List<Router>(); List<Enlace> listaEnlaces = new List<Enlace>(); Dictionary<string, int> routerIDs = new Dictionary<string, int>(); for(int i = 0; i < tablaDatos.Count; ++i) { LSR temp = new LSR(); temp.idRouter = i + 1; temp.cHostname = tablaDatos[i].Hostname; temp.cRouterID = tablaDatos[i].OSPFRouterID.Trim(); temp.listaEnlaces = new List<Enlace>(); routerIDs.Add(temp.cRouterID, temp.idRouter); listaRouters.Add(temp); } foreach(var item in tablaDatos) { var values = item.OSPFNeighborRouterID.Split(','); foreach(var value in values) { Enlace temp = new Enlace(); int thisID = routerIDs[item.OSPFRouterID.Trim()]; int otherID = routerIDs[value.Trim()]; if (thisID < otherID) { temp.idRouterA = thisID; temp.idRouterB = otherID; listaRouters[thisID - 1].listaEnlaces.Add(temp); listaEnlaces.Add(temp); } else if (thisID > otherID) { temp.idRouterA = otherID; temp.idRouterB = thisID; listaRouters[thisID - 1].listaEnlaces.Add(temp); listaEnlaces.Add(temp); } } } listaEnlaces = listaEnlaces.GroupBy(d => new { d.idRouterA, d.idRouterB }) .Select(d => d.First()) .ToList(); for(int i = 0; i < listaEnlaces.Count; ++i) { listaEnlaces[i].idEnlace = i + 1; } this.listadoRouters = listaRouters; this.listadoEnlaces = listaEnlaces; this.InsertUpdateListaRouters(); this.InsertUpdateListaEnlaces(); }
/// <summary> /// Retorna el listado de enlaces en la topologĂa de un proyecto /// </summary> /// <param name="idProyecto"></param> /// <returns></returns> public static List<Enlace> SelectListaEnlaces(int idProyecto) { List<Enlace> listaEnlaces = new List<Enlace>(); Data.dsTopologiaTableAdapters.EnlacesTableAdapter Adapter = new Data.dsTopologiaTableAdapters.EnlacesTableAdapter(); Data.dsTopologia.EnlacesDataTable dt = Adapter.SelectEnlacesProyecto(idProyecto); foreach (var dr in dt) { Enlace temp = new Enlace(); temp.idEnlace = dr.idEnlace; temp.idProyecto = dr.idProyecto; if (!dr.IscNombreNull()) temp.cNombre = dr.cNombre.Trim(); if (!dr.IsidRouterANull()) temp.idRouterA = dr.idRouterA; if (!dr.IsidRouterBNull()) temp.idRouterB = dr.idRouterB; if (!dr.IsnBandwidthNull()) temp.nBandwidth = dr.nBandwidth; if (!dr.IsnPesoAdministrativoNull()) temp.nPesoAdministrativo = dr.nPesoAdministrativo; if (!dr.IscAfinidadNull()) temp.idAfinidad = dr.idAfinidad; listaEnlaces.Add(temp); } return listaEnlaces; }
/// <summary> /// Convierte desde el formato de Json al de modelo de Enlaces /// </summary> /// <param name="list"></param> /// <param name="idProyecto"></param> /// <returns></returns> public static List<Enlace> ToModeList(this List<EnlaceJson> list) { List<Enlace> listaEnlaces = new List<Enlace>(); foreach (var item in list) { Enlace temp = new Enlace(); temp.idEnlace = item.idEnlace; temp.idProyecto = item.id_proyecto; temp.cNombre = item.name; temp.idRouterA = item.from; temp.idRouterB = item.to; temp.nBandwidth = item.total_bw; temp.nPesoAdministrativo = item.weight; temp.idAfinidad = item.afinity; temp.nBandwidthDisponible = item.free_bw; listaEnlaces.Add(temp); } return listaEnlaces; }