private void destroyPIFs() { foreach (PIF pif in PIFs) { if (pif.IsTunnelAccessPIF) { // A tunnel access PIF is destroyed by destroying its tunnel. // (Actually each network will have either all tunnel access PIFs (if // it is a CHIN) or all regular PIFs (if it isn't), but we don't use // that: we do it PIF-by-PIF). foreach (Tunnel tunnel in Connection.ResolveAll(pif.tunnel_access_PIF_of)) // actually there will only ever be one { Tunnel.destroy(Session, tunnel.opaque_ref); } } else { if (!pif.physical) { VLAN.destroy(Session, pif.VLAN_master_of); } else { // do we ever destroy physical pifs anyway? not sure this is something we need but here for completeness PIF.forget(Session, pif.opaque_ref); } } } PIFs = null; }
public CounterSample(byte[] buffer) : base(buffer) { Records = new CounterRecord[buffer.ToUInt(16, 4)]; uint recordStartIndex = 20; for (uint i = 0; i < Records.Length; i++) { CounterRecord record = new CounterRecord(buffer.AsSpan((int)recordStartIndex, (int)Record.HeaderLengthBytes).ToArray()); int recordLength = (int)(record.Length + Record.HeaderLengthBytes); if (record.Type == RecordType.GenericInterface) { record = new Records.Generic(buffer.AsSpan((int)recordStartIndex, recordLength).ToArray()); } else if (record.Type == RecordType.EthernetInterface) { record = new Ethernet(buffer.AsSpan((int)recordStartIndex, recordLength).ToArray()); } else if (record.Type == RecordType.VLAN) { record = new VLAN(buffer.AsSpan((int)recordStartIndex, recordLength).ToArray()); } else if (record.Type == RecordType.ProcessorInformation) { record = new ProcessorInfo(buffer.AsSpan((int)recordStartIndex, recordLength).ToArray()); } recordStartIndex += (uint)recordLength; Records[i] = record; } }
public void Add(VLAN vlan, object connected) { if ((this.vlanID == -1) || (this.vlanID == vlan.ID) || (vlan.ID == -1)) { this.vlanID = vlan.ID; string name = vlan.VlanName; if (name == "") { name = "Empty"; } if (!names.Contains(name)) { names.Add(name); if (names.Count > 1) { actionReq = true; } } foreach (IP ip in vlan.IPs) { if (!this.IPs.Contains(ip)) { this.IPs.Add(ip); } } } else { Console.WriteLine("Error occured reading networks, adding vlan to existing network with wrong vlan ID"); } this.ConnectedTo.Add(connected); }
public XmlElement Save(XmlDocument XmlDoc) { XmlElement NameElement = XmlDoc.CreateElement("Name"); NameElement.InnerText = Name; XmlElement IpElement = XmlDoc.CreateElement("IP"); IpElement.InnerText = IP.ToString(); XmlElement MacElement = XmlDoc.CreateElement("MAC"); MacElement.InnerText = MAC.ToString(); XmlElement VlanElement = XmlDoc.CreateElement("VLAN"); VlanElement.InnerText = VLAN.ToString(); XmlElement ArpServiceElement = XmlDoc.CreateElement("ARP"); ArpServiceElement.InnerText = ArpServiceSupport.ToString(); XmlElement IcmpServiceElement = XmlDoc.CreateElement("ICMP"); IcmpServiceElement.InnerText = IcmpServiceSupport.ToString(); XmlElement TcpServiceElement = XmlDoc.CreateElement("TCP"); TcpServiceElement.InnerText = TcpServiceSupport.ToString(); XmlElement ServiceElement = XmlDoc.CreateElement("Services"); ServiceElement.AppendChild(ArpServiceElement); ServiceElement.AppendChild(IcmpServiceElement); ServiceElement.AppendChild(TcpServiceElement); XmlElement AdapterElement = XmlDoc.CreateElement("VirtualAdapter"); AdapterElement.AppendChild(NameElement); AdapterElement.AppendChild(IpElement); AdapterElement.AppendChild(MacElement); AdapterElement.AppendChild(VlanElement); AdapterElement.AppendChild(ServiceElement); return(AdapterElement); }
public void SendSetResponse(PhysicalAddress destination, uint xid, DCP.BlockOptions option, DCP.BlockErrors status) { Trace.WriteLine("Sending Set " + option.ToString() + " response", null); MemoryStream mem = new MemoryStream(); //ethernet Ethernet.Encode(mem, destination, adapter.MacAddress, Ethernet.Type.VLanTaggedFrame); //VLAN VLAN.Encode(mem, VLAN.Priorities.Priority0, VLAN.Type.PN); //Profinet Real Time RT.EncodeFrameId(mem, RT.FrameIds.DCP_Get_Set_PDU); //Profinet DCP DCP.EncodeSetResponse(mem, xid, option, status); //Send Send(mem); }
public void SendIdentifyResponse(PhysicalAddress destination, uint xid, Dictionary <DCP.BlockOptions, object> blocks) { Trace.WriteLine("Sending identify response", null); MemoryStream mem = new MemoryStream(); //ethernet Ethernet.Encode(mem, destination, adapter.MacAddress, Ethernet.Type.VLanTaggedFrame); //VLAN VLAN.Encode(mem, VLAN.Priorities.Priority0, VLAN.Type.PN); //Profinet Real Time RT.EncodeFrameId(mem, RT.FrameIds.DCP_Identify_ResPDU); //Profinet DCP DCP.EncodeIdentifyResponse(mem, xid, blocks); //Send Send(mem); }
public IAsyncResult BeginGetRequest(PhysicalAddress destination, DCP.BlockOptions option) { Trace.WriteLine("Sending Get " + option.ToString() + " request", null); MemoryStream mem = new MemoryStream(); //ethernet Ethernet.Encode(mem, destination, adapter.MacAddress, Ethernet.Type.VLanTaggedFrame); //VLAN VLAN.Encode(mem, VLAN.Priorities.Priority0, VLAN.Type.PN); //Profinet Real Time RT.EncodeFrameId(mem, RT.FrameIds.DCP_Get_Set_PDU); //Profinet DCP UInt16 xid = ++lastXid; DCP.EncodeGetRequest(mem, xid, option); //start Async return(new ProfinetAsyncDcpResult(this, mem, xid)); }
private void btnAddVLAN_Click(object sender, RoutedEventArgs e) { var wnd = new AddVLANDialogWindow(); wnd.Owner = this; if (wnd.ShowDialog() == true) { string VLAN_IdsStr = (wnd.VLAN_IdsStr ?? string.Empty).Trim(); var nodeIds = VLAN_IdsStr .Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(p => { int id = 0; return(int.TryParse(p, out id) ? id : 0); }) .Where(p => p > 0) .Distinct() .OrderBy(p => p) .ToList(); if (nodeIds.Count > 2 && nodeIds.All(id => _nodes.Any(node => node.NodeId == id))) { var vlan = new VLAN { Color = GetRandomColor() }; vlan.NodeIds.AddRange(nodeIds); _vlans.Add(vlan); } else { MessageBox.Show("Not valid node identifiers", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); } } ; }
public void SendIdentifyBroadcast() { Trace.WriteLine("Sending identify broadcast", null); MemoryStream mem = new MemoryStream(); //ethernet PhysicalAddress ethernetDestinationHwAddress = PhysicalAddress.Parse(RT.MulticastMACAdd_Identify_Address); Ethernet.Encode(mem, ethernetDestinationHwAddress, adapter.MacAddress, Ethernet.Type.VLanTaggedFrame); //VLAN VLAN.Encode(mem, VLAN.Priorities.Priority0, VLAN.Type.PN); //Profinet Real Time RT.EncodeFrameId(mem, RT.FrameIds.DCP_Identify_ReqPDU); //Profinet DCP DCP.EncodeIdentifyRequest(mem, ++lastXid); //Send Send(mem); }
public static async void SendToElastic(this sFlowDatagram datagram) { string request = ""; string datetime = DateTime.Now.ToString("o"); foreach (Sample sample in datagram.Samples) { if (sample == null) { continue; } Dictionary <string, object> doc = new Dictionary <string, object>(); doc.Add("@timestamp", datetime); doc.Add("sflow_source", datagram.AgentAddress.ToString()); doc.Add("sflow_sequence", datagram.SequenceNumber); if (sample.Type == SampleType.Flow) { FlowSample flowSample = (FlowSample)sample; doc.Add("sampling_rate", flowSample.SamplingRate); doc.Add("sampling_pool", flowSample.SamplingPool); doc.Add("dropped_packets", flowSample.DroppedPackets); doc.Add("frame_in_interface_value", flowSample.InputInterface.Value); doc.Add("frame_out_interface_value", flowSample.OutputInterface.Value); doc.Add("frame_out_interface_format", flowSample.OutputInterface.Format.ToString()); doc.Add("frame_out_interface_discard", flowSample.OutputInterface.DiscardReason.ToString()); foreach (FlowRecord record in flowSample.Records) { if (record.Type == FlowRecordType.RawPacketHeader) { RawPacketHeader rawPacketHeader = (RawPacketHeader)record; doc.Add("frame_length_octets", rawPacketHeader.FrameLength); if (rawPacketHeader.HeaderProtocol == HeaderProtocol.Ethernet) { EthernetFrame ethFrame = (EthernetFrame)rawPacketHeader.Header; doc.Add("mac_source", ethFrame.SourceMAC.ToString()); doc.Add("mac_destination", ethFrame.DestinationMAC.ToString()); doc.Add("packet_type", ethFrame.PacketType.ToString()); ProtocolType ProtocolType = 0; if (ethFrame.PacketType == PacketType.IPv4) { IPv4Packet packet = (IPv4Packet)ethFrame.Packet; doc.Add("ip_source", packet.SourceAddress.ToString()); doc.Add("ip_destination", packet.DestinationAddress.ToString()); doc.Add("ip_ttl", packet.TimeToLive); doc.Add("protocol_type", packet.ProtocolType.ToString()); ProtocolType = packet.ProtocolType; } if (ProtocolType == ProtocolType.TCP) { TCP TCP = (TCP)ethFrame.Packet.Payload; doc.Add("port_source", TCP.SourcePort); doc.Add("port_destination", TCP.DestinationPort); } else if (ProtocolType == ProtocolType.UDP) { UDP UDP = (UDP)ethFrame.Packet.Payload; doc.Add("port_source", UDP.SourcePort); doc.Add("port_destination", UDP.DestinationPort); } } } else if (record.Type == FlowRecordType.ExtSwitchData) { SwitchData switchData = (SwitchData)record; doc.Add("vlan_in", switchData.IncomingVLAN); doc.Add("vlan_out", switchData.OutgoingVLAN); } } } else if (sample.Type == SampleType.Counter) { CounterSample countSample = (CounterSample)sample; foreach (CounterRecord record in countSample.Records) { if (record.Type == CounterRecordType.GenericInterface) { Generic gi = (Generic)record; doc.Add("if_direction", gi.IfDirection.ToString()); doc.Add("if_in_broadcast_pkts", gi.IfInBroadcastPkts); doc.Add("if_index", gi.IfIndex); doc.Add("if_in_discards", gi.IfInDiscards); doc.Add("if_in_errors", gi.IfInErrors); doc.Add("if_in_multicast_pkts", gi.IfInMulticastPkts); doc.Add("if_in_octets", gi.IfInOctets); doc.Add("if_in_unicast_pkts", gi.IfInUcastPkts); doc.Add("if_in_unknown_protos", gi.IfInUnknownProtos); doc.Add("if_out_broadcast_pkts", gi.IfOutBroadcastPkts); doc.Add("if_out_discards", gi.IfOutDiscards); doc.Add("if_out_errors", gi.IfOutErrors); doc.Add("if_out_multicast_pkts", gi.IfOutMulticastPkts); doc.Add("if_out_octets", gi.IfOutOctets); doc.Add("if_out_unicast_ptks", gi.IfOutUcastPkts); doc.Add("if_promiscuous_mode", gi.IfPromiscuousMode); doc.Add("if_speed", gi.IfSpeed); doc.Add("if_type", gi.IfType); doc.Add("if_status_up_admin", gi.IfStatus.HasFlag(Generic.IfStatusFlags.IfAdminStatusUp)); doc.Add("if_status_up_operational", gi.IfStatus.HasFlag(Generic.IfStatusFlags.IfOperStatusUp)); } else if (record.Type == CounterRecordType.EthernetInterface) { Ethernet eth = (Ethernet)record; doc.Add("eth_alignment_errors", eth.AlignmentErrors); doc.Add("eth_carrier_sense_errors", eth.CarrierSenseErrors); doc.Add("eth_deferred_transmissions", eth.DeferredTransmissions); doc.Add("eth_excessive_collisions", eth.ExcessiveCollisions); doc.Add("eth_fcs_errors", eth.FCSErrors); doc.Add("eth_frame_too_longs", eth.FrameTooLongs); doc.Add("eth_mac_recieve_errors", eth.InternalMacReceiveErrors); doc.Add("eth_mac_transmit_errors", eth.InternalMacTransmitErrors); doc.Add("eth_late_collisions", eth.LateCollisions); doc.Add("eth_multiple_collision_frames", eth.MultipleCollisionFrames); doc.Add("eth_single_collision_frames", eth.SingleCollisionFrames); doc.Add("eth_sqe_test_errors", eth.SQETestErrors); doc.Add("eth_symbol_errors", eth.SymbolErrors); } else if (record.Type == CounterRecordType.VLAN) { VLAN vlan = (VLAN)record; doc.Add("vlan_multicast_pkts", vlan.MulticastPkts); doc.Add("vlan_octets", vlan.Octets); doc.Add("vlan_unicast_pkts", vlan.UCastPkts); doc.Add("vlan_id", vlan.VlanID); } else if (record.Type == CounterRecordType.ProcessorInformation) { ProcessorInfo pi = (ProcessorInfo)record; doc.Add("stats_cpu_percent_1m", pi.Cpu1mPercentage); doc.Add("stats_cpu_percent", pi.Cpu5mPercentage); doc.Add("stats_cpu_5s_percent", pi.Cpu5sPercentage); doc.Add("stats_memory_free", pi.FreeMemory); doc.Add("stats_memory_total", pi.TotalMemory); } } } request += "{\"create\":{\"_index\":\"" + PREFIX + sample.Type.ToString().ToLower() + "\"}}\n"; request += JsonConvert.SerializeObject(doc) + '\n'; } try { MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(request)); await HC.PostAsync(URI + "/_bulk", new StreamContent(ms) { Headers = { ContentType = MediaTypeHeaderValue.Parse("application/json") } }); ms.Dispose(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public Network(VLAN vlan, object connected) { Add(vlan, connected); }