Пример #1
0
        public async Task SetupAsync()
        {
            _settingsRepositoryMock = new Mock <ISettingsRepository>();
            _settingsRepositoryMock.Setup(x => x.GetSettings()).ReturnsAsync(new Settings());

            _service = new EthernetServices(new BashCommand(), new NullLoggerFactory());
        }
Пример #2
0
 public EthernetController(ILogger <EthernetController> logger, EthernetServices ethernetServices, LLDPServices lldpSercives,
                           ISettingsRepository settingsRepository)
 {
     _logger             = logger;
     _ethernetServices   = ethernetServices;
     _lldpSercives       = lldpSercives;
     _settingsRepository = settingsRepository;
 }
Пример #3
0
        static void AnalyseFrame(List <RawCapture> frames, string interface_name, EthernetServices _ethernetservices)
        {
            //await Task.Run(() => {

            List <EthernetInterface> GVRP_ON_Interfaces = new List <EthernetInterface>();

            foreach (EthernetInterface nic in _ethernetservices.GetEthernetInterfaces().Where(x => x.GVRP_Enabled == true))
            {
                GVRP_ON_Interfaces.Add(nic);
            }

            List <GVRP_data> gvrp_events = new List <GVRP_data>();

            foreach (RawCapture frame in frames)
            {
                string   tmpFrame  = BitConverter.ToString(frame.Data);
                string[] frameArry = tmpFrame.Split('-');
                int      i         = 20;
                while (frameArry[i] != "00" && frameArry[i + 1] != "00")    // while gvrp data
                {
                    gvrp_events.Add(new GVRP_data());
                    gvrp_events.Last().event_id = int.Parse(frameArry[i + 1], System.Globalization.NumberStyles.HexNumber);
                    gvrp_events.Last().vlan_ID  = int.Parse(frameArry[i + 2] + frameArry[i + 3], System.Globalization.NumberStyles.HexNumber);
                    i = i + 4;
                }
            }
            List <int> GVRPadd    = new List <int>();
            List <int> GVRPaddTmp = new List <int>();
            List <int> GVRPrm     = new List <int>();

            foreach (GVRP_data d in gvrp_events)
            {
                if (d.event_id == 3)
                {
                    GVRPrm.Add(d.vlan_ID);
                }
                if (d.event_id == 2)
                {
                    GVRPadd.Add(d.vlan_ID);
                }
            }
            GVRPadd = GVRPadd.Distinct().ToList();
            GVRPrm  = GVRPrm.Distinct().ToList();


            //GVRPaddTmp = GVRPadd.Except(GVRPrm).ToList();
            GVRPrm = GVRPrm.Except(GVRPadd).ToList();

            List <GVRP_data> gvrp_eventsToSet = new List <GVRP_data>();

            foreach (int i in GVRPadd)
            {
                GVRP_data tmp = new GVRP_data();
                tmp.event_id = 2;
                tmp.vlan_ID  = i;
                gvrp_eventsToSet.Add(tmp);
            }
            foreach (int i in GVRPrm)
            {
                GVRP_data tmp = new GVRP_data();
                tmp.event_id = 3;
                tmp.vlan_ID  = i;
                gvrp_eventsToSet.Add(tmp);
            }

            foreach (GVRP_data g in gvrp_eventsToSet)
            {
                if (g.event_id == 3)    // remove vlan from interface
                {
                    foreach (EthernetInterface nic in GVRP_ON_Interfaces)
                    {
                        List <string> vlans = _ethernetservices.GetEthernetInterfaces().Where(x => x.Name == nic.Name).First().VirtualLANs.ToList();

                        bool isVlanToRemove = false;
                        foreach (var vlan in vlans)
                        {
                            if (vlan == g.vlan_ID.ToString())
                            {
                                isVlanToRemove = true;
                            }
                        }
                        if (isVlanToRemove == true)
                        {
                            //vlans.Remove(g.vlan_ID.ToString());
                            List <string> tmp = new List <string>();
                            tmp.Add(g.vlan_ID.ToString());
                            //Console.WriteLine("UsuwamVLAN:{0}", tmp[0]);
                            if (tmp.Count() > 0)
                            {
                                _ethernetservices.RemoveVlanFromInterface(nic.Name, tmp);
                            }
                        }
                    }
                }
                if (g.event_id == 2)    // add vlan to interface
                {
                    List <string> vlans = new List <string>();
                    vlans.Add(g.vlan_ID.ToString());     //vlans to add
                    foreach (EthernetInterface nic in GVRP_ON_Interfaces)
                    {
                        List <string> tmp = new List <string>();
                        foreach (string s in nic.VirtualLANs.ToList())
                        {
                            tmp.Add(s);
                        }
                        tmp.Add(g.vlan_ID.ToString());
                        if (tmp.Count() > 0)
                        {
                            _ethernetservices.ApplyEthernetGVRPInterfaceVLANs(nic.Name, true, true, tmp);
                        }
                    }
                }
            }
            // });
        }