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 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))); }
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 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 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(); }
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 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(); }
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 s61850() { iedModel = ConfigFileParser.CreateModelFromConfigFile("model.cfg"); if (iedModel == null) { Console.WriteLine("SYSERR: No Valid DataModel Found!"); return; } config = new IedServerConfig(); config.ReportBufferSize = 100000; iedServer = new IedServer(iedModel, config); iedServer.Start(10102); Console.WriteLine("SYSLOG: Iec61850 Server is Listening on port 10103."); GC.Collect(); /*Console.WriteLine("Starting GOOSE subscriber..."); * * GooseReceiver receiver = new GooseReceiver(); * //\Device\NPF_{874C4A5F-2D90-42E8-AFD3-E76B65365490} * receiver.SetInterfaceId(@"0"); * * GooseSubscriber subscriber = new GooseSubscriber(@"BUSBAYCTRL/LLN0$GO$Control_DataSet"); * * subscriber.SetAppId(1000); * * subscriber.SetListener(gooseListener, null); * * receiver.AddSubscriber(subscriber); * * receiver.Start();*/ }
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"); TLSConfiguration tlsConfig = new TLSConfiguration(); tlsConfig.SetOwnCertificate(new X509Certificate2("server.cer")); tlsConfig.SetOwnKey("server-key.pem", null); // Add a CA certificate to check the certificate provided by the server - not required when ChainValidation == false tlsConfig.AddCACertificate(new X509Certificate2("root.cer")); // Check if the certificate is signed by a provided CA tlsConfig.ChainValidation = true; // Check that the shown server certificate is in the list of allowed certificates tlsConfig.AllowOnlyKnownCertificates = false; IedServer iedServer = new IedServer(iedModel, tlsConfig); iedServer.SetControlHandler(spcso1, delegate(ControlAction action, 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(); Console.WriteLine("Server started"); GC.Collect(); DataObject ggio1AnIn1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.AnIn1"); DataAttribute ggio1AnIn1magF = (DataAttribute)ggio1AnIn1.GetChild("mag.f"); DataAttribute ggio1AnIn1T = (DataAttribute)ggio1AnIn1.GetChild("t"); float floatVal = 1.0f; while (running) { floatVal += 1f; iedServer.UpdateTimestampAttributeValue(ggio1AnIn1T, new Timestamp(DateTime.Now)); iedServer.UpdateFloatAttributeValue(ggio1AnIn1magF, floatVal); Thread.Sleep(100); } iedServer.Stop(); Console.WriteLine("Server stopped"); iedServer.Destroy(); }
public void CreateModelFromFile() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); Assert.NotNull(iedModel); }
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"); IedServerConfig config = new IedServerConfig(); config.ReportBufferSize = 100000; IedServer iedServer = new IedServer(iedModel, config); iedServer.SetControlHandler(spcso1, delegate(ControlAction action, 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(); DataObject ggio1AnIn1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.AnIn1"); DataAttribute ggio1AnIn1magF = (DataAttribute)ggio1AnIn1.GetChild("mag.f"); DataAttribute ggio1AnIn1T = (DataAttribute)ggio1AnIn1.GetChild("t"); float floatVal = 1.0f; while (running) { floatVal += 1f; iedServer.UpdateTimestampAttributeValue(ggio1AnIn1T, new Timestamp(DateTime.Now)); iedServer.UpdateFloatAttributeValue(ggio1AnIn1magF, floatVal); Thread.Sleep(100); } iedServer.Stop(); Console.WriteLine("Server stopped"); iedServer.Destroy(); }
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; } iedModel.SetIedName("TestIED"); DataObject spcso1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO1"); IedServerConfig config = new IedServerConfig(); config.ReportBufferSize = 100000; IedServer iedServer = new IedServer(iedModel, config); iedServer.SetCheckHandler(spcso1, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test, bool interlockCheck) { Console.WriteLine("Received binary control command:"); Console.WriteLine(" ctlNum: " + action.GetCtlNum()); Console.WriteLine(" execution-time: " + action.GetControlTimeAsDataTimeOffset().ToString()); return(CheckHandlerResult.ACCEPTED); }, null); iedServer.SetControlHandler(spcso1, delegate(ControlAction action, object parameter, MmsValue ctlVal, bool test) { bool val = ctlVal.GetBoolean(); if (val) { Console.WriteLine("execute binary control command: on"); } else { Console.WriteLine("execute binary control command: off"); } return(ControlHandlerResult.OK); }, null); DataObject spcso2 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO2"); iedServer.SetSelectStateChangedHandler(spcso2, delegate(ControlAction action, object parameter, bool isSelected, SelectStateChangedReason reason) { DataObject cObj = action.GetControlObject(); Console.WriteLine("Control object " + cObj.GetObjectReference() + (isSelected ? " selected" : " unselected") + " reason: " + reason.ToString()); }, null); iedServer.Start(102); if (iedServer.IsRunning()) { Console.WriteLine("Server started"); GC.Collect(); DataObject ggio1AnIn1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.AnIn1"); DataAttribute ggio1AnIn1magF = (DataAttribute)ggio1AnIn1.GetChild("mag.f"); DataAttribute ggio1AnIn1T = (DataAttribute)ggio1AnIn1.GetChild("t"); float floatVal = 1.0f; while (running) { floatVal += 1f; iedServer.UpdateTimestampAttributeValue(ggio1AnIn1T, new Timestamp(DateTime.Now)); iedServer.UpdateFloatAttributeValue(ggio1AnIn1magF, floatVal); Thread.Sleep(100); } iedServer.Stop(); Console.WriteLine("Server stopped"); } else { Console.WriteLine("Failed to start server"); } iedServer.Destroy(); }
public static IedModel CreateFromFile(string filePath) { return(ConfigFileParser.CreateModelFromConfigFile(filePath)); }
public void CreateModelFromNonExistingFile() { IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("test.cfg"); Assert.IsNull(iedModel); }