Skip to content

Commit 0380732

Browse files
authored
Merge pull request #81 from Botinoc/dev
Cisco: fix bugs with 255.255.255.255
2 parents 28b9abc + 8dd88ca commit 0380732

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

CiscoMigration/CiscoCommands.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,7 @@ public override void Parse(CiscoCommand command, CiscoCommand prevCommand, Dicti
18461846
}
18471847
}
18481848

1849+
18491850
public class Cisco_AccessList : CiscoCommand
18501851
{
18511852
public enum ActionType { NA, Deny, Permit };
@@ -1907,6 +1908,9 @@ public SourceDest(List<string> words) : this()
19071908
if (words.Count > 1)
19081909
{
19091910
RefObjectName = words[1];
1911+
var NameValidityRegex = @"[^A-Za-z0-9_.-]";
1912+
RefObjectName = Validators.ChangeNameAccordingToRules(RefObjectName);
1913+
Regex.Replace(RefObjectName, NameValidityRegex, "_");
19101914
WordsCount = 2;
19111915
}
19121916
break;
@@ -1916,6 +1920,9 @@ public SourceDest(List<string> words) : this()
19161920
if (words.Count > 1)
19171921
{
19181922
RefObjectName = InterfacePrefix + words[1];
1923+
var NameValidityRegex = @"[^A-Za-z0-9_.-]";
1924+
RefObjectName = Validators.ChangeNameAccordingToRules(RefObjectName);
1925+
Regex.Replace(RefObjectName, NameValidityRegex, "_");
19191926
WordsCount = 2;
19201927
}
19211928
break;

CiscoMigration/CiscoParser.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,47 @@ protected override void ParseVersion(object versionProvider)
136136
}
137137
}
138138
}
139+
private void chengeLines(List<String> newLines, int index, string ip)
140+
{
141+
if ((newLines[index - 1][0] == ' ' && !newLines[index - 1].Contains("description")) || (newLines[index + 1][0] == ' ' && !newLines[index + 1].Contains("description")))
142+
{
143+
newLines[index] = " network-object host " + ip;
144+
int inserIndex = index;
145+
while (newLines[inserIndex][0] == ' ')
146+
{
147+
inserIndex -= 1;
148+
}
149+
newLines.Insert(inserIndex, "object network " + ip);
150+
newLines.Insert(inserIndex+1, " host " + ip);
151+
}
152+
}
139153

140154
private void ParseCommands(string filename)
141155
{
142156
string[] lines = File.ReadAllLines(filename, Encoding.GetEncoding("us-ascii", new EncoderReplacementFallback(""), new DecoderReplacementFallback("")));
143157
ParsedLines = lines.Count();
144158

159+
var newLines = lines.ToList();
160+
161+
for (var i = 0; i < newLines.Count; i++)
162+
{
163+
if (newLines[i].Contains("255.255.255.255") && newLines[i].Contains("network-object"))
164+
chengeLines(newLines, i, newLines[i].Split(' ')[2]);
165+
}
166+
lines = newLines.ToArray();
167+
145168
var parents = new Stack<Indentation>();
146169
var flatList = new List<CiscoCommand>();
147-
148170
parents.Push(new Indentation(null, 0));
149171

150172
int prevIndentationLevel = 0;
151173
int lineId = 0;
152-
174+
153175
foreach (string line in lines)
154176
{
155177
lineId++;
178+
179+
156180

157181
// Check for an empty line or line with just spaces.
158182
if (line.Trim().Length == 0)
@@ -195,6 +219,11 @@ private void ParseCommands(string filename)
195219

196220
prevIndentationLevel = command.IndentationLevel;
197221
flatList.Add(FindCommand(command));
222+
223+
if (line.Contains("g-ext-dns-leg"))
224+
{
225+
var gd = 3;
226+
}
198227
}
199228

200229
_ciscoCommands = flatList.BuildTree();
@@ -204,6 +233,10 @@ private void ParseCommands(string filename)
204233
{
205234
ParseWithChildren(command, prevCommand);
206235
prevCommand = command;
236+
if (command.Text.Contains("g-ext-dns-leg"))
237+
{
238+
var gd = 3;
239+
}
207240
}
208241

209242
// Remove duplicates

0 commit comments

Comments
 (0)