From 68a19977722ff626e7ba7219303bfe4991fba324 Mon Sep 17 00:00:00 2001 From: ASemenchuk <59782501+Botinoc@users.noreply.github.com> Date: Mon, 1 Aug 2022 15:20:44 +0300 Subject: [PATCH 1/2] Cisco fix: add error message --- CiscoMigration/CiscoCommands.cs | 9 ++++-- CiscoMigration/CiscoConverter.cs | 55 +++++++++++++++++++++++--------- CiscoMigration/CiscoParser.cs | 10 +----- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/CiscoMigration/CiscoCommands.cs b/CiscoMigration/CiscoCommands.cs index 8834f2d..9096f28 100644 --- a/CiscoMigration/CiscoCommands.cs +++ b/CiscoMigration/CiscoCommands.cs @@ -1370,6 +1370,7 @@ public class Cisco_Interface : CiscoCommand public string VLan { get; set; } public string IpAddress { get; set; } public string Netmask { get; set; } + public int LineId { get; set; } public bool Shutdown { get; set; } public bool ManagementOnly { get; set; } public bool LeadsToInternet { get; set; } @@ -1378,11 +1379,13 @@ public class Subnet { public string Network { get; private set; } public string Netmask { get; private set; } + public int LineId { get; private set; } - public Subnet(string sIp, string sMask) + public Subnet(string sIp, string sMask, int lineId) { Network = sIp; Netmask = sMask; + LineId = lineId; } } @@ -1399,6 +1402,7 @@ public override void Parse(CiscoCommand command, CiscoCommand prevCommand, Dicti VLan = ""; IpAddress = ""; Netmask = ""; + LineId = 0; Shutdown = false; ManagementOnly = false; LeadsToInternet = false; @@ -1439,10 +1443,11 @@ public override void Parse(CiscoCommand command, CiscoCommand prevCommand, Dicti case "ip address": IpAddress = ((Cisco_IP)child).IpAddress; Netmask = ((Cisco_IP)child).Netmask; + LineId = ((Cisco_IP)child).Id; if (NetworkUtils.IsValidIpv4(IpAddress) && NetworkUtils.IsValidNetmaskv4(Netmask)) { - Topology.Add(new Subnet(NetworkUtils.GetNetwork(IpAddress, Netmask), Netmask)); + Topology.Add(new Subnet(NetworkUtils.GetNetwork(IpAddress, Netmask), Netmask, LineId)); } else { diff --git a/CiscoMigration/CiscoConverter.cs b/CiscoMigration/CiscoConverter.cs index 303dbca..92e319c 100644 --- a/CiscoMigration/CiscoConverter.cs +++ b/CiscoMigration/CiscoConverter.cs @@ -1848,26 +1848,51 @@ private void Add_InterfacesAndRoutes() foreach (Cisco_Interface.Subnet subnet in ciscoInterface.Topology) { - // Note, that a subnet can be a host in Cisco, but we want to always convert to network in CP!!! - string networkName = (new CiscoNetwork(ciscoInterface.Id, subnet.Network, subnet.Netmask)).AutoGeneratedNetworkName(); - if (networkName.Contains(AutoGeneratedNameWithError)) + + + // Note, that a subnet can be a host in Cisco, but we want to always convert to network in CP!!! + string networkName = (new CiscoNetwork(ciscoInterface.Id, subnet.Network, subnet.Netmask)).AutoGeneratedNetworkName(); + if (networkName.Contains(AutoGeneratedNameWithError)) + { + ciscoInterface.ConversionIncidentType = ConversionIncidentType.ManualActionRequired; + ciscoInterface.ConversionIncidentMessage = "Unrecognized topology details."; + + + ciscoCommandIdWithIncident = ciscoInterface.Id; + } + if (subnet.Netmask == "255.255.255.255") { - ciscoInterface.ConversionIncidentType = ConversionIncidentType.ManualActionRequired; - ciscoInterface.ConversionIncidentMessage = "Unrecognized topology details: " + subnet.Network + " " + subnet.Netmask + "."; - ciscoCommandIdWithIncident = ciscoInterface.Id; - } + //string errorDesc = ciscoCommand.Name() + " details: " + ciscoObject + "."; + string conversionIncidentMessage = "Unrecognized topology details: " + subnet.Network + " " + subnet.Netmask + "."; + _conversionIncidents.Add(new ConversionIncident(subnet.LineId, + conversionIncidentMessage, + "cannot create network objects", + ConversionIncidentType.ManualActionRequired)); + string networkErrorName = (new CiscoNetwork(subnet.LineId, subnet.Network, subnet.Netmask)).AutoGeneratedNetworkName(); - var cpNetwork = new CheckPoint_Network(); - cpNetwork.Name = networkName; - cpNetwork.Name = cpNetwork.SafeName(); - cpNetwork.Subnet = subnet.Network; - cpNetwork.Netmask = subnet.Netmask; - AddCheckPointObject(cpNetwork); + var cpNetworkError = new CheckPoint_Network(); + cpNetworkError.Name = networkErrorName; + cpNetworkError.Name = cpNetworkError.SafeName(); + cpNetworkError.Subnet = subnet.Network; + cpNetworkError.Netmask = subnet.Netmask; + AddCheckPointObject(cpNetworkError); + //continue; + } else + { - cpNetworkGroup.Members.Add(cpNetwork.Name); - } + var cpNetwork = new CheckPoint_Network(); + cpNetwork.Name = networkName; + cpNetwork.Name = cpNetwork.SafeName(); + cpNetwork.Subnet = subnet.Network; + cpNetwork.Netmask = subnet.Netmask; + AddCheckPointObject(cpNetwork); + cpNetworkGroup.Members.Add(cpNetwork.Name); + } + + + } ApplyConversionIncidentOnCheckPointObject(cpNetworkGroup, ciscoInterface); AddCheckPointObject(cpNetworkGroup); diff --git a/CiscoMigration/CiscoParser.cs b/CiscoMigration/CiscoParser.cs index 871e81a..5b17172 100644 --- a/CiscoMigration/CiscoParser.cs +++ b/CiscoMigration/CiscoParser.cs @@ -220,10 +220,6 @@ private void ParseCommands(string filename) prevIndentationLevel = command.IndentationLevel; flatList.Add(FindCommand(command)); - if (line.Contains("g-ext-dns-leg")) - { - var gd = 3; - } } _ciscoCommands = flatList.BuildTree(); @@ -233,10 +229,6 @@ private void ParseCommands(string filename) { ParseWithChildren(command, prevCommand); prevCommand = command; - if (command.Text.Contains("g-ext-dns-leg")) - { - var gd = 3; - } } // Remove duplicates @@ -264,7 +256,7 @@ private void ParseInterfacesTopology() string routeInterfaceName = CiscoCommand.InterfacePrefix + route.InterfaceName; if (routeInterfaceName == ciscoInterface.CiscoId) { - ciscoInterface.Topology.Add(new Cisco_Interface.Subnet(route.DestinationIp, route.DestinationNetmask)); + ciscoInterface.Topology.Add(new Cisco_Interface.Subnet(route.DestinationIp, route.DestinationNetmask, route.Id)); if (route.DefaultRoute) { From 7f3970b0b4f876e6a9ec57d06931a6974384b1d5 Mon Sep 17 00:00:00 2001 From: ASemenchuk <59782501+Botinoc@users.noreply.github.com> Date: Mon, 1 Aug 2022 16:15:16 +0300 Subject: [PATCH 2/2] cisco fix: fix bug with red flag on error --- CiscoMigration/CiscoConverter.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CiscoMigration/CiscoConverter.cs b/CiscoMigration/CiscoConverter.cs index 92e319c..17f3f16 100644 --- a/CiscoMigration/CiscoConverter.cs +++ b/CiscoMigration/CiscoConverter.cs @@ -1870,6 +1870,14 @@ private void Add_InterfacesAndRoutes() "cannot create network objects", ConversionIncidentType.ManualActionRequired)); string networkErrorName = (new CiscoNetwork(subnet.LineId, subnet.Network, subnet.Netmask)).AutoGeneratedNetworkName(); + foreach (CiscoCommand ciscoCommand in CiscoAllCommands) + { + if (ciscoCommand.Id == subnet.LineId) + { + ciscoCommand.ConversionIncidentMessage = conversionIncidentMessage; + ciscoCommand.ConversionIncidentType = ConversionIncidentType.ManualActionRequired; + } + } var cpNetworkError = new CheckPoint_Network(); cpNetworkError.Name = networkErrorName;