Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify metamako configuration format #1042

Merged
merged 4 commits into from
Mar 9, 2018
Merged

Identify metamako configuration format #1042

merged 4 commits into from
Mar 9, 2018

Conversation

corinaminer
Copy link
Contributor

Identifies Metamako configurations by the phrase "username admin secret". As far as I could tell with the configurations at hand, that phrase appears in only and all Metamako device configurations. @saparikh @arifogel will that work more broadly, as far as you know?

@batfish-bot
Copy link

This change is Reviewable

@dhalperi
Copy link
Member

dhalperi commented Mar 9, 2018

Reviewed 3 of 3 files at r1.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


projects/batfish/src/main/java/org/batfish/grammar/VendorConfigurationFormatDetector.java, line 188 at r1 (raw file):

  @Nullable
  private ConfigurationFormat checkMetamako() {
    if (_fileText.contains("username admin secret")) {

So the goal of this part of the code is to find something that is unique to the vendor at hand. In this case, I think this is actually very common (Metamako, like many others, seems to be Cisco-like).

The better detector might be something that finds lines like these:

! device: <foo> (A32-A7, MOS-0.13.25)
! device: <foo> (A32-A5, MOS-0.14.0)

Especially since the MOS-#.#.# is the part that relates to Metamako's "Metamako Operating System (MOS)".

I would use a gracious regex to catch lines like this.


Comments from Reviewable

@corinaminer
Copy link
Contributor Author

Review status: all files reviewed at latest revision, 1 unresolved discussion.


projects/batfish/src/main/java/org/batfish/grammar/VendorConfigurationFormatDetector.java, line 188 at r1 (raw file):

Previously, dhalperi (Dan Halperin) wrote…

So the goal of this part of the code is to find something that is unique to the vendor at hand. In this case, I think this is actually very common (Metamako, like many others, seems to be Cisco-like).

The better detector might be something that finds lines like these:

! device: <foo> (A32-A7, MOS-0.13.25)
! device: <foo> (A32-A5, MOS-0.14.0)

Especially since the MOS-#.#.# is the part that relates to Metamako's "Metamako Operating System (MOS)".

I would use a gracious regex to catch lines like this.

isn't that a comment that could be changed arbitrarily? seems like most of the other possible formats are identified by unique phrases in the config text.


Comments from Reviewable

@corinaminer
Copy link
Contributor Author

Devices are now identified as Metamako if they have any of the following:

  • the phrase "application metamux"
  • the phrase "application metawatch"
  • a line ! device: [at least one non-newline char] MOS-[number].[number].[number])

Of 29 sample Metamako configurations, 21 matched (at least) one of the first two criteria; all of them matched the third.


Review status: 2 of 3 files reviewed at latest revision, 1 unresolved discussion.


projects/batfish/src/main/java/org/batfish/grammar/VendorConfigurationFormatDetector.java, line 188 at r1 (raw file):

Previously, corinaminer (Corina Miner) wrote…

isn't that a comment that could be changed arbitrarily? seems like most of the other possible formats are identified by unique phrases in the config text.

Added better identification criteria.


Comments from Reviewable

@dhalperi
Copy link
Member

dhalperi commented Mar 9, 2018

Tests are failing because there are tests for it. I'm of mixed opinion -- we don't have grammar or interesting tests of this stuff -- as indicated by the failing cisco-assumptions that led to this work -- but we do parse its structure somewhat usefully in a cisco-like way right now.

@arifogel thoughts?


Review status: 2 of 3 files reviewed at latest revision, all discussions resolved, some commit checks failed.


projects/batfish/src/main/java/org/batfish/grammar/VendorConfigurationFormatDetector.java, line 191 at r2 (raw file):

      return ConfigurationFormat.METAMAKO;
    }
    Matcher deviceDescription =

why two ifs vs three things || together?


projects/batfish/src/main/java/org/batfish/grammar/VendorConfigurationFormatDetector.java, line 192 at r2 (raw file):

    }
    Matcher deviceDescription =
        Pattern.compile("(?m)^! device: [^\\n]+ MOS-\\d+\\.\\d+\\.\\d+\\)$").matcher(_fileText);

compile the regex once (private static final METAMAKO_MOS_PATTERN = Pattern.compile..), then use the compiled Pattern's function instead to do the match.


Comments from Reviewable

@dhalperi
Copy link
Member

dhalperi commented Mar 9, 2018

Reviewed 1 of 1 files at r2.
Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.


Comments from Reviewable

@arifogel
Copy link
Member

arifogel commented Mar 9, 2018

As discussed offline, this format for now should be detected but unsupported.


Reviewed 2 of 3 files at r1, 1 of 1 files at r2.
Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.


Comments from Reviewable

@corinaminer
Copy link
Contributor Author

Review status: 2 of 6 files reviewed at latest revision, 2 unresolved discussions.


projects/batfish/src/main/java/org/batfish/grammar/VendorConfigurationFormatDetector.java, line 191 at r2 (raw file):

Previously, dhalperi (Dan Halperin) wrote…

why two ifs vs three things || together?

it was to avoid creating the matcher for ~75% of metamako configurations. new setup manages to do that without splitting up the if.


projects/batfish/src/main/java/org/batfish/grammar/VendorConfigurationFormatDetector.java, line 192 at r2 (raw file):

Previously, dhalperi (Dan Halperin) wrote…

compile the regex once (private static final METAMAKO_MOS_PATTERN = Pattern.compile..), then use the compiled Pattern's function instead to do the match.

done for this and all other patterns in the file


Comments from Reviewable

@dhalperi
Copy link
Member

dhalperi commented Mar 9, 2018

:lgtm:


Reviewed 4 of 4 files at r3.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


projects/batfish/src/main/java/org/batfish/grammar/VendorConfigurationFormatDetector.java, line 192 at r2 (raw file):

Previously, corinaminer (Corina Miner) wrote…

done for this and all other patterns in the file

In future, would prefer wide-scale refactoring changes in a separate PR. It confuses this PR (e.g., if we want to revert this PR we revert the refactoring) and is not a blocker for this PR.

LGTM.


Comments from Reviewable

@dhalperi dhalperi merged commit ada7f05 into master Mar 9, 2018
@dhalperi dhalperi deleted the add-metamako branch March 9, 2018 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants