Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CiscoMigration/CiscoCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,7 @@ public override void Parse(CiscoCommand command, CiscoCommand prevCommand, Dicti
}
}


public class Cisco_AccessList : CiscoCommand
{
public enum ActionType { NA, Deny, Permit };
Expand Down Expand Up @@ -1907,6 +1908,9 @@ public SourceDest(List<string> words) : this()
if (words.Count > 1)
{
RefObjectName = words[1];
var NameValidityRegex = @"[^A-Za-z0-9_.-]";
RefObjectName = Validators.ChangeNameAccordingToRules(RefObjectName);
Regex.Replace(RefObjectName, NameValidityRegex, "_");
WordsCount = 2;
}
break;
Expand All @@ -1916,6 +1920,9 @@ public SourceDest(List<string> words) : this()
if (words.Count > 1)
{
RefObjectName = InterfacePrefix + words[1];
var NameValidityRegex = @"[^A-Za-z0-9_.-]";
RefObjectName = Validators.ChangeNameAccordingToRules(RefObjectName);
Regex.Replace(RefObjectName, NameValidityRegex, "_");
WordsCount = 2;
}
break;
Expand Down
37 changes: 35 additions & 2 deletions CiscoMigration/CiscoParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,47 @@ protected override void ParseVersion(object versionProvider)
}
}
}
private void chengeLines(List<String> newLines, int index, string ip)
{
if ((newLines[index - 1][0] == ' ' && !newLines[index - 1].Contains("description")) || (newLines[index + 1][0] == ' ' && !newLines[index + 1].Contains("description")))
{
newLines[index] = " network-object host " + ip;
int inserIndex = index;
while (newLines[inserIndex][0] == ' ')
{
inserIndex -= 1;
}
newLines.Insert(inserIndex, "object network " + ip);
newLines.Insert(inserIndex+1, " host " + ip);
}
}

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

var newLines = lines.ToList();

for (var i = 0; i < newLines.Count; i++)
{
if (newLines[i].Contains("255.255.255.255") && newLines[i].Contains("network-object"))
chengeLines(newLines, i, newLines[i].Split(' ')[2]);
}
lines = newLines.ToArray();

var parents = new Stack<Indentation>();
var flatList = new List<CiscoCommand>();

parents.Push(new Indentation(null, 0));

int prevIndentationLevel = 0;
int lineId = 0;

foreach (string line in lines)
{
lineId++;



// Check for an empty line or line with just spaces.
if (line.Trim().Length == 0)
Expand Down Expand Up @@ -195,6 +219,11 @@ 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();
Expand All @@ -204,6 +233,10 @@ private void ParseCommands(string filename)
{
ParseWithChildren(command, prevCommand);
prevCommand = command;
if (command.Text.Contains("g-ext-dns-leg"))
{
var gd = 3;
}
}

// Remove duplicates
Expand Down