Initial framework migration to 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 java.io.IOException;
11 import java.net.InetSocketAddress;
12
13 import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactory;
14 import org.opendaylight.protocol.bgp.rib.impl.BGPConnectionImpl;
15 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionFactory;
16 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionProposalCheckerImpl;
17 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionProposalImpl;
18 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPConnection;
19 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPConnectionFactory;
20 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
21 import org.opendaylight.protocol.concepts.ASNumber;
22 import org.opendaylight.protocol.concepts.IPv4;
23 import org.opendaylight.protocol.framework.DispatcherImpl;
24 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
25
26 public class BGPSpeakerMock {
27
28         DispatcherImpl dispatcher;
29
30         BGPSpeakerMock() throws IOException {
31                 this.dispatcher = new DispatcherImpl(new BGPMessageFactory());
32         }
33
34         public static void main(final String[] args) throws IOException {
35
36                 final BGPSpeakerMock m = new BGPSpeakerMock();
37
38                 final ProtocolMessageFactory parser = new BGPMessageFactory();
39
40                 m.dispatcher.createServer(new InetSocketAddress("127.0.0.2", 12345), new BGPConnectionFactory() {
41                         @Override
42                         public BGPConnection createProtocolConnection(final InetSocketAddress address) {
43                                 final BGPSessionProposalImpl prop = new BGPSessionProposalImpl((short) 90, new ASNumber(25), IPv4.FAMILY.addressForString("127.0.0.2"));
44                                 final BGPSessionPreferences prefs = prop.getProposal();
45                                 try {
46                                         prop.close();
47                                 } catch (final IOException e) {
48                                         e.printStackTrace();
49                                 }
50                                 return new BGPConnectionImpl(address, new SpeakerSessionListener(m.dispatcher), prefs, new BGPSessionProposalCheckerImpl());
51                         }
52                 }, new BGPSessionFactory(parser));
53         }
54 }