public RoutingProtocol toRoutingProtocol() { switch (this) { case E1: return RoutingProtocol.OSPF_E1; case E2: return RoutingProtocol.OSPF_E2; default: throw new BatfishException("invalid ospf metric type"); } } }
public String toInterfaceName() { if (_inverted) { // _warnings.redFlag("Inversion of interface matching is not supported."); throw new BatfishException("Unknown matchdata type"); } return (String) _matchData; } }
@JsonCreator public static OriginType fromString(String name) { OriginType instance = _map.get(name.toLowerCase()); if (instance == null) { throw new BatfishException("Not a valid OriginType: \"" + name + "\""); } return instance; }
/** The relative order of precedence for this NAT's type */ static int getTypePrecedence(CiscoIosNat nat) { String name = nat.getClass().getSimpleName(); if (!typePrecedence.containsKey(name)) { throw new BatfishException("Unsupported NAT type"); } return typePrecedence.get(name); }
@JsonCreator public static Protocol fromString(@Nullable String name) { requireNonNull(name, "Cannot instantiate protocol from null"); Protocol value = MAP.get(name.toLowerCase()); if (value == null) { throw new BatfishException( "No " + Protocol.class.getSimpleName() + " with name: '" + name + "'"); } return value; }
private BatfishException convError(Class<?> type, ParserRuleContext ctx) { String typeName = type.getSimpleName(); String txt = getFullText(ctx); return new BatfishException("Could not convert to " + typeName + ": " + txt); }
public void add(Prefix prefix, String device) { if (prefix == null) { throw new BatfishException("Cannot add null prefix to trie"); } _trie.addPrefix(prefix, device); }
private static Configuration loadFileConfiguration(File configFile) { try { return new Configurations().properties(configFile); } catch (ConfigurationException e) { throw new BatfishException( "Error loading configuration from " + configFile.getAbsolutePath(), e); } }
public SubRange getLengthRange() { if (_prefix.getPrefixLength() <= _ge && _ge <= _le) { return new SubRange(_ge, _le); } else { throw new BatfishException("Invalid length range restriction"); } }
@Override public void enterExtended_ipv6_access_list_stanza(Extended_ipv6_access_list_stanzaContext ctx) { String name; if (ctx.name != null) { name = ctx.name.getText(); } else { throw new BatfishException("Could not determine acl name"); } _currentExtendedIpv6Acl = _configuration.getExtendedIpv6Acls().computeIfAbsent(name, ExtendedIpv6AccessList::new); defineStructure(IPV6_ACCESS_LIST_EXTENDED, name, ctx); }
/** Utility to parse versions, with error handling. */ private static DefaultArtifactVersion parseVersion(String version, String name) { DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(version); if (artifactVersion.getMajorVersion() == 0 && artifactVersion.getMinorVersion() == 0) { throw new BatfishException(String.format("Illegal version '%s' for %s", version, name)); } return artifactVersion; }
@Override public void storeAnswerMetadata(AnswerMetadata answerMetadata, AnswerId answerId) { String metricsStr; try { metricsStr = BatfishObjectMapper.writePrettyString(answerMetadata); } catch (JsonProcessingException e) { throw new BatfishException("Could not write answer metrics", e); } Path answerMetadataPath = getAnswerMetadataPath(answerId); mkdirs(answerMetadataPath.getParent()); CommonUtil.writeFile(answerMetadataPath, metricsStr); }
private static IkeAuthenticationMethod toIkeAuthenticationMethod( Ike_authentication_methodContext ctx) { if (ctx.DSA_SIGNATURES() != null) { return IkeAuthenticationMethod.DSA_SIGNATURES; } else if (ctx.PRE_SHARED_KEYS() != null) { return IkeAuthenticationMethod.PRE_SHARED_KEYS; } else if (ctx.RSA_SIGNATURES() != null) { return IkeAuthenticationMethod.RSA_SIGNATURES; } else { throw new BatfishException("Invalid ike authentication method: " + ctx.getText()); } }
@Override public void enterCip_profile(Cip_profileContext ctx) { if (_currentIpsecProfile != null) { throw new BatfishException("IpsecProfile should be null!"); } _currentIpsecProfile = new IpsecProfile(ctx.name.getText()); defineStructure(IPSEC_PROFILE, ctx.name.getText(), ctx); }
@Override public void enterS_protocols_bgp(S_protocols_bgpContext ctx) { int as = toInteger(ctx.asnum); if (_bgpProcess == null) { _bgpProcess = new BgpProcess(as); _configuration.setBgpProcess(_bgpProcess); } else { if (_bgpProcess.getLocalAs() != as) { throw new BatfishException("Do not support multiple BGP processes at this time"); } } }
@Test public void testSetErrors() { BatfishException exception = new BatfishException("sample exception"); BatfishStackTrace stackTrace = new BatfishStackTrace(exception); List<BatfishStackTrace> errors = new ArrayList<>(); errors.add(stackTrace); SortedMap<String, List<BatfishStackTrace>> error = new TreeMap<>(); error.put("error", errors); _element.setErrors(error); assertThat(_element.getErrors().get("error"), is(errors)); } }
@Override public void exitIkept_encryption(Ikept_encryptionContext ctx) { if (ctx.AES128() != null) { _currentIkeProposal.setEncryptionAlgorithm(EncryptionAlgorithm.AES_128_CBC); } else if (ctx.AES256() != null) { _currentIkeProposal.setEncryptionAlgorithm(EncryptionAlgorithm.AES_256_CBC); } else if (ctx.THREEDES() != null) { _currentIkeProposal.setEncryptionAlgorithm(EncryptionAlgorithm.THREEDES_CBC); } else { throw new BatfishException("Invalid encryption algorithm"); } }
BoolExpr mkLt(Expr e1, Expr e2) { if (e1 instanceof BoolExpr && e2 instanceof BoolExpr) { return mkAnd((BoolExpr) e2, mkNot((BoolExpr) e1)); } if (e1 instanceof ArithExpr && e2 instanceof ArithExpr) { return getCtx().mkLt((ArithExpr) e1, (ArithExpr) e2); } if (e1 instanceof BitVecExpr && e2 instanceof BitVecExpr) { return getCtx().mkBVULT((BitVecExpr) e1, (BitVecExpr) e2); } throw new BatfishException("Invalid call to mkLt while encoding control plane"); }
@Test public void checkNonEmptyErrors() { BatfishException exception = new BatfishException("sample exception"); _element.getErrors().put("error", new BatfishStackTrace(exception)); assertThat(_element.getErrors().size(), is(1)); }
@Override public void enterIs_type_is_stanza(Is_type_is_stanzaContext ctx) { IsisProcess proc = currentVrf().getIsisProcess(); if (ctx.LEVEL_1() != null) { proc.setLevel(IsisLevel.LEVEL_1); } else if (ctx.LEVEL_2_ONLY() != null || ctx.LEVEL_2() != null) { proc.setLevel(IsisLevel.LEVEL_2); } else { throw new BatfishException("Unsupported is-type"); } }