public Node(String name, DeviceType type) { this(name, makeId(name), type); }
public Topology(String testrigName) { this(getId(testrigName), testrigName); }
public Aggregate getOrCreateAggregate(String name, AggregateType aggType) { String aggId = Aggregate.getId(name); for (Aggregate aggregate : _aggregates) { if (aggregate.getId().equals(aggId)) { return aggregate; } } Aggregate aggregate = new Aggregate(name, aggType); getAggregates().add(aggregate); return aggregate; }
@Test public void serialization() { Topology topo = new Topology("testrig"); topo.getAggregates().add(new Aggregate("cloud")); topo.getInterfaces().add(new Interface("node", "name")); topo.getLinks().add(new Link("src", "dst")); topo.getNodes().add(new Node("node")); Map<String, String> properties = new HashMap<>(); properties.put("key", "value"); topo.setProperties(properties); JsonNode jsonNode = BatfishObjectMapper.mapper().valueToTree(topo); assertThat(jsonNode.get("id").asText(), equalTo(Topology.getId("testrig"))); assertThat(jsonNode.get("aggregates").get(0).get("name").asText(), equalTo("cloud")); assertThat(jsonNode.get("interfaces").get(0).get("nodeId").asText(), equalTo("node")); assertThat(jsonNode.get("interfaces").get(0).get("name").asText(), equalTo("name")); assertThat(jsonNode.get("links").get(0).get("srcId").asText(), equalTo("src")); assertThat(jsonNode.get("links").get(0).get("dstId").asText(), equalTo("dst")); assertThat(jsonNode.get("nodes").get(0).get("name").asText(), equalTo("node")); assertThat(jsonNode.get("properties").get("key").asText(), equalTo("value")); } }
@Test public void constructor() throws IOException { String str = "{\"testrigName\" : \"testrig\"," + " \"nodes\" : [{\"name\": \"node\"}], " + " \"links\" : [{\"srcId\" : \"src\", \"dstId\" : \"dst\"}]," + " \"interfaces\" : [{\"nodeId\": \"node\", \"name\" : \"node\"}]," + " \"aggregates\" : [{\"name\": \"cloud\", \"contents\" : [\"id1\"]}]}"; Topology topo = BatfishObjectMapper.mapper().readValue(str, Topology.class); assertThat(topo.getId(), equalTo(Topology.getId("testrig"))); assertThat(topo.getTestrigName(), equalTo("testrig")); assertThat(topo.getAggregates().size(), equalTo(1)); assertThat( topo.getOrCreateAggregate("cloud", AggregateType.CLOUD).getContents().size(), equalTo(1)); assertThat(topo.getInterfaces().size(), equalTo(1)); assertThat(topo.getLinks().size(), equalTo(1)); assertThat(topo.getNodes().size(), equalTo(1)); }
/** Creates a new TransmissionContext for the specified last-hop node and outgoing interface. */ private TransmissionContext branch( NodeInterfacePair lastHopNodeAndOutgoingInterface, String currentHop) { TransmissionContext transmissionContext = new TransmissionContext( _aclDefinitions, new Node(currentHop), _flowTraces, _hopsSoFar, lastHopNodeAndOutgoingInterface, _newSessions, _namedIpSpaces, _originalFlow, _transformedFlow); return transmissionContext; } }
@Override protected String featureValueOf(Hop hop) { return hop.getNode().getName(); } }
@Test public void testToString() { Analysis a = new Analysis("foo", Maps.newHashMap()); assertThat(a.toString(), equalTo("Analysis{name=foo, questions={}}")); a.addQuestion("question", "questionContent"); assertThat(a.toString(), equalTo("Analysis{name=foo, questions={question=questionContent}}")); }
@Test public void testConstructorAndGetter() { Map<String, String> questions = Collections.singletonMap("question", "questionContent"); Analysis a = new Analysis("analysis", questions); assertThat(a.getName(), equalTo("analysis")); assertThat(a.getQuestions(), equalTo(questions)); }
@Override public Environment getEnvironment() { SortedSet<Edge> edgeBlackList = getEdgeBlacklist(); SortedSet<NodeInterfacePair> interfaceBlackList = getInterfaceBlacklist(); SortedSet<String> nodeBlackList = getNodeBlacklist(); // TODO: add bgp tables and external announcements as well return new Environment( _settings.getSnapshotName(), edgeBlackList, interfaceBlackList, nodeBlackList, null, null, null); }
public Aggregate(String name, AggregateType type) { super(getId(name)); _name = name; _type = type; _contents = new HashSet<>(); }
@Test public void testLinkTypeSymmetric() { for (InterfaceType t1 : InterfaceType.values()) { for (InterfaceType t2 : InterfaceType.values()) { assertThat(interfaceTypesToLinkType(t1, t2), equalTo(interfaceTypesToLinkType(t2, t1))); } } } }
public @Nonnull WorkStatus toWorkStatus() { return new WorkStatus(_workItem, _status, _lastTaskCheckResult); } }
@Override public boolean equals(Object o) { return (o != null && o.getClass() == this.getClass() && Objects.equals(_id, ((BfObject) o).getId())); }
public Node(String name) { this(name, makeId(name), null); }
@JsonCreator public Node( @JsonProperty(PROP_NAME) String name, @JsonProperty(PROP_ID) String id, @JsonProperty(PROP_TYPE) DeviceType type) { super(firstNonNull(id, makeId(name))); _name = name; _type = type; if (name == null) { throw new IllegalArgumentException("Cannot build Node: name is null"); } }