Example #1
0
        private void AddSegment(string ipSegment, Brush color, double columnHeight, Dictionary <string, int> ipSegmentDic, List <IpFlowIpSegment4> segments, bool isSrc, IpFlowIpNode ipNode, List <IpFlowIpToPortLink> links, string partIp)
        {
            var findNode = segments.Find(n => n.Segment == ipSegment);

            if (findNode == null)
            {
                var segment = ConfigureSegment(new IpFlowIpSegment4(), isSrc, 3, ipSegment, color, columnHeight, ipSegmentDic, segments, partIp);
                segments.Add(segment);
                ipNode.SetSegment(segment, 3);
                CalculateLinkPositionInSegment4Node(segment, links);
            }
            else
            {
                ipNode.SetSegment(findNode, 3);
            }
        }
Example #2
0
        private void AddSegment(string ipSegment, Brush color, double columnHeight, Dictionary <string, int> ipSegmentDic, List <IpFlowIpSegment> segments, int index, bool isSrc, IpFlowIpNode ipNode, string partIp)
        {
            var findNode = segments.Find(n => n.Segment == ipSegment);

            if (findNode == null)
            {
                var segment = ConfigureSegment(new IpFlowIpSegment(), isSrc, index, ipSegment, color, columnHeight, ipSegmentDic, segments, partIp);
                segments.Add(segment);
                ipNode.SetSegment(segment, index);
            }
            else
            {
                ipNode.SetSegment(findNode, index);
            }
        }
Example #3
0
        public void DrawDiagram()
        {
            if (filteredDatas == null || filteredDatas.Count == 0)
            {
                return;
            }

            if (DiagramGrid.ActualHeight <= 5 || (DiagramGrid.ActualWidth - 5 - diagram.IpSegmentColumnWidth * 8) <= 0)
            {
                return;
            }

            if (SrcIpToPortContainer.ActualWidth <= 0 || SrcToDestPortContainer.ActualWidth <= 0 || DestIpToPortContainer.ActualWidth <= 0)
            {
                return;
            }

            CheckRange(diagram.LinkCurvature, "LinkCurvature", "curvature should be ranged from 0 to 1");

            #region preparing...

            var srcIp1Dic         = new Dictionary <string, int>();
            var srcIp2Dic         = new Dictionary <string, int>();
            var srcIp3Dic         = new Dictionary <string, int>();
            var srcIp4Dic         = new Dictionary <string, int>();
            var destIp1Dic        = new Dictionary <string, int>();
            var destIp2Dic        = new Dictionary <string, int>();
            var destIp3Dic        = new Dictionary <string, int>();
            var destIp4Dic        = new Dictionary <string, int>();
            var srcIpToPortLinks  = new List <IpFlowIpToPortLink>();
            var destIpToPortLinks = new List <IpFlowIpToPortLink>();
            var portLinks         = new List <IpFlowPortLink>();
            var links             = new List <IpFlowLink>();
            var ipDatas           = (from d in filteredDatas select new { SourceColor = d.SourceColor, DestinationColor = d.DestinationColor, SourceIp = d.SourceIp, SourcePort = d.SourcePort, DestinationIp = d.DestinationIp, DestinationPort = d.DestinationPort, SrcIpSegments = d.SourceIp.ToString().Split('.'), DestSegments = d.DestinationIp.ToString().Split('.') }).ToList(); // store the results

            foreach (var data in ipDatas)
            {
                BuildCountDictionary(data.SrcIpSegments[0], srcIp1Dic);
                BuildCountDictionary(data.SrcIpSegments[1], srcIp2Dic);
                BuildCountDictionary(data.SrcIpSegments[2], srcIp3Dic);
                var s4 = data.SrcIpSegments[3];
                BuildCountDictionary(s4, srcIp4Dic);
                var srcIpToPortLink = BuildLinks(CreateIpToPortLink(data.SourceIp, data.SourcePort, s4, diagram.LinkFill, diagram.LinkStroke), srcIpToPortLinks, l => l.Segment == s4 && l.Port == data.SourcePort);
                BuildCountDictionary(data.DestSegments[0], destIp1Dic);
                BuildCountDictionary(data.DestSegments[1], destIp2Dic);
                BuildCountDictionary(data.DestSegments[2], destIp3Dic);
                var d4 = data.DestSegments[3];
                BuildCountDictionary(d4, destIp4Dic);
                var destIpToPortLink = BuildLinks(CreateIpToPortLink(data.DestinationIp, data.DestinationPort, d4, diagram.LinkFill, diagram.LinkStroke), destIpToPortLinks, l => l.Segment == d4 && l.Port == data.DestinationPort);
                var portLink         = BuildLinks(CreatePortLink(data.SourcePort, data.DestinationPort, diagram.LinkFill, diagram.LinkStroke), portLinks, l => l.SourcePort == data.SourcePort && l.DestinationPort == data.DestinationPort);

                links.Add(new IpFlowLink()
                {
                    OriginalLinkFillBrush       = diagram.LinkFill.CloneCurrentValue(),
                    OriginalLinkStrokeBrush     = diagram.LinkStroke.CloneCurrentValue(),
                    SourceIpToPortLink          = srcIpToPortLink,
                    DestinationIpToPortLink     = destIpToPortLink,
                    SourceToDestinationPortLink = portLink
                });
            }

            #endregion

            #region ip segment node & port labels

            styleManager.UpdateLabelAdjustY();
            var srcPort200  = CreateSrcPortLabel(200);
            var destPort200 = CreateDestPortLabel(200);

            if (srcPort200 == null || destPort200 == null)
            {
                return;
            }

            srcPortLabels = new List <IpFlowPortLabel>()
            {
                srcPort200
            };
            destPortLabels = new List <IpFlowPortLabel>()
            {
                destPort200
            };
            SrcIpToPortContainer.Children.Add(srcPort200.Label);
            DestIpToPortContainer.Children.Add(destPort200.Label);
            var ipColumnHeight = SrcIpSegment1Container.ActualHeight;
            styleManager.DefaultNodesPaletteIndex = 0;
            var src1Ips  = new List <IpFlowIpSegment>();
            var src2Ips  = new List <IpFlowIpSegment>();
            var src3Ips  = new List <IpFlowIpSegment>();
            var src4Ips  = new List <IpFlowIpSegment4>();
            var dest1Ips = new List <IpFlowIpSegment>();
            var dest2Ips = new List <IpFlowIpSegment>();
            var dest3Ips = new List <IpFlowIpSegment>();
            var dest4Ips = new List <IpFlowIpSegment4>();
            nodes = new List <IpFlowNode>();

            foreach (var data in ipDatas)
            {
                var srcIpNode = new IpFlowIpNode()
                {
                    IpAddress = data.SourceIp
                };

                AddSegment(data.SrcIpSegments[0], data.SourceColor, ipColumnHeight, srcIp1Dic, src1Ips, 0, true, srcIpNode, data.SrcIpSegments[0]);
                AddSegment(data.SrcIpSegments[1], data.SourceColor, ipColumnHeight, srcIp2Dic, src2Ips, 1, true, srcIpNode, data.SrcIpSegments[0] + "." + data.SrcIpSegments[1]);
                AddSegment(data.SrcIpSegments[2], data.SourceColor, ipColumnHeight, srcIp3Dic, src3Ips, 2, true, srcIpNode, data.SrcIpSegments[0] + "." + data.SrcIpSegments[1] + "." + data.SrcIpSegments[2]);
                AddSegment(data.SrcIpSegments[3], data.SourceColor, ipColumnHeight, srcIp4Dic, src4Ips, true, srcIpNode, srcIpToPortLinks, data.SourceIp);

                var destIpNode = new IpFlowIpNode()
                {
                    IpAddress = data.DestinationIp
                };

                AddSegment(data.DestSegments[0], data.DestinationColor, ipColumnHeight, destIp1Dic, dest1Ips, 0, false, destIpNode, data.DestSegments[0]);
                AddSegment(data.DestSegments[1], data.DestinationColor, ipColumnHeight, destIp2Dic, dest2Ips, 1, false, destIpNode, data.DestSegments[0] + "." + data.DestSegments[1]);
                AddSegment(data.DestSegments[2], data.DestinationColor, ipColumnHeight, destIp3Dic, dest3Ips, 2, false, destIpNode, data.DestSegments[0] + "." + data.DestSegments[1] + "." + data.DestSegments[2]);
                AddSegment(data.DestSegments[3], data.DestinationColor, ipColumnHeight, destIp4Dic, dest4Ips, false, destIpNode, destIpToPortLinks, data.DestinationIp);

                nodes.Add(new IpFlowNode()
                {
                    DestinationIpNode = destIpNode,
                    SourceIpNode      = srcIpNode
                });

                AddSrcPortLabel(data.SourcePort, srcPortLabels);
                AddDestPortLabel(data.DestinationPort, destPortLabels);
            }

            nodes = nodes.GroupBy(n => n.SourceIpNode.IpAddress + n.DestinationIpNode.IpAddress).Select(group => group.First()).ToList();
            SrcIpSegment1Nodes  = src1Ips;
            SrcIpSegment2Nodes  = src2Ips;
            SrcIpSegment3Nodes  = src3Ips;
            SrcIpSegment4Nodes  = src4Ips;
            DestIpSegment1Nodes = dest1Ips;
            DestIpSegment2Nodes = dest2Ips;
            DestIpSegment3Nodes = dest3Ips;
            DestIpSegment4Nodes = dest4Ips;

            #endregion

            #region links

            CalculateSegment4VerticalPosition(src4Ips);
            CalculateSegment4VerticalPosition(dest4Ips);
            CalculatePortLinkWidth(SrcToDestPortContainer.ActualHeight, portLinks);

            foreach (var label in srcPortLabels)
            {
                CalculateLinkPositionInPorts(SrcIpToPortContainer.ActualHeight / 2, label, srcIpToPortLinks, portLinks, l => l.SourcePort == label.Port && !l.PositionInSourcePortsIsSetted, l => 200 < l.SourcePort && l.SourcePort <= label.Port && !l.PositionInSourcePortsIsSetted, SetPortLinkPositionInSrcPortLessThan200, SetPortLinkPositionInSrcPortGreaterThan200);
            }

            foreach (var label in destPortLabels)
            {
                CalculateLinkPositionInPorts(DestIpToPortContainer.ActualHeight / 2, label, destIpToPortLinks, portLinks, l => l.DestinationPort == label.Port && !l.PositionInDestinationPortsIsSetted, l => 200 < l.DestinationPort && l.DestinationPort <= label.Port && !l.PositionInDestinationPortsIsSetted, SetPortLinkPositionInDestPortLessThan200, SetPortLinkPositionInDestPortGreaterThan200);
            }

            foreach (var link in srcIpToPortLinks)
            {
                SrcIpToPortContainer.Children.Add(ShapeSrcLink(link, SrcIpToPortContainer.ActualWidth).Shape);
            }

            foreach (var link in destIpToPortLinks)
            {
                DestIpToPortContainer.Children.Add(ShapeDestLink(link, DestIpToPortContainer.ActualWidth).Shape);
            }

            foreach (var link in portLinks)
            {
                SrcToDestPortContainer.Children.Add(ShapePortLink(link, SrcToDestPortContainer.ActualWidth).Shape);
            }

            foreach (var node in nodes)
            {
                node.Links = links.FindAll(l => l.SourceIpToPortLink.IpAddress == node.SourceIpNode.IpAddress && l.DestinationIpToPortLink.IpAddress == node.DestinationIpNode.IpAddress);
            }

            #endregion

            DiagramGrid.Visibility = Visibility.Visible;
        }