BUG-58: refactor to take advantage of netty
[bgpcep.git] / bgp / testtool / src / test / java / org / opendaylight / protocol / bgp / testtool / BGPSpeakerMock.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.bgp.testtool;
9
10 import io.netty.util.HashedWheelTimer;
11
12 import java.io.IOException;
13 import java.net.InetSocketAddress;
14
15 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
16 import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactory;
17 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionNegotiatorFactory;
18 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionProposalImpl;
19 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
20 import org.opendaylight.protocol.concepts.ASNumber;
21 import org.opendaylight.protocol.concepts.IPv4;
22 import org.opendaylight.protocol.framework.DispatcherImpl;
23 import org.opendaylight.protocol.framework.SessionListenerFactory;
24
25 public class BGPSpeakerMock {
26
27         DispatcherImpl dispatcher = new DispatcherImpl();
28
29         public static void main(final String[] args) throws IOException {
30
31                 final BGPSpeakerMock m = new BGPSpeakerMock();
32
33                 final BGPSessionPreferences prefs = new BGPSessionProposalImpl((short) 90, new ASNumber(25), IPv4.FAMILY.addressForString("127.0.0.2")).getProposal();
34
35                 final SessionListenerFactory<BGPSessionListener> f = new SessionListenerFactory<BGPSessionListener>() {
36                         @Override
37                         public BGPSessionListener getSessionListener() {
38                                 return new SpeakerSessionListener(m.dispatcher);
39                         }
40                 };
41
42                 m.dispatcher.createServer(new InetSocketAddress("127.0.0.2", 12345), f,
43                                 new BGPSessionNegotiatorFactory(new HashedWheelTimer(), prefs), new BGPMessageFactory());
44         }
45 }