本文整理汇总了Java中net.i2cat.netconf.rpc.Reply类的典型用法代码示例。如果您正苦于以下问题:Java Reply类的具体用法?Java Reply怎么用?Java Reply使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Reply类属于net.i2cat.netconf.rpc包,在下文中一共展示了Reply类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBehaviours
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
@Test
public void testBehaviours() {
Server server = Server.createServerStoringMessages(2222);
// define behaviours
Query bQuery = QueryFactory.newGetRouteInformation();
Reply bReply = new Reply();
Error error = ErrorFactory.newError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, null, null, null, null);
bReply.addError(error);
Behaviour behaviour = new Behaviour(bQuery, bReply);
server.defineBehaviour(behaviour);
// start the server
server.startServer();
try {
SessionContext sessionContext = new SessionContext();
sessionContext.setURI(new URI("ssh://user:[email protected]:2222/"));
INetconfSession session = new NetconfSession(sessionContext);
session.connect();
// send a message
Query query = QueryFactory.newGetRouteInformation();
Reply reply = session.sendSyncQuery(query);
// assertions
Assert.assertEquals("Reply must contain 1 error", 1, reply.getErrors().size());
Assert.assertEquals("Reply error must be of 'type application'", ErrorType.APPLICATION, reply.getErrors().get(0).getType());
Assert.assertEquals("Error tag must be 'operation-failed'", ErrorTag.OPERATION_FAILED, reply.getErrors().get(0).getTag());
Assert.assertEquals("Error severity must be 'error'", ErrorSeverity.ERROR, reply.getErrors().get(0).getSeverity());
} catch (Exception e) {
Assert.fail("Error creating session: " + e.getMessage());
} finally {
server.stopServer();
}
}
示例2: parseResponse
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
public void parseResponse(Object responseMessage, Object model) throws ActionException {
// FIXME This "if" is important because it resets the model if we want to update it
if (this.modelToUpdate == null)
this.modelToUpdate = new ComputerSystem();
String message;
try {
System routerModel = (System) model;
/* getting interface information */
if (responseMessage instanceof Reply) {
Reply rpcReply = (Reply) responseMessage;
message = rpcReply.getContain();
} else {
throw new CommandException("Error parsing response: the response is not a Reply message");
}
if (message != null) {
/* Parse interface info */
routerModel = parseInterfaces(routerModel, message);
/* Parse protocols info */
// Protocols parsing should be done before parsing routing-options:
// Protocol parser creates classes in the model that require being updated by routing-options parser.
// That's the case of RouteCalculationServices which routerID is set by RoutingOptionsParser
routerModel = parseProtocols(routerModel, message);
/* Parse routing options info */
routerModel = parseRoutingOptions(routerModel, message);
}
} catch (Exception e) {
throw new ActionException(e);
}
}
示例3: parseResponse
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
@Override
public void parseResponse(Object responseMessage, Object model) throws ActionException {
if (this.modelToUpdate == null)
this.modelToUpdate = new ComputerSystem();
String message;
try {
System routerModel = (System) model;
/* getting interface information */
if (responseMessage instanceof Reply) {
Reply rpcReply = (Reply) responseMessage;
message = rpcReply.getContain();
} else {
throw new CommandException("Error parsing response: the response is not a Reply message");
}
routerModel.removeAllremoveManagedSystemElementByType(ComputerSystem.class);
if (message != null) {
routerModel = parseInterface(routerModel, message);
routerModel = FilterInterface(routerModel);
routerModel = parseRoutingOptions(routerModel, message);
}
} catch (Exception e) {
throw new ActionException(e);
}
}
示例4: parseResponse
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
public void parseResponse(Object responseMessage, Object model) throws ActionException {
String message;
try {
org.opennaas.extensions.router.model.System routerModel = (org.opennaas.extensions.router.model.System) model;
DigesterEngine listLogicalRoutersParser = new ListLogicalRoutersParser();
// DigesterEngine logicalInterfParser = new IPConfigurationInterfaceParser();
listLogicalRoutersParser.init();
/* getting interface information */
if (responseMessage instanceof Reply) {
Reply rpcReply = (Reply) responseMessage;
message = rpcReply.getContain();
} else {
throw new CommandException("Error parsing response: the response is not a Reply message");
}
listLogicalRoutersParser.configurableParse(new ByteArrayInputStream(message.getBytes()));
for (Object idLogicalRouter : listLogicalRoutersParser.getMapElements().values()) {
ComputerSystem system = new ComputerSystem();
system.setName((String) idLogicalRouter);
routerModel.addSystem(system);
}
} catch (Exception e) {
throw new ActionException(e);
}
}
示例5: parseResponse
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
@Override
public void parseResponse(Object responseMessage, Object model) throws ActionException {
/* the model have to be null and we have to initialize */
// FIXME This "if" is important because it resets the model if we want to update it
if (this.modelToUpdate == null)
this.modelToUpdate = new ComputerSystem();
String message;
try {
System routerModel = (System) model;
/* getting interface information */
if (responseMessage instanceof Reply) {
Reply rpcReply = (Reply) responseMessage;
message = rpcReply.getContain();
} else {
throw new CommandException("Error parsing response: the response is not a Reply message");
}
if (message != null) {
/* Parse LR info */
routerModel = parseLRs(routerModel, message);
/* Parse interface info */
routerModel = parseInterfaces(routerModel, message);
/* Parse routing options info */
// Routing options parsing should be done after parsing protocols (protocols is required):
// Protocol parser creates classes in the model that require being updated by routing-options parser.
// That's the case of RouteCalculationServices which routerID is set by RoutingOptionsParser
routerModel = parseRoutingOptions(routerModel, message);
}
} catch (Exception e) {
throw new ActionException(e);
}
}
示例6: testsParseOSPFConfigTwice
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
@Test
public void testsParseOSPFConfigTwice() throws IOException, ActionException {
String netconfReply = readStringFromFile("/parsers/getConfigWithOSPF.xml");
Reply rpcReply = new Reply();
rpcReply.setContain(netconfReply);
System routerModel = new ComputerSystem();
GetOSPFConfigAction action = new GetOSPFConfigAction();
action.setModelToUpdate(routerModel);
action.parseResponse(rpcReply, routerModel);
GetOSPFConfigAction action2 = new GetOSPFConfigAction();
action2.setModelToUpdate(routerModel);
action2.parseResponse(rpcReply, routerModel);
Assert.assertTrue("Router must have only one OPSFService", routerModel.getHostedService().size() == 1);
// check interfaces has at most one OSPFProtocolEndpoint
for (NetworkPort port : ModelHelper.getInterfaces(routerModel)) {
int ospfPEPCount = 0;
for (ProtocolEndpoint pep : port.getProtocolEndpoint()) {
if (pep instanceof OSPFProtocolEndpoint)
ospfPEPCount++;
}
Assert.assertTrue("A NetworkPort must have at most one OSPFProtocolEndpoint", ospfPEPCount < 2);
}
}
示例7: testsParseRemoveOSPFCorreclty
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
@Test
public void testsParseRemoveOSPFCorreclty() throws IOException, ActionException {
String netconfReply1 = readStringFromFile("/parsers/getConfigWithOSPF.xml");
String netconfReply2 = readStringFromFile("/parsers/getConfigWithoutOSPF.xml");
Reply rpcReply1 = new Reply();
rpcReply1.setContain(netconfReply1);
Reply rpcReply2 = new Reply();
rpcReply2.setContain(netconfReply2);
System routerModel = new ComputerSystem();
GetOSPFConfigAction action = new GetOSPFConfigAction();
action.setModelToUpdate(routerModel);
action.parseResponse(rpcReply1, routerModel);
GetOSPFConfigAction action2 = new GetOSPFConfigAction();
action2.setModelToUpdate(routerModel);
action2.parseResponse(rpcReply2, routerModel);
Assert.assertTrue("Router must have no OPSFService", routerModel.getHostedService().isEmpty());
for (NetworkPort port : ModelHelper.getInterfaces(routerModel)) {
for (ProtocolEndpoint pep : port.getProtocolEndpoint()) {
if (pep instanceof OSPFProtocolEndpoint)
Assert.fail("A NetworkPort must have no OSPFProtocolEndpoint");
}
}
}
示例8: testPrepareRestoreAction
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
@Test
public void testPrepareRestoreAction() throws Exception {
String uri = System.getProperty("protocol.uri");
if (uri == null || uri.equals("${protocol.uri}")) {
uri = "mock://user:[email protected]:2212/mocksubsystem";
}
String compare = null;
String toCompare = null;
Query query = QueryFactory.newGetConfig("running", "<configuration></configuration>", null);
Reply reply = sendNetconfMessage(query, uri);
compare = reply.getContain();
IAction action = new MockAction();
action.setActionID("mockAction");
queueManagerCapability.queueAction(action);
action = new CorruptedAction();
action.setActionID("corruptedAction");
queueManagerCapability.queueAction(action);
boolean isChecked = false;
try {
queueManagerCapability.execute();
} catch (Exception e) {
if (e instanceof CapabilityException)
isChecked = true;
}
if (!uri.startsWith("mock:"))
Assert.assertTrue(isChecked);
reply = sendNetconfMessage(query, uri);
toCompare = reply.getContain();
Assert.assertEquals(compare, toCompare);
}
示例9: sendNetconfMessage
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
public Reply sendNetconfMessage(Query query, String uri) throws Exception {
SessionContext sessionContext = new SessionContext();
sessionContext.setURI(new URI(uri));
NetconfSession session = new NetconfSession(sessionContext);
session.connect();
Reply reply = session.sendSyncQuery(query);
if (reply.containsErrors())
throw new Exception();
session.disconnect();
return reply;
}
示例10: execute
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
@Override
public ActionResponse execute(IProtocolSessionManager protocolSessionManager) throws ActionException {
Response response = null;
try {
/*
* IT INCLUDES AN ERROR IN THE MASK
*/
String netconfXML = "<configuration><interfaces>" +
"<interface>" +
"<name>fe-0/1/2</name>" +
"<unit operation=\"replace\">" +
"<name>2<name>" +
"<family><inet><address>192.168.1.3/60</address></inet></family>" +
"</unit>" +
"</interface></interfaces></configuration>";
NetconfProtocolSession protocol = (NetconfProtocolSession) protocolSessionManager.obtainSessionByProtocol("netconf", false);
Query query = QueryFactory.newEditConfig("candidate", null, null, null, netconfXML);
Reply reply = (Reply) protocol.sendReceive(query);
// extra control, it checks if is not null the error list
response = checkResponse(reply, query);
validateResponse(response);
} catch (ProtocolException e) {
throw new ActionException(e);
}
ActionResponse actionResponse = new ActionResponse();
actionResponse.setActionID(actionID);
actionResponse.addResponse(response);
return actionResponse;
}
示例11: sendFakeConfig
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
public void sendFakeConfig(Query configQuery) throws IOException {
InputStream configFileIs = this.getClass().getResourceAsStream("/router_configs/router_config_A.xml");
Reply reply = ReplyFactory.newGetConfigReply(configQuery, null, IOUtils.toString(configFileIs));
sendReply(reply);
}
示例12: sendReply
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
public void sendReply(Reply reply) throws IOException {
send(reply.toXML());
}
示例13: getReply
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
public Reply getReply() {
return reply;
}
示例14: testConsumingBehaviours
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
@Test
public void testConsumingBehaviours() {
Server server = Server.createServerStoringMessages(2222);
// define behaviours
Query bQuery = QueryFactory.newGetRouteInformation();
Reply bReply = new Reply();
Error error = ErrorFactory.newError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, null, null, null, null);
bReply.addError(error);
Behaviour behaviour = new Behaviour(bQuery, bReply, true);
server.defineBehaviour(behaviour);
bQuery = QueryFactory.newDiscardChanges();
bReply = ReplyFactory.newOk(bQuery, null);
behaviour = new Behaviour(bQuery, bReply, true);
server.defineBehaviour(behaviour);
bQuery = QueryFactory.newGetRouteInformation();
bReply = ReplyFactory.newOk(bQuery, null);
behaviour = new Behaviour(bQuery, bReply, true);
server.defineBehaviour(behaviour);
// start the server
server.startServer();
try {
SessionContext sessionContext = new SessionContext();
sessionContext.setURI(new URI("ssh://user:[email protected]:2222/"));
INetconfSession session = new NetconfSession(sessionContext);
session.connect();
// send first query
Query query = QueryFactory.newGetRouteInformation();
Reply reply = session.sendSyncQuery(query);
// assertions
Assert.assertEquals("Reply must contain 1 error", 1, reply.getErrors().size());
Assert.assertEquals("Reply error must be of 'type application'", ErrorType.APPLICATION, reply.getErrors().get(0).getType());
Assert.assertEquals("Error tag must be 'operation-failed'", ErrorTag.OPERATION_FAILED, reply.getErrors().get(0).getTag());
Assert.assertEquals("Error severity must be 'error'", ErrorSeverity.ERROR, reply.getErrors().get(0).getSeverity());
// send second query
query = QueryFactory.newDiscardChanges();
reply = session.sendSyncQuery(query);
// assertions
Assert.assertEquals("Reply must contain 0 errors", 0, reply.getErrors().size());
Assert.assertEquals("Reply must be OK", true, reply.isOk());
// send third query
query = QueryFactory.newGetRouteInformation();
reply = session.sendSyncQuery(query);
// assertions
Assert.assertEquals("Reply must contain 0 errors", 0, reply.getErrors().size());
Assert.assertEquals("Reply must be OK", true, reply.isOk());
} catch (Exception e) {
Assert.fail("Error executing tests: " + e.getMessage());
} finally {
server.stopServer();
}
}
示例15: Behaviour
import net.i2cat.netconf.rpc.Reply; //导入依赖的package包/类
/**
* Creates a Behaviour that NOT consumes itself
*
* @param query
* @param reply
*/
public Behaviour(Query query, Reply reply) {
this.query = query;
this.reply = reply;
this.consume = false;
}