public void Find8SlotsSameSize() { Topology t = new Topology(); t.AddDevice("D1"); t.AddDevice("D2"); t.AddConnection("C1", "D1", "D2", 80); t.AddLink("L1", "D1", "D2", 10); t.AddLink("L2", "D1", "D2", 10); t.AddLink("L3", "D1", "D2", 10); t.AddLink("L4", "D1", "D2", 10); t.AddLink("L5", "D1", "D2", 10); t.AddLink("L6", "D1", "D2", 10); t.AddLink("L7", "D1", "D2", 10); t.AddLink("L8", "D1", "D2", 10); t.AllocateLinksPaths(); t.AllocateSlots(); Assert.AreEqual(1, t.GetLink("L1").mainPath.Count); Assert.AreEqual(t.GetDevice("D1"), t.GetLink("L1").mainPath[0].source); Assert.AreEqual(t.GetDevice("D2"), t.GetLink("L1").mainPath[0].destination); Assert.AreEqual(8, t.GetConnection("C1").slots.Count); Assert.AreEqual(t.GetLink("L1"), t.GetConnection("C1").slots[0].slotOWner); Assert.AreEqual(t.GetLink("L2"), t.GetConnection("C1").slots[1].slotOWner); Assert.AreEqual(t.GetLink("L3"), t.GetConnection("C1").slots[2].slotOWner); Assert.AreEqual(t.GetLink("L4"), t.GetConnection("C1").slots[3].slotOWner); Assert.AreEqual(t.GetLink("L5"), t.GetConnection("C1").slots[4].slotOWner); Assert.AreEqual(t.GetLink("L6"), t.GetConnection("C1").slots[5].slotOWner); Assert.AreEqual(t.GetLink("L7"), t.GetConnection("C1").slots[6].slotOWner); Assert.AreEqual(t.GetLink("L8"), t.GetConnection("C1").slots[7].slotOWner); }
public void FixedSlotConstraintTest_complexCase() { Topology t = new Topology(); t.AddDevice("O1"); t.AddDevice("D1"); t.AddDevice("I1"); t.AddDevice("I2"); t.AddConnection("C1", "I1", "D1", 40); t.AddConnection("C2", "I2", "D1", 40); t.AddConnection("C3", "D1", "O1", 80); t.AddLink("L1", "I1", "O1", 10); t.AddLink("L2", "I2", "O1", 10); t.AddFixedSlotConstraint("L1", 3, 4); t.AddFixedSlotConstraint("L2", 3, 4); t.AllocateLinksPaths(); t.AllocateSlots(); Assert.AreEqual("L1", t.GetConnection("C3").slots[6].slotOWner.name); Assert.AreEqual("L2", t.GetConnection("C3").slots[7].slotOWner.name); }
public void FindPathWith2Sources() { Topology t = new Topology(); t.AddDevice("D1"); t.AddDevice("D2"); t.AddDevice("D3"); t.AddConnection("C1", "D1", "D3", 10); t.AddConnection("C2", "D2", "D3", 10); List<string> sources = new List<string>() { "D1", "D2" }; List<string> destinations = new List<string>() { "D3" }; t.AddLink("L1", sources, destinations, 10); t.AllocateLinksPaths(); }
public void FixedSlotConstraintTest() { Topology t = new Topology(); t.AddDevice("D1"); t.AddDevice("D2"); t.AddDevice("D3"); t.AddConnection("C1", "D1", "D2", 20); t.AddConnection("C2", "D2", "D3", 80); t.AddLink("L1", "D1", "D3", 10); t.AddFixedSlotConstraint("L1", 3, 4); t.AllocateLinksPaths(); t.AllocateSlots(); }
public void SimpleRoutingCalculation() { Topology t = new Topology(); t.AddDevice("D/I"); t.AddDevice("P/O"); t.AddDevice("RT/I"); t.AddDevice("RT/O"); t.AddConnection("C1", "D/I", "RT/I", 20); t.AddConnection("C2", "RT/I", "RT/O", 80); t.AddConnection("C3", "RT/O", "P/O", 40); t.AddLink("L1", "D/I", "P/O", 10); t.AddLink("L2", "D/I", "P/O", 10); t.AllocateLinksPaths(); t.AllocateSlots(); RoutingTable rt = t.CalculateRoutingTableForDevice("RT"); Assert.AreEqual(2, rt.routingEntities.Count); }
public static Topology CreateTopology(string fileName) { Topology t = new Topology(); bool readingDevices = false; bool readingLinks = false; string currDeviceKey = String.Empty; Dictionary<string, List<string>> devicesData = new Dictionary<string, List<string>>(); List<string[]> linksData = new List<string[]>(); using (StreamReader sr = new StreamReader(fileName)) { string line; while((line = sr.ReadLine()) != null) { if (line.Contains("ENDED PRINTING LOGICAL LINKS!")) { readingLinks = false; } if (line.Contains("FINISHED CONFIGURATION STRUCTURE PRINTING!")) { readingDevices = false; } if (readingDevices) { int cutTo = line.IndexOf("[Rp3Configuration::showConfigurationStructure]") + "[Rp3Configuration::showConfigurationStructure]".Length; string cutLine = line.Substring(cutTo); if (cutLine.EndsWith(":\t")) { currDeviceKey = cutLine.Substring(0, cutLine.Length - 3).TrimStart(new char[] { ' ', '\t' }); } else { if (!devicesData.ContainsKey(currDeviceKey)) { devicesData.Add(currDeviceKey, new List<string>()); } //add only uniqie - there is some bug in topology (fake rx are connected many times) string connectedDevice = cutLine.TrimStart(new char[] { ' ', '\t' }); if (!devicesData[currDeviceKey].Exists(x => x == connectedDevice)) devicesData[currDeviceKey].Add(connectedDevice); } } if (readingLinks) { //TODO: support for multi receiver/transmitter int cutTo = line.IndexOf("NF/CellP/BBConf,") + "NF/CellP/BBConf,".Length; string cutLine = line.Substring(cutTo); linksData.Add(cutLine.Split(new char[] { ';' })); } if (line.Contains("PRINTING LOGICAL LINKS:")) { readingLinks = true; linksData.Clear(); // so only last data will be taken } if (line.Contains("PRINTING CONFIGURATION STRUCTURE")) { readingDevices = true; devicesData.Clear(); // so only last data will be taken } } } //DEVICES SortedSet<string> devices = new SortedSet<string>(); foreach (var deviceData in devicesData) { string dev = GetName(deviceData.Key); devices.Add(dev); foreach (string value in deviceData.Value) { string dev2 = GetName(value); devices.Add(dev2); } } foreach (string dev in devices) { t.AddDevice(dev); } //CONNECTIONS int nextConnNo = 1; foreach (var deviceData in devicesData) { foreach (string value in deviceData.Value) { string fromDev = GetName(deviceData.Key); string toDev = GetName(value); t.AddConnection(nextConnNo.ToString(), fromDev, toDev, Math.Min(GetSpeed(deviceData.Key), GetSpeed(value)) * 10); nextConnNo++; } } //LOGICAL LINKS foreach (var linkData in linksData) { t.AddLink(linkData[0], linkData[2].Substring(1, linkData[2].Length - 2), linkData[1].Substring(1, linkData[1].Length - 2), Convert.ToInt32(linkData[3])); } return t; }
public void SlotAllocationWithMultiplexing_ComplexCase() { Topology t = new Topology(); t.AddDevice("O1"); t.AddDevice("O2"); t.AddDevice("O3"); t.AddDevice("O4"); t.AddDevice("D1"); t.AddDevice("I1"); t.AddConnection("C1", "D1", "O1", 10); t.AddConnection("C2", "D1", "O2", 40); t.AddConnection("C3", "D1", "O3", 20); t.AddConnection("C4", "D1", "O4", 10); t.AddConnection("C5", "I1", "D1", 80); t.AddLink("L1", "I1", "O1", 10); t.AddLink("L2", "I1", "O2", 20); t.AddLink("L3", "I1", "O2", 10); t.AddLink("L4", "I1", "O2", 10); t.AddLink("L5", "I1", "O3", 5); t.AddLink("L6", "I1", "O3", 5); t.AddLink("L7", "I1", "O3", 10); t.AddLink("L8", "I1", "O4", 5); t.AddLink("L9", "I1", "O4", 5); t.AllocateLinksPaths(); t.AllocateSlots(); }
public void SlotAllocationWithMultiplexing() { Topology t = new Topology(); t.AddDevice("D1"); t.AddDevice("D2"); t.AddDevice("D3"); t.AddDevice("D4"); t.AddConnection("C1", "D1", "D2", 20); t.AddConnection("C2", "D2", "D3", 10); t.AddConnection("C3", "D2", "D4", 10); t.AddLink("L1", "D1", "D3", 10); t.AddLink("L2", "D1", "D4", 10); t.AllocateLinksPaths(); t.AllocateSlots(); }
public void SlotAllocationWithDemultiplexing_EvenMoreComplexCase() { Topology t = new Topology(); t.AddDevice("D1"); t.AddDevice("D2"); t.AddDevice("D3"); t.AddDevice("D4"); t.AddConnection("C1", "D1", "D3", 40); t.AddConnection("C2", "D2", "D3", 10); t.AddConnection("C3", "D3", "D4", 80); t.AddLink("L1", "D1", "D4", 10); t.AddLink("L2", "D1", "D4", 20); t.AddLink("L3", "D1", "D4", 10); t.AddLink("L4", "D2", "D4", 10); t.AllocateLinksPaths(); t.AllocateSlots(); }
public void SimpleSlotFind() { Topology t = new Topology(); t.AddDevice("D1"); t.AddDevice("D2"); t.AddConnection("C1", "D1", "D2", 10); t.AddLink("L1", "D1", "D2", 10); t.AllocateLinksPaths(); t.AllocateSlots(); Assert.AreEqual(1, t.GetLink("L1").mainPath.Count); Assert.AreEqual(t.GetDevice("D1"), t.GetLink("L1").mainPath[0].source); Assert.AreEqual(t.GetDevice("D2"), t.GetLink("L1").mainPath[0].destination); Assert.AreEqual(1, t.GetConnection("C1").slots.Count); Assert.AreEqual(t.GetLink("L1"), t.GetConnection("C1").slots[0].slotOWner); }
public void PathAllocationNeedsSorting() { Topology t = new Topology(); t.AddDevice("D1"); t.AddDevice("D2"); t.AddDevice("D3"); t.AddConnection("C1", "D1", "D2", 20); t.AddConnection("C2", "D1", "D3", 10); t.AddConnection("C3", "D3", "D2", 10); t.AddLink("L1", "D1", "D2", 10); t.AddLink("L2", "D1", "D2", 20); t.AllocateLinksPaths(); t.AllocateSlots(); //ASSERIONS NOT NEEDED - NO EXCEPTION SHOULD BE ENOUGH! }
public void TwoWayPathFind() { Topology t = new Topology(); t.AddDevice("D1"); t.AddDevice("D2"); t.AddConnection("C1", "D1", "D2", 10); t.AddConnection("C2", "D2", "D1", 10); t.AddLink("L1", "D1", "D2", 10); t.AddLink("L2", "D2", "D1", 10); t.AllocateLinksPaths(); Assert.AreEqual(1, t.GetLink("L1").mainPath.Count); Assert.AreEqual(t.GetDevice("D1"), t.GetLink("L1").mainPath[0].source); Assert.AreEqual(t.GetDevice("D2"), t.GetLink("L1").mainPath[0].destination); Assert.AreEqual(1, t.GetLink("L2").mainPath.Count); Assert.AreEqual(t.GetDevice("D2"), t.GetLink("L2").mainPath[0].source); Assert.AreEqual(t.GetDevice("D1"), t.GetLink("L2").mainPath[0].destination); }
public void TolopogyCreation() { Topology t = new Topology(); t.AddDevice("D1"); t.AddDevice("D2"); t.AddConnection("C1", "D1", "D2", 10); t.AddLink("L1", "D1", "D2", 10); }
public void ForbiddenSlotConstraintTest() { Topology t = new Topology(); t.AddDevice("D1"); t.AddDevice("D2"); t.AddConnection("C1", "D1", "D2", 20); t.AddLink("L1", "D1", "D2", 10); t.AddForbiddenSlotConstraint("Constraint-1", "D1", 0, 2); t.AllocateLinksPaths(); t.AllocateSlots(); Assert.AreEqual(1, t.GetLink("L1").mainPath.Count); Assert.AreEqual(t.GetDevice("D1"), t.GetLink("L1").mainPath[0].source); Assert.AreEqual(t.GetDevice("D2"), t.GetLink("L1").mainPath[0].destination); Assert.AreEqual(2, t.GetConnection("C1").slots.Count); Assert.AreEqual(Slot.State.FORBIDDEN, t.GetConnection("C1").slots[0].state); Assert.AreEqual("Constraint-1", t.GetConnection("C1").slots[0].constraintName); Assert.AreEqual(Slot.State.TAKEN, t.GetConnection("C1").slots[1].state); Assert.AreEqual(t.GetLink("L1"), t.GetConnection("C1").slots[1].slotOWner); }