2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.pcep.impl;
10 import java.net.InetAddress;
11 import java.net.InetSocketAddress;
12 import java.net.UnknownHostException;
13 import java.util.Timer;
15 import org.opendaylight.protocol.pcep.PCEPCloseTermination;
16 import org.opendaylight.protocol.pcep.PCEPConnection;
17 import org.opendaylight.protocol.pcep.PCEPMessage;
18 import org.opendaylight.protocol.pcep.PCEPSessionListener;
19 import org.opendaylight.protocol.pcep.PCEPSessionPreferences;
20 import org.opendaylight.protocol.pcep.PCEPSessionProposalChecker;
21 import org.opendaylight.protocol.pcep.object.PCEPCloseObject.Reason;
22 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
24 public class ServerSessionMock extends PCEPSessionImpl {
26 private final MockPCE client;
28 public ServerSessionMock(final PCEPSessionListener listener, final PCEPSessionListener client) {
29 super(new MockDispatcher(), new Timer(), new PCEPConnection() {
31 public InetSocketAddress getPeerAddress() {
33 return new InetSocketAddress(InetAddress.getByName("localhost"), 4189);
34 } catch (final UnknownHostException e) {
41 public PCEPSessionListener getListener() {
46 public PCEPSessionPreferences getProposal() {
47 return new PCEPSessionPreferences(new PCEPOpenObject(4, 9, 2));
51 public PCEPSessionProposalChecker getProposalChecker() {
52 return new SimpleSessionProposalChecker();
54 }, new PCEPMessageFactory(), 5, 30, null);
55 this.client = (MockPCE) client;
59 public void sendMessage(final PCEPMessage msg) {
60 this.lastMessageSentAt = System.nanoTime();
61 this.client.onMessage(this, msg);
66 this.client.onSessionTerminated(this, new PCEPCloseTermination(Reason.UNKNOWN));