예제 #1
0
        internal static string[] InteractionList(IModule policy, HlaObjectNode hlaObjectTree)
        {
            // interactionList is a simple list of fully qualified interaction names
            List <string> interactionList = new List <string>();

            // Logic: We need to get a list of interactions (no parameters):

            if (policy.GetType() == typeof(ModuleExport))
            {
                ModuleExport exportPolicy = (ModuleExport)policy;
                foreach (Source source in exportPolicy.Sources)
                {
                    // Find the interactons, add if not already there
                    foreach (HlaInteraction inter in source.Interactions)
                    {
                        if (!interactionList.Contains(inter.InteractionClassName))
                        {
                            interactionList.Add(inter.InteractionClassName);
                        }
                    }
                }
            }
            else
            {
                ModuleImport importPolicy = (ModuleImport)policy;
                // Find the interactons, add if not already there
                foreach (HlaInteraction inter in importPolicy.Interactions)
                {
                    if (!interactionList.Contains(inter.InteractionClassName))
                    {
                        interactionList.Add(inter.InteractionClassName);
                    }
                }
            }
            // Now we can build the string[]
            return(interactionList.ToArray());
        }
예제 #2
0
 // Add object with no attribute list defined
 private static void addObject(Dictionary <string, List <string> > objectList, HlaObject obj, HlaObjectNode hlaObjectTree)
 {
     // If the object is not in the list, add it
     if (!objectList.ContainsKey(obj.ObjectClassName))
     {
         // Get the complete attribute list
         objectList.Add(obj.ObjectClassName, TreeReader.FindAttributes(hlaObjectTree, obj.ObjectClassName));
     }
 }
예제 #3
0
        public static string Create(DeployObject deploy, Component component)
        {
            // Find the modules we need
            ModuleFederation federation = (ModuleFederation)findModule(component.Modules, Enums.ModuleType.federation);
            ModuleImport     import     = (ModuleImport)findModule(component.Modules, Enums.ModuleType.import);
            ModuleExport     export     = (ModuleExport)findModule(component.Modules, Enums.ModuleType.export);
            ModuleExtension  extension  = (ModuleExtension)findModule(component.Modules, Enums.ModuleType.extension);

            ModuleOsp[] osp = findModules(component.Modules);

            // Create an HlaObject tree to use when defining attribute lists
            StringReader  ms            = new StringReader(Properties.Resources.HLAfeatures);
            HlaObjectNode hlaObjectTree = TreeReader.CreateTree(ms);

            StringBuilder sb = new StringBuilder();

            // Side A - always the side connected to a federation
            sb.AppendLine("# A side settings (Federation Side)");
            sb.AppendLine("A.side_name=" + federation.FederationName);
            sb.AppendLine("A.description=Federate " + federation.FederateName + " on " + federation.FederationName + " federation");
            switch (federation.RTI.HlaSpec)
            {
            case "Pitch pRTI 1516":
                sb.AppendLine("A.profile=A");
                break;

            case "HLA Evolved":
                sb.AppendLine("A.profile=B");
                break;

            case "Pitch pRTI 1.3":
                sb.AppendLine("A.profile=C");
                break;

            case "RTI NG":
                sb.AppendLine("A.profile=D");
                break;

            case "MAK 1.3 RTI":
                sb.AppendLine("A.profile=E");
                break;

            case "MAK 1516 RTI":
                sb.AppendLine("A.profile=F");
                break;

            case "RTI NG C++":
                sb.AppendLine("A.profile=G");
                break;

            case "RTI DLC C++":
                sb.AppendLine("A.profile=H");
                break;

            case "Evolved C++":
                sb.AppendLine("A.profile=I");
                break;

            default:
                sb.AppendLine("A.profile=B");
                break;
            }
            sb.AppendLine("A.configurationType=" + extension.Parameters["configurationType"]);
            sb.AppendLine("A.host=" + federation.RTI.CrcAddress);
            sb.AppendLine("A.port=" + federation.RTI.CrcPortNumber);
            sb.AppendLine("A.designator=");
            sb.AppendLine("A.federation=" + federation.FederationName);
            sb.AppendLine("A.type=" + deploy.Systems[0].SystemType.ToString());
            sb.AppendLine("A.name=" + federation.FederateName);
            sb.AppendLine("A.create=" + extension.Parameters["create"]);
            sb.Append("A.evolvedFomModules=");
            for (int i = 0; i < federation.RTI.FomFile.Count; i++)
            {
                if (i == federation.RTI.FomFile.Count - 1)
                {
                    sb.AppendFormat("{0}\n", federation.RTI.FomFile[i]);
                }
                else
                {
                    sb.AppendFormat("{0};", federation.RTI.FomFile[i]);
                }
            }
            sb.AppendLine("A.destroy=false");
            sb.AppendLine("A.disableRequest=false");
            sb.AppendLine("A.logicalTimeFactoryClassName=");
            sb.AppendLine("A.conveyProducingFederate=true");

            // If this is a High proxy then this is the Export Policy list, otherwise the Import Policy
            string result = (component.ComponentName.ToUpper().Contains("HIGH")) ?
                            string.Join("; ", ListBuilder.ObjectList(export, hlaObjectTree)) :
                            string.Join("; ", ListBuilder.ObjectList(import, hlaObjectTree));

            sb.AppendLine("A.objects=" + result);
            // same idea for interactions
            result = (component.ComponentName.ToUpper().Contains("HIGH")) ?
                     string.Join("; ", ListBuilder.InteractionList(export, hlaObjectTree)) :
                     string.Join("; ", ListBuilder.InteractionList(import, hlaObjectTree));
            sb.AppendLine("A.interactions=" + result);
            sb.AppendLine("A.filter=se.pitch.ral.extender.hpsd.Hpsd");
            sb.AppendLine("A.filter.policy=" + component.ComponentName + ".xml");
            sb.AppendLine();

            // B Side -- Always connected to OSP
            sb.AppendLine("# B side settings (HPSD side)");
            sb.AppendLine("B.side_name=" + component.ComponentName);
            sb.AppendLine("B.description=Federate " + federation.FederateName + " HPSD interface");
            sb.AppendLine("B.profile=M");   // HPSD designator
            sb.AppendLine("B.configurationType=LocalSettingsDesignator");
            sb.AppendLine("B.host=0.0.0.0");
            sb.AppendLine("B.port=0");
            sb.AppendFormat("B.designator={0};DEBUG;CONNECT_TIMEOUT\\=10;HEARTBEAT\\=5\n",
                            getDesignator(osp, component));
            sb.AppendLine("B.federation=" + component.ComponentName);
            sb.AppendLine("B.type=" + deploy.Systems[0].SystemType.ToString());
            sb.AppendLine("B.name=" + federation.FederateName);
            sb.AppendLine("B.create=" + extension.Parameters["create"]);
            sb.Append("B.evolvedFomModules=");
            for (int i = 0; i < federation.RTI.FomFile.Count; i++)
            {
                if (i == federation.RTI.FomFile.Count - 1)
                {
                    sb.AppendFormat("{0}\n", federation.RTI.FomFile[i]);
                }
                else
                {
                    sb.AppendFormat("{0};", federation.RTI.FomFile[i]);
                }
            }
            sb.AppendLine("B.destroy=false");
            sb.AppendLine("B.disableRequest=false");
            sb.AppendLine("B.logicalTimeFactoryClassName=");
            sb.AppendLine("B.conveyProducingFederate=true");

            // If this is a High proxy then this is the Import Policy list, otherwise the Export Policy
            result = (component.ComponentName.ToUpper().Contains("HIGH")) ?
                     string.Join("; ", ListBuilder.ObjectList(import, hlaObjectTree)) :
                     string.Join("; ", ListBuilder.ObjectList(export, hlaObjectTree));
            sb.AppendLine("B.objects=" + result);
            // same idea for interactions
            result = (component.ComponentName.ToUpper().Contains("HIGH")) ?
                     string.Join("; ", ListBuilder.InteractionList(import, hlaObjectTree)) :
                     string.Join("; ", ListBuilder.InteractionList(export, hlaObjectTree));
            sb.AppendLine("B.interactions=" + result);

            return(sb.ToString());
        }
예제 #4
0
        internal static string[] ObjectList(IModule policy, HlaObjectNode hlaObjectTree)
        {
            // objectListPartial has key=objectClassName, value=comma separated list of attributes
            Dictionary <string, List <string> > objectList = new Dictionary <string, List <string> >();

            // Logic: We need to get the maximum list of attributes associated with each object:
            //      1. Find all objects in the policy with no attributes defined
            //      2. Add these objects and the full lst of attributes for the object
            //      3. Find the objects in the policy with some attributes defined
            //      4. Add these objects (and their attributes) if they are not there already

            if (policy.GetType() == typeof(ModuleExport))
            {
                ModuleExport exportPolicy = (ModuleExport)policy;
                foreach (Source source in exportPolicy.Sources)
                {
                    // Find the objects with no attributes defined and add the object and all attributes
                    foreach (HlaObject obj in source.Objects)
                    {
                        if (obj.Attributes.Count == 0)
                        {
                            addObject(objectList, obj, hlaObjectTree);
                        }
                    }
                    // Find the objects with attributes defined and add the object and attributes if needed
                    foreach (HlaObject obj in source.Objects)
                    {
                        if (obj.Attributes.Count > 0)
                        {
                            addObjectWithAttributes(objectList, obj);
                        }
                    }
                }
            }
            else
            {
                ModuleImport importPolicy = (ModuleImport)policy;
                // Find the objects with no attributes defined and add the object and all attributes
                foreach (HlaObject obj in importPolicy.Objects)
                {
                    if (obj.Attributes.Count == 0)
                    {
                        addObject(objectList, obj, hlaObjectTree);
                    }
                }
                // Find the objects with attributes defined and add the object and attributes if needed
                foreach (HlaObject obj in importPolicy.Objects)
                {
                    if (obj.Attributes.Count > 0)
                    {
                        addObjectWithAttributes(objectList, obj);
                    }
                }
            }
            // Now we can build the string[]
            List <string> result = new List <string>();

            foreach (KeyValuePair <string, List <string> > obj in objectList)
            {
                // General format is <fully qualified object class name>\: <attribute1>, <attribute2>
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("{0}\\: ", obj.Key);
                for (int i = 0; i < obj.Value.Count; i++)
                {
                    if (i < obj.Value.Count - 1)
                    {
                        sb.AppendFormat("{0}, ", obj.Value[i]);
                    }
                    else
                    {
                        sb.AppendFormat("{0}", obj.Value[i]);
                    }
                }
                result.Add(sb.ToString());
            }
            return(result.ToArray());
        }
예제 #5
0
        public static XElement Create(DeployObject deploy, Component component)
        {
            HpsdPolicy hpsdPolicy = new HpsdPolicy();

            // We can assume that there is only one System in the deploy doc
            DeploySystem system = deploy.Systems[0];


            // PolicyIdentification <--> ConfigMgmt
            PolicyIdentification polID = new PolicyIdentification
            {
                PolicyName    = system.FederateName,
                PolicyVersion = ConfigMgmt.VersionToString(deploy.ConfigMgmt.CurrentVersion),
                CreatedDate   = deploy.ConfigMgmt.Created.date,
                ModifiedDate  = deploy.ConfigMgmt.Changed[deploy.ConfigMgmt.Changed.Count - 1].date,
                Status        = deploy.ConfigMgmt.DocReference.ToString(),
                Description   = deploy.ConfigMgmt.Description
            }; // No POC information

            hpsdPolicy.PolicyIdentification = polID;
            // =======================================

            // FomInformation <--> Federation, Extensions
            FomInformation fominfo = new FomInformation();

            // List of fomModule in Federation module
            ModuleFederation fedModule = (ModuleFederation)findModule(component.Modules, Enums.ModuleType.federation);

            foreach (string file in fedModule.RTI.FomFile)
            {
                fominfo.FomModule.Add(file);
            }

            // InstanceIdAttributes are a Vendor extension
            ModuleExtension extModule = (ModuleExtension)findModule(component.Modules, Enums.ModuleType.extension);

            if (extModule.VendorName != "Pitch Technologies")
            {
                throw new ApplicationException("Pitch Technologies vendor extensions not found");
            }
            foreach (KeyValuePair <string, string> p in extModule.Parameters)
            {
                // General format key = <identifier>:<parameterName>
                // we expect: key = instanceIdAttribute:<fully qualified attribute>
                string[] sa1 = p.Key.Split(':');
                if (sa1[0] == "instanceIdAttribute")
                {
                    string     attribName = sa1[1].Split('.').Last();
                    string     objclass   = sa1[1].Substring(0, sa1[1].Length - (attribName.Length + 1)); // trailing '.'
                    string     encoding   = p.Value;
                    InstanceId instId     = new InstanceId
                    {
                        ObjectClass        = objclass,
                        Attribute_Name     = attribName,
                        Attribute_Encoding = encoding
                    };
                    fominfo.InstanceID.Add(instId);
                }
            }
            hpsdPolicy.FomInformation = fominfo;
            // =====================================================================================

            // Federates <--->  Export module
            Federates feds = new Federates();

            // List of federates in Export module
            ModuleExport expModule = (ModuleExport)findModule(component.Modules, Enums.ModuleType.export);

            foreach (Source source in expModule.Sources)
            {
                feds.Federate.Add(source.FederateName);
            }

            hpsdPolicy.Federates = feds;
            // =====================================================================================

            // PolicyRules <----> Export/Import module

            // Hack
            // Create an HlaObject tree to use when defining attribute lists
            StringReader  ms            = new StringReader(Properties.Resources.HLAfeatures);
            HlaObjectNode hlaObjectTree = TreeReader.CreateTree(ms);

            PolicyRules rules      = new PolicyRules();
            int         ruleNumber = 0;

            if (component.ComponentName.ToUpper().Contains("HIGH"))
            {
                // Status message - session name = federateName
                SessionStatusReleaseRule sess = new SessionStatusReleaseRule
                {
                    Condition_SessionName = system.FederateName,
                    RuleName = ruleNumber++.ToString()
                };
                rules.SessionStatus.Add(sess);

                // Object update/create
                foreach (Source source in expModule.Sources)
                {
                    string federateName = source.FederateName;
                    string entityID     = "";
                    if (source.SourceType == Source.Type.Federate)
                    {
                        entityID = "*";
                    }
                    else
                    {
                        entityID = source.EntityId;
                    }

                    foreach (HlaObject hlaObj in source.Objects)
                    {
                        ObjectReleaseReplaceRule obj = new ObjectReleaseReplaceRule()
                        {
                            Condition_ProducingFederate = federateName,
                            Condition_InstanceID        = entityID,
                            RuleName = ruleNumber++.ToString(),
                            Condition_ObjectClass = hlaObj.ObjectClassName.NoHlaRoot()
                        };
                        //  Hack if no attribs listed add all attribs from the TreeReader
                        if (hlaObj.Attributes.Count == 0)
                        {
                            List <string> theworks = TreeReader.FindAttributes(hlaObjectTree, hlaObj.ObjectClassName);
                            foreach (string attrib in theworks)
                            {
                                obj.Release_Attribute.Add(attrib);
                            }
                            rules.ObjectRelease.Add(obj);
                        }
                        else
                        // Hack - read attributes from the object and add them; de-duplicate
                        {
                            List <string> temp = new List <string>();
                            foreach (HlaAttribute attrib in hlaObj.Attributes)
                            {
                                temp.Add(attrib.AttributeName);
                            }
                            obj.Release_Attribute = temp.Distinct().ToList();
                            rules.ObjectRelease.Add(obj);
                        }
                    }

                    foreach (HlaInteraction hlaInt in source.Interactions)
                    {
                        InteractionReleaseReplaceRule intr = new InteractionReleaseReplaceRule()
                        {
                            Condition_ProducingFederate = federateName,
                            RuleName = ruleNumber++.ToString(),
                            Condition_InteractionClass = hlaInt.InteractionClassName.NoHlaRoot()
                        };
                        List <string> temp = new List <string>();
                        foreach (HlaParameter para in hlaInt.Parameters)
                        {
                            temp.Add(para.ParameterName);
                        }
                        intr.Release_Parameter = temp.Distinct().ToList();
                        rules.InteractionRelease.Add(intr);
                    }
                }
            }
            else
            {
                ModuleImport impModule = (ModuleImport)findModule(component.Modules, Enums.ModuleType.import);
                foreach (HlaObject hlaObj in impModule.Objects)
                {
                    ObjectReleaseReplaceRule obj = new ObjectReleaseReplaceRule()
                    {
                        Condition_ProducingFederate = "*",
                        Condition_InstanceID        = "*",
                        RuleName = ruleNumber++.ToString(),
                        Condition_ObjectClass = hlaObj.ObjectClassName.NoHlaRoot()
                    };
                    List <string> temp = new List <string>();
                    foreach (HlaAttribute attrib in hlaObj.Attributes)
                    {
                        temp.Add(attrib.AttributeName);
                    }
                    obj.Release_Attribute = temp.Distinct().ToList();
                    rules.ObjectRelease.Add(obj);
                }

                foreach (HlaInteraction hlaInt in impModule.Interactions)
                {
                    InteractionReleaseReplaceRule intr = new InteractionReleaseReplaceRule()
                    {
                        Condition_ProducingFederate = "*",
                        RuleName = ruleNumber++.ToString(),
                        Condition_InteractionClass = hlaInt.InteractionClassName.NoHlaRoot()
                    };
                    List <string> temp = new List <string>();
                    foreach (HlaParameter para in hlaInt.Parameters)
                    {
                        temp.Add(para.ParameterName);
                    }
                    intr.Release_Parameter = temp.Distinct().ToList();
                    rules.InteractionRelease.Add(intr);
                }
            }
            hpsdPolicy.PolicyRules = rules;
            return(hpsdPolicy.ToHPSD());
        }