public void ShouldHandleEmptyString() { var parser = new ConfigFileParser(new ScriptConsole()); var result = parser.Parse(""); result.ShouldBeNull(); }
/// <summary> /// Checks if the runtime of an allocation exceeds the maximum program duration /// </summary> /// <returns> /// An empty string if the runtime is valid, /// an error message if invalid /// </returns> /// <param name="configFileContent">Content of a configuration file</param> /// <param name="allocationRuntime">Runtime of an allocation</param> public static string IsAllocationRuntimeValid(string configFileContent, float allocationRuntime) { string errorMsg = "Runtime of the given allocation exceeds maximum duration of the program."; float maxDuration = ConfigFileParser.GetMaximumDuration(configFileContent); return(allocationRuntime <= maxDuration ? "" : errorMsg); }
public void AccessDataModelServerSideNavigateModelNode() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); ModelNode modelNode = iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.AnIn1"); Assert.IsNotNull(modelNode); Assert.IsTrue(modelNode.GetType().Equals(typeof(DataObject))); var children = modelNode.GetChildren(); Assert.AreEqual(3, children.Count); ModelNode mag = children.First.Value; Assert.AreEqual("mag", mag.GetName()); ModelNode t = children.Last.Value; Assert.AreEqual("t", t.GetName()); //modelNode = iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.AnIn1.mag.f"); //Assert.IsTrue(modelNode.GetType().Equals(typeof(IEC61850.Server.DataAttribute))); }
/// <summary> /// Computes the runtime of an allocation /// </summary> /// <returns> /// The runtime of an allocation /// </returns> /// <param name="configFileContent">Content of a configuration file</param> /// <param name="allocation">A single allocation of tasks on processors</param> public static float GetAllocationRuntime(string configFileContent, List <List <bool> > allocation) { List <float> processorFrequencies = ConfigFileParser.GetProcessorFrequencies(configFileContent); List <float> taskRuntimes = ConfigFileParser.GetTaskRuntimes(configFileContent); float runtimeReferenceFrequency = ConfigFileParser.GetRuntimeReferenceFrequency(configFileContent); float allocationRuntime = 0; if (processorFrequencies.Count == 0 || taskRuntimes.Count == 0 || allocation.Count == 0 || runtimeReferenceFrequency == -1) { return(-1); } else { for (int processorId = 0; processorId < allocation.Count; processorId++) { float processorRuntime = 0; for (int taskId = 0; taskId < allocation[processorId].Count; taskId++) { if (allocation[processorId][taskId]) { processorRuntime += GetTaskRuntime(runtimeReferenceFrequency, taskRuntimes[taskId], processorFrequencies[processorId]); } } if (processorRuntime >= allocationRuntime) { allocationRuntime = processorRuntime; } } return(allocationRuntime); } }
public void AccessDataModelClientServer() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); ModelNode ind1 = iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.Ind1.stVal"); Assert.IsTrue(ind1.GetType().Equals(typeof(IEC61850.Server.DataAttribute))); IedServer iedServer = new IedServer(iedModel); iedServer.Start(10002); iedServer.UpdateBooleanAttributeValue((IEC61850.Server.DataAttribute)ind1, true); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); bool stVal = connection.ReadBooleanValue("simpleIOGenericIO/GGIO1.Ind1.stVal", FunctionalConstraint.ST); Assert.IsTrue(stVal); iedServer.UpdateBooleanAttributeValue((IEC61850.Server.DataAttribute)ind1, false); stVal = connection.ReadBooleanValue("simpleIOGenericIO/GGIO1.Ind1.stVal", FunctionalConstraint.ST); Assert.IsFalse(stVal); connection.Abort(); iedServer.Stop(); iedServer.Destroy(); }
public void CanParseEvenIfNoService() { var parser = new ConfigFileParser(Path.Combine(TestContext.DeploymentDirectory, "NoService.config")); var output = parser.Analyze(); Assert.IsTrue(output.IsSuccess); }
private void Load() { if (string.IsNullOrEmpty(Path.GetFileName(_fileName)) || !File.Exists(_fileName)) return; ConfigFileParser parser = new ConfigFileParser(this); parser.Parse(); }
public void CanDetectBindingMismatch() { var parser = new ConfigFileParser(Path.Combine(TestContext.DeploymentDirectory, "BindingMismatch.config")); var output = parser.Analyze(); Assert.IsTrue(output.IsFailure); }
public ConfigFile(string configFileContent) { this.content = configFileContent; this.maxDuration = ConfigFileParser.GetMaximumDuration(configFileContent); this.refFrequency = ConfigFileParser.GetRuntimeReferenceFrequency(configFileContent); this.tasks = ConfigFileParser.GetTasks(configFileContent); this.processors = ConfigFileParser.GetProcessors(configFileContent); this.coefficients = ConfigFileParser.GetCoefficients(configFileContent); }
/// <summary> /// Constructor /// </summary> /// <param name="filepath">Path of the file, for manual file creation, leave empty here</param> public ConfigFile(string filepath) { FilePath = filepath; if (filepath == null || filepath == "") { return; } ConfigFileParser parser = new ConfigFileParser(this); parser.readConfigFile(filepath); }
public void ControlWriteAccessToServer() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); IEC61850.Server.DataAttribute opDlTmms = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/PDUP1.OpDlTmms.setVal"); IEC61850.Server.DataAttribute rsDlTmms = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/PDUP1.RsDlTmms.setVal"); IedServer iedServer = new IedServer(iedModel); int opDlTmmsValue = 0; iedServer.HandleWriteAccess(opDlTmms, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) { opDlTmmsValue = value.ToInt32(); return(MmsDataAccessError.SUCCESS); }, null); iedServer.HandleWriteAccess(rsDlTmms, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) { if (value.ToInt32() > 1000) { return(MmsDataAccessError.OBJECT_VALUE_INVALID); } else { return(MmsDataAccessError.SUCCESS); } }, null); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); connection.WriteValue("simpleIOGenericIO/PDUP1.OpDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234)); try { connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234)); } catch (IedConnectionException e) { Assert.AreEqual(IedClientError.IED_ERROR_OBJECT_VALUE_INVALID, e.GetIedClientError()); } connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)999)); MmsValue rsDlTmmsValue = iedServer.GetAttributeValue(rsDlTmms); Assert.AreEqual(999, rsDlTmmsValue.ToInt32()); connection.Abort(); iedServer.Stop(); Assert.AreEqual((int)1234, opDlTmmsValue); iedServer.Destroy(); }
public void ShouldHandleConfigMalformedConfig() { const string file = "{\"Install\": \"install "; var parser = new ConfigFileParser(new ScriptConsole()); var result = parser.Parse(file); result.ShouldBeNull(); }
private void Load() { if (string.IsNullOrEmpty(Path.GetFileName(FileName)) || !File.Exists(FileName)) { return; } ConfigFileParser parser = new ConfigFileParser(this); parser.Parse(); }
public void ShouldHandleConfigFile() { const string file = "{\"Install\": \"install test value\", \"script\": \"server.csx\" }"; var parser = new ConfigFileParser(new ScriptConsole()); var result = parser.Parse(file); result.ShouldNotBeNull(); result.ScriptName.ShouldEqual("server.csx"); result.Install.ShouldEqual("install test value"); }
public void ShouldHanldeArgumentTypeConversionBool() { const string file = "{\"Install\": \"install test value\", \"script\": \"server.csx\", \"cache\": \"true\" }"; var parser = new ConfigFileParser(new ScriptConsole()); var result = parser.Parse(file); result.ShouldNotBeNull(); result.ScriptName.ShouldEqual("server.csx"); result.Install.ShouldEqual("install test value"); result.Cache.ShouldEqual(true); }
static void Main(string[] args) { Logger.Instance.Verbose = true; Dictionary <ArgumentKey, object> arguments; Logger.Instance.Info("Starting Routing Daemon..."); try { // Load arguments arguments = ArgumentsParser.GetArguments(args); } catch { Logger.Instance.Error("Invalid arguments"); return; } // Set the local node ID. DaemonBackEnd.Instance.LocalNode.NodeID = (int)arguments[ArgumentKey.NodeID]; List <NodeConfiguration> config; try { // Load configuration file. config = ConfigFileParser.LoadConfigurationFromPath((string)arguments[ArgumentKey.ConfigFilePath]); } catch { return; } Logger.Instance.Debug("Loaded configuration file"); // Configure all the neighbors of the local node DaemonBackEnd.Instance.ConfigureLocalNode(config); RoutingDaemon1 daemon = new RoutingDaemon1( DaemonBackEnd.Instance.LocalNode.Configuration.RoutingPort, DaemonBackEnd.Instance.LocalNode.Configuration.LocalPort ); // Start the daemon daemon.Start(); Logger.Instance.Info("Daemon Started Successfully"); // Infinite Loop till the application exits. while (true) { System.Threading.Thread.Sleep(100000); } }
public void ConnectionHandler() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); int handlerCalled = 0; int connectionCount = 0; IedServer iedServer = new IedServer(iedModel); string ipAddress = null; iedServer.SetConnectionIndicationHandler(delegate(IedServer server, ClientConnection clientConnection, bool connected, object parameter) { handlerCalled++; if (connected) { connectionCount++; } else { connectionCount--; } ipAddress = clientConnection.GetPeerAddress(); }, null); iedServer.Start(10002); IedConnection con1 = new IedConnection(); con1.Connect("localhost", 10002); Assert.AreEqual(1, handlerCalled); Assert.AreEqual(1, connectionCount); IedConnection con2 = new IedConnection(); con2.Connect("localhost", 10002); Assert.AreEqual(2, handlerCalled); Assert.AreEqual(2, connectionCount); con1.Abort(); con2.Abort(); Assert.AreEqual(4, handlerCalled); Assert.AreEqual(0, connectionCount); Assert.AreEqual("127.0.0.1:", ipAddress.Substring(0, 10)); iedServer.Stop(); iedServer.Dispose(); }
public static void Main(string[] args) { bool running = true; /* run until Ctrl-C is pressed */ Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; running = false; }; IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); if (iedModel == null) { Console.WriteLine("No valid data model found!"); return; } DataObject spcso1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO1"); IedServer iedServer = new IedServer(iedModel); iedServer.SetControlHandler(spcso1, delegate(DataObject controlObject, object parameter, MmsValue ctlVal, bool test) { bool val = ctlVal.GetBoolean(); if (val) { Console.WriteLine("received binary control command: on"); } else { Console.WriteLine("received binary control command: off"); } return(ControlHandlerResult.OK); }, null); iedServer.Start(102); Console.WriteLine("Server started"); GC.Collect(); while (running) { Thread.Sleep(1); } iedServer.Stop(); Console.WriteLine("Server stopped"); iedServer.Destroy(); }
public void ControlWriteAccessComplexDAToServer() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model2.cfg"); IEC61850.Server.DataAttribute setAnVal_setMag = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/LLN0.SetAnVal.setMag"); IedServer iedServer = new IedServer(iedModel); int handlerCalled = 0; MmsValue receivedValue = null; iedServer.SetWriteAccessPolicy(FunctionalConstraint.SP, AccessPolicy.ACCESS_POLICY_DENY); iedServer.HandleWriteAccessForComplexAttribute(setAnVal_setMag, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) { receivedValue = value; handlerCalled++; return(MmsDataAccessError.SUCCESS); }, null); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); MmsValue complexValue = MmsValue.NewEmptyStructure(1); complexValue.SetElement(0, new MmsValue((float)1.0)); connection.WriteValue("simpleIOGenericIO/LLN0.SetAnVal.setMag", FunctionalConstraint.SP, complexValue); Assert.NotNull(receivedValue); Assert.AreEqual(MmsType.MMS_STRUCTURE, receivedValue.GetType()); Assert.AreEqual(1.0, receivedValue.GetElement(0).ToFloat()); receivedValue.Dispose(); receivedValue = null; connection.WriteValue("simpleIOGenericIO/LLN0.SetAnVal.setMag.f", FunctionalConstraint.SP, new MmsValue((float)2.0)); Assert.NotNull(receivedValue); Assert.AreEqual(MmsType.MMS_FLOAT, receivedValue.GetType()); Assert.AreEqual(2.0, receivedValue.ToFloat()); connection.Abort(); iedServer.Stop(); iedServer.Dispose(); }
// parse the configuration file return the root or // null if error. protected ConfigElement ParseConfiguration(bool toPrint) { ConfigElement root = null; root = ConfigFileParser.parseFile(configFile); if (root != null && toPrint) { System.Text.StringBuilder tree = new System.Text.StringBuilder(); ConfigFileParser.printConfigurationTree(root, tree, 0); System.Console.WriteLine(tree); } return(root); }
public void ShouldHandleConfigArgumentsCaseInsensitive() { const string file = "{\"Install\": \"install test value\", \"script\": \"server.csx\", \"cache\": \"tRUe\", \"logLEVEL\": \"TRaCE\" }"; var parser = new ConfigFileParser(new ScriptConsole()); var result = parser.Parse(file); result.ShouldNotBeNull(); result.ScriptName.ShouldEqual("server.csx"); result.Install.ShouldEqual("install test value"); result.Cache.ShouldEqual(true); result.LogLevel.ShouldEqual(LogLevel.Trace); }
public void ShouldHanldeArgumentTypeConversionEnum() { const string file = "{\"Install\": \"install test value\", \"script\": \"server.csx\", \"inMemory\": \"true\", \"log\": \"error\" }"; var parser = new ConfigFileParser(new ScriptConsole()); var result = parser.Parse(file); result.ShouldNotBeNull(); result.ScriptName.ShouldEqual("server.csx"); result.Install.ShouldEqual("install test value"); result.InMemory.ShouldEqual(true); result.LogLevel.ShouldEqual(LogLevel.Error); }
public void AccessDataModelServerSide() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); ModelNode modelNode = iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.AnIn1"); Assert.IsTrue(modelNode.GetType().Equals(typeof(DataObject))); modelNode = iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.AnIn1.mag.f"); Assert.IsTrue(modelNode.GetType().Equals(typeof(IEC61850.Server.DataAttribute))); Assert.IsNotNull(modelNode); }
public void ControlHandler() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); DataObject spcso1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO1"); Assert.IsNotNull(spcso1); int handlerCalled = 0; IedServer iedServer = new IedServer(iedModel); iedServer.SetControlHandler(spcso1, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test) { byte [] orIdent = action.GetOrIdent(); string orIdentStr = System.Text.Encoding.UTF8.GetString(orIdent, 0, orIdent.Length); Assert.AreEqual("TEST1234", orIdentStr); Assert.AreEqual(OrCat.MAINTENANCE, action.GetOrCat()); Assert.AreSame(spcso1, action.GetControlObject()); handlerCalled++; return(ControlHandlerResult.OK); }, null); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); ControlObject controlClient = connection.CreateControlObject("simpleIOGenericIO/GGIO1.SPCSO1"); controlClient.SetOrigin("TEST1234", OrCat.MAINTENANCE); Assert.IsNotNull(controlClient); controlClient.Operate(true); connection.Abort(); Assert.AreEqual(1, handlerCalled); iedServer.Stop(); iedServer.Destroy(); }
public s61850(ILogger <s61850> logger, IServiceScopeFactory scopeFactory, IHubContext <SignalRHub, IHub> hub) { _logger = logger; _scopeFactory = scopeFactory; _hub = hub; iedModel = ConfigFileParser.CreateModelFromConfigFile("model.cfg"); if (iedModel == null) { _logger.LogError("SYSERR: No Valid DataModel Found!"); return; } config = new IedServerConfig(); config.ReportBufferSize = 100000; iedServer = new IedServer(iedModel, config); }
public void WriteAccessPolicy() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); IEC61850.Server.DataAttribute opDlTmms = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/PDUP1.OpDlTmms.setVal"); IEC61850.Server.DataAttribute rsDlTmms = (IEC61850.Server.DataAttribute)iedModel.GetModelNodeByShortObjectReference("GenericIO/PDUP1.RsDlTmms.setVal"); IedServer iedServer = new IedServer(iedModel); iedServer.HandleWriteAccess(opDlTmms, delegate(IEC61850.Server.DataAttribute dataAttr, MmsValue value, ClientConnection con, object parameter) { return(MmsDataAccessError.SUCCESS); }, null); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); iedServer.SetWriteAccessPolicy(FunctionalConstraint.SP, AccessPolicy.ACCESS_POLICY_ALLOW); connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234)); iedServer.SetWriteAccessPolicy(FunctionalConstraint.SP, AccessPolicy.ACCESS_POLICY_DENY); connection.WriteValue("simpleIOGenericIO/PDUP1.OpDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)1234)); try { connection.WriteValue("simpleIOGenericIO/PDUP1.RsDlTmms.setVal", FunctionalConstraint.SP, new MmsValue((int)999)); } catch (IedConnectionException e) { Assert.AreEqual(IedClientError.IED_ERROR_ACCESS_DENIED, e.GetIedClientError()); } MmsValue rsDlTmmsValue = iedServer.GetAttributeValue(rsDlTmms); Assert.AreEqual(1234, rsDlTmmsValue.ToInt32()); connection.Abort(); iedServer.Stop(); iedServer.Dispose(); }
public void StartStopSimpleServer() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); IedServer iedServer = new IedServer(iedModel); Assert.NotNull(iedServer); iedServer.Start(10002); Assert.IsTrue(iedServer.IsRunning()); iedServer.Stop(); Assert.IsFalse(iedServer.IsRunning()); iedServer.Destroy(); }
/// <summary> /// Checks if a provided configuration file contains frequencies of processors /// </summary> /// <returns> /// An empty string if it is valid, /// an error message if invalid /// </returns> /// <param name="configFileContent">Content of a configuration file</param> public static string ContainsProcessorFrequencies(string configFileContent) { List <float> processorFrequencies = ConfigFileParser.GetProcessorFrequencies(configFileContent); List <string> processorIds = ConfigFileParser.GetProcessorIds(configFileContent); if (processorFrequencies.Count == 0 || processorIds.Count == 0 || processorFrequencies.Count != processorIds.Count) { return(ConfigErrors["ProcessorFrequencies"]); } else { // check if processor ids are unique if (processorIds.Distinct().Count() != processorIds.Count) { return(ConfigErrors["ProcessorFrequenciesIds"]); } return(""); } }
public void ReadNonExistingObject() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); IedServer iedServer = new IedServer(iedModel); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); MmsValue value = connection.ReadValue("simpleIOGenericIO/GGIO1.SPCSO1.stVal", FunctionalConstraint.MX); Assert.IsNotNull(value); Assert.AreEqual(MmsType.MMS_DATA_ACCESS_ERROR, value.GetType()); iedServer.Stop(); iedServer.Destroy(); }
public void ConnectToServer() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); IedServer iedServer = new IedServer(iedModel); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); List <string> list = connection.GetServerDirectory(); Assert.IsNotEmpty(list); Assert.AreEqual(list.ToArray() [0], "simpleIOGenericIO"); iedServer.Stop(); iedServer.Destroy(); }
public void ControlHandler() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); DataObject spcso1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO1"); Assert.IsNotNull(spcso1); int handlerCalled = 0; IedServer iedServer = new IedServer(iedModel); iedServer.SetControlHandler(spcso1, delegate(DataObject controlObject, object parameter, MmsValue ctlVal, bool test) { handlerCalled++; return(ControlHandlerResult.OK); }, null); iedServer.Start(10002); IedConnection connection = new IedConnection(); connection.Connect("localhost", 10002); ControlObject controlClient = connection.CreateControlObject("simpleIOGenericIO/GGIO1.SPCSO1"); Assert.IsNotNull(controlClient); controlClient.Operate(true); connection.Abort(); Assert.AreEqual(1, handlerCalled); iedServer.Stop(); iedServer.Destroy(); }
public void LoadFromString(string str) { ConfigFileParser parser = new ConfigFileParser(this); parser.Parse(str); }