use of org.onosproject.cluster.DefaultControllerNode in project onos by opennetworkinglab.
the class BgpSessionManagerTest method setUp.
@Before
public void setUp() throws Exception {
peer1 = new TestBgpPeer(BGP_PEER1_ID);
peer2 = new TestBgpPeer(BGP_PEER2_ID);
peer3 = new TestBgpPeer(BGP_PEER3_ID);
peers.clear();
peers.add(peer1);
peers.add(peer2);
peers.add(peer3);
//
// Setup the BGP Session Manager to test, and start listening for BGP
// connections.
//
bgpSessionManager = new BgpSessionManager();
routeService = createNiceMock(RouteAdminService.class);
replay(routeService);
bgpSessionManager.routeService = routeService;
ClusterService clusterService = createMock(ClusterService.class);
expect(clusterService.getLocalNode()).andReturn(new DefaultControllerNode(NODE_ID, LOCAL)).anyTimes();
replay(clusterService);
bgpSessionManager.clusterService = clusterService;
// NOTE: We use port 0 to bind on any available port
ComponentContext componentContext = createMock(ComponentContext.class);
getDictionaryMock(componentContext);
replay(componentContext);
bgpSessionManager.activate(componentContext);
// Get the port number the BGP Session Manager is listening on
Channel serverChannel = TestUtils.getField(bgpSessionManager, "serverChannel");
SocketAddress socketAddress = serverChannel.getLocalAddress();
InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
InetAddress connectToAddress = InetAddresses.forString("127.0.0.1");
connectToSocket = new InetSocketAddress(connectToAddress, inetSocketAddress.getPort());
//
// Setup the AS Paths
//
ArrayList<BgpRouteEntry.PathSegment> pathSegments = new ArrayList<>();
byte pathSegmentType1 = (byte) BgpConstants.Update.AsPath.AS_SEQUENCE;
ArrayList<Long> segmentAsNumbers1 = new ArrayList<>();
segmentAsNumbers1.add(65010L);
segmentAsNumbers1.add(65020L);
segmentAsNumbers1.add(65030L);
BgpRouteEntry.PathSegment pathSegment1 = new BgpRouteEntry.PathSegment(pathSegmentType1, segmentAsNumbers1);
pathSegments.add(pathSegment1);
asPathShort = new BgpRouteEntry.AsPath(new ArrayList<>(pathSegments));
//
byte pathSegmentType2 = (byte) BgpConstants.Update.AsPath.AS_SET;
ArrayList<Long> segmentAsNumbers2 = new ArrayList<>();
segmentAsNumbers2.add(65041L);
segmentAsNumbers2.add(65042L);
segmentAsNumbers2.add(65043L);
BgpRouteEntry.PathSegment pathSegment2 = new BgpRouteEntry.PathSegment(pathSegmentType2, segmentAsNumbers2);
pathSegments.add(pathSegment2);
//
asPathLong = new BgpRouteEntry.AsPath(pathSegments);
}
use of org.onosproject.cluster.DefaultControllerNode in project onos by opennetworkinglab.
the class ControllerNodeCodec method decode.
@Override
public ControllerNode decode(ObjectNode json, CodecContext context) {
checkNotNull(json, "JSON cannot be null");
String ip = json.path("ip").asText();
return new DefaultControllerNode(new NodeId(json.path("id").asText(ip)), IpAddress.valueOf(ip), json.path("tcpPort").asInt(DEFAULT_PORT));
}
use of org.onosproject.cluster.DefaultControllerNode in project onos by opennetworkinglab.
the class SimpleClusterStore method activate.
@Activate
public void activate() {
instance = new DefaultControllerNode(new NodeId("local"), LOCALHOST);
listenerRegistry = new ListenerRegistry<>();
eventDispatcher.addSink(WorkPartitionEvent.class, listenerRegistry);
log.info("Started");
}
use of org.onosproject.cluster.DefaultControllerNode in project onos by opennetworkinglab.
the class SimpleMastershipStore method activate.
@Activate
public void activate() {
if (clusterService == null) {
// just for ease of unit test
final ControllerNode instance = new DefaultControllerNode(new NodeId("local"), IpAddress.valueOf("127.0.0.1"));
clusterService = new ClusterService() {
private final Instant creationTime = Instant.now();
@Override
public ControllerNode getLocalNode() {
return instance;
}
@Override
public Set<ControllerNode> getNodes() {
return ImmutableSet.of(instance);
}
@Override
public Set<Node> getConsensusNodes() {
return ImmutableSet.of();
}
@Override
public ControllerNode getNode(NodeId nodeId) {
if (instance.id().equals(nodeId)) {
return instance;
}
return null;
}
@Override
public State getState(NodeId nodeId) {
if (instance.id().equals(nodeId)) {
return State.ACTIVE;
} else {
return State.INACTIVE;
}
}
@Override
public Version getVersion(NodeId nodeId) {
if (instance.id().equals(nodeId)) {
return versionService.version();
}
return null;
}
@Override
public Instant getLastUpdatedInstant(NodeId nodeId) {
return creationTime;
}
@Override
public void addListener(ClusterEventListener listener) {
}
@Override
public void removeListener(ClusterEventListener listener) {
}
};
}
log.info("Started");
}
use of org.onosproject.cluster.DefaultControllerNode in project onos by opennetworkinglab.
the class DefaultClusterMetadataProvider method activate.
@Activate
public void activate() {
String localIp = getSiteLocalAddress();
ControllerNode localNode = new DefaultControllerNode(new NodeId(localIp), IpAddress.valueOf(localIp), DEFAULT_ONOS_PORT);
ClusterMetadata metadata = new ClusterMetadata(PROVIDER_ID, "default", localNode, ImmutableSet.of(), ImmutableSet.of(), UUID.randomUUID().toString());
long version = System.currentTimeMillis();
cachedMetadata.set(new Versioned<>(metadata, version));
providerRegistry.register(this);
log.info("Started");
}
Aggregations