Skip to content

Commit 53aec53

Browse files
authored
Merge pull request #82 from Botinoc/dev
Cisco fix: add error message
2 parents be31162 + 7f3970b commit 53aec53

File tree

3 files changed

+56
-26
lines changed

3 files changed

+56
-26
lines changed

CiscoMigration/CiscoCommands.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,7 @@ public class Cisco_Interface : CiscoCommand
13701370
public string VLan { get; set; }
13711371
public string IpAddress { get; set; }
13721372
public string Netmask { get; set; }
1373+
public int LineId { get; set; }
13731374
public bool Shutdown { get; set; }
13741375
public bool ManagementOnly { get; set; }
13751376
public bool LeadsToInternet { get; set; }
@@ -1378,11 +1379,13 @@ public class Subnet
13781379
{
13791380
public string Network { get; private set; }
13801381
public string Netmask { get; private set; }
1382+
public int LineId { get; private set; }
13811383

1382-
public Subnet(string sIp, string sMask)
1384+
public Subnet(string sIp, string sMask, int lineId)
13831385
{
13841386
Network = sIp;
13851387
Netmask = sMask;
1388+
LineId = lineId;
13861389
}
13871390
}
13881391

@@ -1399,6 +1402,7 @@ public override void Parse(CiscoCommand command, CiscoCommand prevCommand, Dicti
13991402
VLan = "";
14001403
IpAddress = "";
14011404
Netmask = "";
1405+
LineId = 0;
14021406
Shutdown = false;
14031407
ManagementOnly = false;
14041408
LeadsToInternet = false;
@@ -1439,10 +1443,11 @@ public override void Parse(CiscoCommand command, CiscoCommand prevCommand, Dicti
14391443
case "ip address":
14401444
IpAddress = ((Cisco_IP)child).IpAddress;
14411445
Netmask = ((Cisco_IP)child).Netmask;
1446+
LineId = ((Cisco_IP)child).Id;
14421447

14431448
if (NetworkUtils.IsValidIpv4(IpAddress) && NetworkUtils.IsValidNetmaskv4(Netmask))
14441449
{
1445-
Topology.Add(new Subnet(NetworkUtils.GetNetwork(IpAddress, Netmask), Netmask));
1450+
Topology.Add(new Subnet(NetworkUtils.GetNetwork(IpAddress, Netmask), Netmask, LineId));
14461451
}
14471452
else
14481453
{

CiscoMigration/CiscoConverter.cs

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,26 +1848,59 @@ private void Add_InterfacesAndRoutes()
18481848

18491849
foreach (Cisco_Interface.Subnet subnet in ciscoInterface.Topology)
18501850
{
1851-
// Note, that a subnet can be a host in Cisco, but we want to always convert to network in CP!!!
1852-
string networkName = (new CiscoNetwork(ciscoInterface.Id, subnet.Network, subnet.Netmask)).AutoGeneratedNetworkName();
1853-
if (networkName.Contains(AutoGeneratedNameWithError))
1851+
1852+
1853+
// Note, that a subnet can be a host in Cisco, but we want to always convert to network in CP!!!
1854+
string networkName = (new CiscoNetwork(ciscoInterface.Id, subnet.Network, subnet.Netmask)).AutoGeneratedNetworkName();
1855+
if (networkName.Contains(AutoGeneratedNameWithError))
1856+
{
1857+
ciscoInterface.ConversionIncidentType = ConversionIncidentType.ManualActionRequired;
1858+
ciscoInterface.ConversionIncidentMessage = "Unrecognized topology details.";
1859+
1860+
1861+
ciscoCommandIdWithIncident = ciscoInterface.Id;
1862+
}
1863+
if (subnet.Netmask == "255.255.255.255")
18541864
{
1855-
ciscoInterface.ConversionIncidentType = ConversionIncidentType.ManualActionRequired;
1856-
ciscoInterface.ConversionIncidentMessage = "Unrecognized topology details: " + subnet.Network + " " + subnet.Netmask + ".";
18571865

1858-
ciscoCommandIdWithIncident = ciscoInterface.Id;
1859-
}
1866+
//string errorDesc = ciscoCommand.Name() + " details: " + ciscoObject + ".";
1867+
string conversionIncidentMessage = "Unrecognized topology details: " + subnet.Network + " " + subnet.Netmask + ".";
1868+
_conversionIncidents.Add(new ConversionIncident(subnet.LineId,
1869+
conversionIncidentMessage,
1870+
"cannot create network objects",
1871+
ConversionIncidentType.ManualActionRequired));
1872+
string networkErrorName = (new CiscoNetwork(subnet.LineId, subnet.Network, subnet.Netmask)).AutoGeneratedNetworkName();
1873+
foreach (CiscoCommand ciscoCommand in CiscoAllCommands)
1874+
{
1875+
if (ciscoCommand.Id == subnet.LineId)
1876+
{
1877+
ciscoCommand.ConversionIncidentMessage = conversionIncidentMessage;
1878+
ciscoCommand.ConversionIncidentType = ConversionIncidentType.ManualActionRequired;
1879+
}
1880+
}
18601881

1861-
var cpNetwork = new CheckPoint_Network();
1862-
cpNetwork.Name = networkName;
1863-
cpNetwork.Name = cpNetwork.SafeName();
1864-
cpNetwork.Subnet = subnet.Network;
1865-
cpNetwork.Netmask = subnet.Netmask;
1866-
AddCheckPointObject(cpNetwork);
1882+
var cpNetworkError = new CheckPoint_Network();
1883+
cpNetworkError.Name = networkErrorName;
1884+
cpNetworkError.Name = cpNetworkError.SafeName();
1885+
cpNetworkError.Subnet = subnet.Network;
1886+
cpNetworkError.Netmask = subnet.Netmask;
1887+
AddCheckPointObject(cpNetworkError);
1888+
//continue;
1889+
} else
1890+
{
18671891

1868-
cpNetworkGroup.Members.Add(cpNetwork.Name);
1869-
}
1892+
var cpNetwork = new CheckPoint_Network();
1893+
cpNetwork.Name = networkName;
1894+
cpNetwork.Name = cpNetwork.SafeName();
1895+
cpNetwork.Subnet = subnet.Network;
1896+
cpNetwork.Netmask = subnet.Netmask;
1897+
AddCheckPointObject(cpNetwork);
1898+
1899+
cpNetworkGroup.Members.Add(cpNetwork.Name);
1900+
}
18701901

1902+
1903+
}
18711904
ApplyConversionIncidentOnCheckPointObject(cpNetworkGroup, ciscoInterface);
18721905
AddCheckPointObject(cpNetworkGroup);
18731906

CiscoMigration/CiscoParser.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,6 @@ private void ParseCommands(string filename)
220220
prevIndentationLevel = command.IndentationLevel;
221221
flatList.Add(FindCommand(command));
222222

223-
if (line.Contains("g-ext-dns-leg"))
224-
{
225-
var gd = 3;
226-
}
227223
}
228224

229225
_ciscoCommands = flatList.BuildTree();
@@ -233,10 +229,6 @@ private void ParseCommands(string filename)
233229
{
234230
ParseWithChildren(command, prevCommand);
235231
prevCommand = command;
236-
if (command.Text.Contains("g-ext-dns-leg"))
237-
{
238-
var gd = 3;
239-
}
240232
}
241233

242234
// Remove duplicates
@@ -264,7 +256,7 @@ private void ParseInterfacesTopology()
264256
string routeInterfaceName = CiscoCommand.InterfacePrefix + route.InterfaceName;
265257
if (routeInterfaceName == ciscoInterface.CiscoId)
266258
{
267-
ciscoInterface.Topology.Add(new Cisco_Interface.Subnet(route.DestinationIp, route.DestinationNetmask));
259+
ciscoInterface.Topology.Add(new Cisco_Interface.Subnet(route.DestinationIp, route.DestinationNetmask, route.Id));
268260

269261
if (route.DefaultRoute)
270262
{

0 commit comments

Comments
 (0)